-
Notifications
You must be signed in to change notification settings - Fork 5
/
int64_test.go
171 lines (163 loc) · 5.15 KB
/
int64_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package numtow
import (
"errors"
"strings"
"testing"
"github.com/gammban/numtow/lang/en"
"github.com/gammban/numtow/lang"
"github.com/gammban/numtow/lang/kz"
"github.com/gammban/numtow/lang/ru"
"github.com/gammban/numtow/lang/ru/gender"
)
//nolint:gochecknoglobals
var testCaseIntNumbers = []struct {
GiveInt string
GiveInt64 int64
GiveLang lang.Lang
GiveOpts []interface{}
WantResult string
WantErr error
}{
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.RU,
WantResult: "Одна",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithFmtFracIgnore(true)},
WantResult: "Одна",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithFmtGender(gender.Female), ru.WithFmtFracIgnore(true)},
WantResult: "Одна",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithFmtGender(gender.Male), ru.WithFmtFracIgnore(true)},
WantResult: "Один",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithFmtGender(gender.Neuter), ru.WithFmtFracIgnore(true)},
WantResult: "Одно",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithFmtGender(gender.Neuter)},
WantResult: "Одно",
},
{
GiveInt: "1541", GiveInt64: 1541, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithFmtGender(gender.Male)},
WantResult: "одна тысяча пятьсот сорок один",
},
{
GiveInt: "1541", GiveInt64: 1541, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithFmtGender(gender.Male)},
WantResult: "одна тысяча пятьсот сорок один",
},
{
GiveInt: "2", GiveInt64: 2, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithFmtFracUseDigits(true)},
WantResult: "Две",
},
{
GiveInt: "2", GiveInt64: 2, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithFmtFracUseDigits(true), ru.WithFmtFracIgnore(true)},
WantResult: "Две",
},
{
GiveInt: "2", GiveInt64: 2, GiveLang: lang.RU,
WantResult: "Две",
},
{
GiveInt: "2", GiveInt64: 2, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithParseFracLen(2)},
WantResult: "Две",
},
{
GiveInt: "2", GiveInt64: 2, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithParseFracLen(3)},
WantResult: "Две",
},
{
GiveInt: "2", GiveInt64: 2, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithParseFracLen(0)},
WantResult: "Две",
},
{
GiveInt: "2", GiveInt64: 2, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithParseFracLen(3)},
WantResult: "Две",
},
{
GiveInt: "2", GiveInt64: 2, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithParseFracLen(3), ru.WithFmtFracIgnore(true), ru.WithFmtFracUseDigits(true)},
WantResult: "Две",
},
{
GiveInt: "2", GiveInt64: 2, GiveLang: lang.RU, GiveOpts: []interface{}{ru.WithParseFracLen(2), ru.WithParseSep(',')},
WantResult: "Две",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.Lang(5),
WantResult: "", WantErr: lang.ErrBadLanguage,
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.Unknown,
WantResult: "", WantErr: lang.ErrBadLanguage,
},
{
GiveInt: "-88", GiveInt64: -88, GiveLang: lang.KZ,
WantResult: "минус сексен сегіз",
},
{
GiveInt: "-88", GiveInt64: -88, GiveLang: lang.KZ,
WantResult: "минус сексен сегіз",
},
{
GiveInt: "-88", GiveInt64: -88, GiveLang: lang.KZ, GiveOpts: []interface{}{kz.WithFmtFracUseDigits(true)},
WantResult: "минус сексен сегіз",
},
{
GiveInt: "-88", GiveInt64: -88, GiveLang: lang.KZ, GiveOpts: []interface{}{kz.WithParseFracLen(2)},
WantResult: "минус сексен сегіз",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.KZ,
WantResult: "бір",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.KZ, GiveOpts: []interface{}{kz.WithParseFracLen(2)},
WantResult: "бір",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.KZ, GiveOpts: []interface{}{kz.WithParseFracLen(1)},
WantResult: "бір",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.KZ, GiveOpts: []interface{}{kz.WithParseFracLen(1), kz.WithFmtFracUseDigits(true)},
WantResult: "бір",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.KZ, GiveOpts: []interface{}{kz.WithFmtFracIgnore(true)},
WantResult: "бір",
},
{
GiveInt: "1", GiveInt64: 1, GiveLang: lang.EN, GiveOpts: []interface{}{en.WithFmtFracIgnore(true)},
WantResult: "one",
},
}
func TestInt64(t *testing.T) {
for _, v := range testCaseIntNumbers {
gotResult, gotErr := Int64(v.GiveInt64, v.GiveLang, v.GiveOpts...)
if !errors.Is(gotErr, v.WantErr) {
t.Errorf("%s: \nexp: '%s' \ngot: '%s'", v.GiveInt, v.WantErr, gotErr)
}
if gotErr == nil {
if !strings.EqualFold(gotResult, v.WantResult) {
t.Errorf("%s: \nexp: '%s' \ngot: '%s'", v.GiveInt, v.WantResult, gotResult)
}
}
}
}
func TestMustInt64(t *testing.T) {
for _, v := range testCaseIntNumbers {
gotResult := MustInt64(v.GiveInt64, v.GiveLang, v.GiveOpts...)
if v.WantErr != nil && gotResult != "" {
t.Errorf("%s: expected error", v.GiveInt)
}
if gotResult != "" {
if !strings.EqualFold(gotResult, v.WantResult) {
t.Errorf("%s: \nexp: '%s' \ngot: '%s'", v.GiveInt, v.WantResult, gotResult)
}
}
}
}