oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1package web
2
3import (
4 "testing"
5 "time"
6)
7
8func TestGreeting(t *testing.T) {
9 london, err := time.LoadLocation("Europe/London")
10 if err != nil {
11 t.Fatal(err)
12 }
13 at := func(h, m int) time.Time { return time.Date(2026, 7, 1, h, m, 0, 0, time.UTC) }
14 for _, c := range []struct {
15 now time.Time
16 loc *time.Location
17 want string
18 }{
19 {at(0, 0), time.UTC, "Hello, Paul."},
20 {at(4, 59), time.UTC, "Hello, Paul."},
21 {at(5, 0), time.UTC, "Good morning, Paul."},
22 {at(11, 59), time.UTC, "Good morning, Paul."},
23 {at(12, 0), time.UTC, "Good afternoon, Paul."},
24 {at(17, 59), time.UTC, "Good afternoon, Paul."},
25 {at(18, 0), time.UTC, "Good evening, Paul."},
26 {at(23, 59), time.UTC, "Good evening, Paul."},
27 {at(8, 0), london, "Good morning, Paul."}, // 09:00 BST
28 {at(17, 0), london, "Good evening, Paul."}, // 18:00 BST
29 {at(23, 30), london, "Hello, Paul."}, // 00:30 BST next day
30 {at(8, 0), nil, "Good morning, Paul."}, // no zone: as given
31 } {
32 if got := greeting(c.now, c.loc, "Paul"); got != c.want {
33 t.Errorf("greeting(%s, %v) = %q, want %q", c.now.Format(time.RFC3339), c.loc, got, c.want)
34 }
35 }
36}
37