-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcore_test.go
More file actions
66 lines (55 loc) · 1.16 KB
/
core_test.go
File metadata and controls
66 lines (55 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package textsbox
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNew(t *testing.T) {
tb := New()
assert.NotNil(t, tb)
}
func TestLoad(t *testing.T) {
file, err := os.Open("./fixtures/fr.yml")
if err != nil {
panic(err)
}
defer file.Close()
tb := New()
err = tb.Load(file)
assert.Nil(t, err)
}
func TestFind(t *testing.T) {
tb := New()
filenameList := []string{"fr.yml", "en.yml"}
for _, lang := range filenameList {
filename := fmt.Sprintf("./fixtures/%s", lang)
err := tb.LoadFile(filename)
assert.Nil(t, err)
}
tb.AddKeyAlias("fr", "fr-FR", "FR-FR")
data := map[string]map[string]interface{}{
"fr": {
"hello_msg": "Bonjour tout le monde",
},
"FR-FR": {
"hello_msg": "Bonjour tout le monde",
},
"fr-FR": {
"hello_msg": "Bonjour tout le monde",
},
"en": {
"hello_msg": "Hello World !",
"nested.value": "value",
},
}
for key, values := range data {
for pattern, expectedValue := range values {
value, err := tb.Find(key, pattern)
assert.Nil(t, err)
assert.Equal(t, expectedValue, value)
}
}
_, err := tb.Find("fr", "foo.bar")
assert.Error(t, ErrNotFound{}, err)
}