-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
pluralize_test.go
52 lines (47 loc) · 1.74 KB
/
pluralize_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
package flect
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_Pluralize(t *testing.T) {
for _, tt := range singlePluralAssertions {
if tt.doPluralizeTest {
t.Run(tt.singular, func(st *testing.T) {
r := require.New(st)
r.Equal(tt.plural, Pluralize(tt.singular), "pluralize %s", tt.singular)
r.Equal(tt.plural, Pluralize(tt.plural), "pluralize %s", tt.plural)
})
}
}
}
func Test_PluralizeWithSize(t *testing.T) {
for _, tt := range singlePluralAssertions {
t.Run(tt.singular, func(st *testing.T) {
r := require.New(st)
if tt.doSingularizeTest {
r.Equal(tt.singular, PluralizeWithSize(tt.singular, -1), "pluralize %d %s", -1, tt.singular)
r.Equal(tt.singular, PluralizeWithSize(tt.plural, -1), "pluralize %d %s", -1, tt.plural)
r.Equal(tt.singular, PluralizeWithSize(tt.singular, 1), "pluralize %d %s", 1, tt.singular)
r.Equal(tt.singular, PluralizeWithSize(tt.plural, 1), "pluralize %d %s", 1, tt.plural)
}
if tt.doPluralizeTest {
r.Equal(tt.plural, PluralizeWithSize(tt.singular, -2), "pluralize %d %s", -2, tt.singular)
r.Equal(tt.plural, PluralizeWithSize(tt.plural, -2), "pluralize %d %s", -2, tt.plural)
r.Equal(tt.plural, PluralizeWithSize(tt.singular, 0), "pluralize %d %s", 0, tt.singular)
r.Equal(tt.plural, PluralizeWithSize(tt.plural, 0), "pluralize %d %s", 0, tt.plural)
r.Equal(tt.plural, PluralizeWithSize(tt.singular, 2), "pluralize %d %s", 2, tt.singular)
r.Equal(tt.plural, PluralizeWithSize(tt.plural, 2), "pluralize %d %s", 2, tt.plural)
}
})
}
}
func BenchmarkPluralize(b *testing.B) {
for n := 0; n < b.N; n++ {
for _, tt := range singlePluralAssertions {
if tt.doPluralizeTest {
Pluralize(tt.singular)
Pluralize(tt.plural)
}
}
}
}