forked from gotnospirit/messageformat
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathselect_test.go
80 lines (69 loc) · 1.95 KB
/
select_test.go
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// @TODO(gotnospirit) add test on readKey, readChoice
package messageformat
import (
"testing"
)
func TestSelect(t *testing.T) {
doTest(t, Test{
"{GENDER, select, male{He} female {She} other{They}} liked this.",
[]Expectation{
{map[string]interface{}{"GENDER": "male"}, "He liked this."},
{map[string]interface{}{"GENDER": "female"}, "She liked this."},
{nil, "They liked this."},
},
})
doTest(t, Test{
"{GENDER,select,male{He}female{She}other{They}} liked this.",
[]Expectation{
{map[string]interface{}{"GENDER": "male"}, "He liked this."},
{map[string]interface{}{"GENDER": "female"}, "She liked this."},
{nil, "They liked this."},
},
})
doTest(t, Test{
"{A, select, other{!#}}, and {B, select, other{#!}}",
[]Expectation{
{map[string]interface{}{"A": "black", "B": "mortimer"}, "!black, and mortimer!"},
},
})
doTest(t, Test{
"{A,select,other{#, and {B,select,other{#}}}}!",
[]Expectation{
{map[string]interface{}{"A": "black", "B": "mortimer"}, "black, and mortimer!"},
},
})
doTest(t, Test{
`{A,select,other{\##\, and {B,select,other{#\#}}}}`,
[]Expectation{
{map[string]interface{}{"A": "black", "B": "mortimer"}, `#black\, and mortimer#`},
},
})
doTest(t, Test{
`Hello {A,select,キティ{Kitty}other{World}}`,
[]Expectation{
{map[string]interface{}{"A": "キティ"}, `Hello Kitty`},
{map[string]interface{}{"A": "世界"}, `Hello World`},
},
})
doTest(t, Test{
`{isTrueOrFalse, select, true {True} other {False}}`,
[]Expectation{
{map[string]interface{}{"isTrueOrFalse": true}, `True`},
{map[string]interface{}{"isTrueOrFalse": false}, `False`},
},
})
doTestFormatException(
t,
"{VAR,select,other{succeed}}",
map[string]interface{}{"VAR": struct{}{}},
"toString: Unsupported type: struct {}",
)
}
func BenchmarkSelect(b *testing.B) {
doBenchmarkExecute(
b,
"This is a {A, select, other{#}}",
"This is a benchmark",
map[string]interface{}{"A": "benchmark"},
)
}