Passed
Push — master ( 2df23a...0c8182 )
by Serhii
01:29
created

timeago.TestSet_for_language   A

Complexity

Conditions 4

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nop 1
dl 0
loc 16
rs 9.8
c 0
b 0
f 0
1
package timeago
2
3
import "testing"
4
5
func TestTrans(t *testing.T) {
6
	cases := []struct {
7
		lang   string
8
		key    string
9
		result string
10
	}{
11
		{"ru", "online", "В сети"},
12
		{"ru", "second", "секунда"},
13
		{"ru", "hour", "час"},
14
		{"ru", "day", "день"},
15
		{"en", "online", "Online"},
16
		{"en", "second", "second"},
17
		{"en", "hour", "hour"},
18
		{"en", "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 := trans(tc.key); result != tc.result {
26
				test.Errorf("Result mast 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