Passed
Push — master ( ad64d3...e465b8 )
by Serhii
01:08 queued 11s
created

config_test.go   A

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 20
eloc 53
dl 0
loc 84
rs 10
c 0
b 0
f 0

3 Methods

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