-
Notifications
You must be signed in to change notification settings - Fork 8
/
plural_test.go
97 lines (85 loc) · 2.59 KB
/
plural_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// @TODO(gotnospirit) add test on readOffset
package messageformat
import (
"testing"
)
func TestPlural(t *testing.T) {
doTest(t, Test{
"You have {NUM_TASKS, plural, one {one task} other {# tasks} =42 {the answer to the life, the universe and everything tasks}} remaining.",
[]Expectation{
{map[string]interface{}{"NUM_TASKS": -1}, "You have -1 tasks remaining."},
{map[string]interface{}{"NUM_TASKS": 1}, "You have one task remaining."},
{map[string]interface{}{"NUM_TASKS": 42}, "You have the answer to the life, the universe and everything tasks remaining."},
},
})
doTest(t, Test{
"{NUM_TASKS, plural, one {a} =1 {b} other {c}}",
[]Expectation{
{map[string]interface{}{"NUM_TASKS": 1}, "b"},
},
})
doTest(t, Test{
`{NUM, plural, one{a} other{b}}`,
[]Expectation{
{map[string]interface{}{"NUM": 1}, "a"},
{map[string]interface{}{"NUM": "1"}, "a"},
},
})
doTestException(
t,
"{NUM,plural,other{b}}",
map[string]interface{}{"NUM": struct{}{}},
"toString: Unsupported type: struct {}",
)
}
func BenchmarkPluralNonInteger(b *testing.B) {
doBenchmarkExecute(
b,
"This is a {A, plural, other{benchmark}}",
"This is a benchmark",
map[string]interface{}{"A": "1"},
)
}
func BenchmarkPluralLiteralize(b *testing.B) {
doBenchmarkExecute(
b,
"This is a {A, plural, one{benchmark} other{}}",
"This is a benchmark",
map[string]interface{}{"A": 1},
)
}
func BenchmarkPluralOther(b *testing.B) {
doBenchmarkExecute(
b,
"This is a {A, plural, other{benchmark}}",
"This is a benchmark",
map[string]interface{}{"A": 1},
)
}
func BenchmarkPluralExactValue(b *testing.B) {
doBenchmarkExecute(
b,
"This is a {A, plural, =2{benchmark} other{}}",
"This is a benchmark",
map[string]interface{}{"A": 2},
)
}
func TestPluralOffsetExtension(t *testing.T) {
doTest(t, Test{
"You {NUM_ADDS, plural, offset:1 =0{didnt add this to your profile} =1{added this to your profile} one{and one other person added this to their profile} other{and # others added this to their profiles}}.",
[]Expectation{
{map[string]interface{}{"NUM_ADDS": 0}, "You didnt add this to your profile."},
{map[string]interface{}{"NUM_ADDS": 1}, "You added this to your profile."},
{map[string]interface{}{"NUM_ADDS": 2}, "You and one other person added this to their profile."},
{map[string]interface{}{"NUM_ADDS": 3}, "You and 2 others added this to their profiles."},
},
})
}
func BenchmarkPluralOffsetExtension(b *testing.B) {
doBenchmarkExecute(
b,
"This is a {A, plural, offset:1 =2{benchmark} other{}}",
"This is a benchmark",
map[string]interface{}{"A": 2},
)
}