|
1
|
|
|
package timeago |
|
2
|
|
|
|
|
3
|
|
|
import "testing" |
|
4
|
|
|
|
|
5
|
|
|
func TestTrans(t *testing.T) { |
|
6
|
|
|
cases := []struct { |
|
7
|
|
|
lang string |
|
8
|
|
|
trans func() string |
|
9
|
|
|
result string |
|
10
|
|
|
}{ |
|
11
|
|
|
{"ru", func() string { return trans().Online }, "В сети"}, |
|
12
|
|
|
{"ru", func() string { return trans().Second }, "секунда"}, |
|
13
|
|
|
{"ru", func() string { return trans().Hour }, "час"}, |
|
14
|
|
|
{"ru", func() string { return trans().Day }, "день"}, |
|
15
|
|
|
{"en", func() string { return trans().Online }, "Online"}, |
|
16
|
|
|
{"en", func() string { return trans().Second }, "second"}, |
|
17
|
|
|
{"en", func() string { return trans().Hour }, "hour"}, |
|
18
|
|
|
{"en", func() string { return trans().Day }, "day"}, |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
for _, tc := range cases { |
|
22
|
|
|
t.Run("returns "+tc.lang+" language", func(test *testing.T) { |
|
23
|
|
|
Set("language", tc.lang) |
|
24
|
|
|
|
|
25
|
|
|
if result := tc.trans(); result != tc.result { |
|
26
|
|
|
test.Errorf("Result must be %s but got %s", tc.result, result) |
|
27
|
|
|
} |
|
28
|
|
|
}) |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
func TestSet_for_language(t *testing.T) { |
|
33
|
|
|
cases := []struct { |
|
34
|
|
|
name string |
|
35
|
|
|
value string |
|
36
|
|
|
err string |
|
37
|
|
|
}{ |
|
38
|
|
|
{"sets language to ru", "ru", "Set must set the `language` variable to `ru` but it didn't"}, |
|
39
|
|
|
{"sets language to en", "en", "Set must set the `language` variable to `en` but it didn't"}, |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
for _, tc := range cases { |
|
43
|
|
|
t.Run(tc.name, func(test *testing.T) { |
|
44
|
|
|
Set("language", tc.value) |
|
45
|
|
|
|
|
46
|
|
|
if language != tc.value { |
|
47
|
|
|
test.Error(tc.err) |
|
48
|
|
|
} |
|
49
|
|
|
}) |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
func TestSet_for_location(t *testing.T) { |
|
54
|
|
|
cases := []struct { |
|
55
|
|
|
name string |
|
56
|
|
|
value string |
|
57
|
|
|
err string |
|
58
|
|
|
}{ |
|
59
|
|
|
{"sets location to India Delhi", "India/Delhi", "Set must set the `location` variable to `India/Delhi` but it didn't"}, |
|
60
|
|
|
{"sets language to Europe/Kiev", "Europe/Kiev", "Set must set the `location` variable to `Europe/Kiev` but it didn't"}, |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
for _, tc := range cases { |
|
64
|
|
|
t.Run(tc.name, func(test *testing.T) { |
|
65
|
|
|
Set("location", tc.value) |
|
66
|
|
|
|
|
67
|
|
|
if location != tc.value { |
|
68
|
|
|
test.Error(tc.err) |
|
69
|
|
|
} |
|
70
|
|
|
}) |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|