-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnumero_test.go
More file actions
executable file
·89 lines (79 loc) · 1.82 KB
/
numero_test.go
File metadata and controls
executable file
·89 lines (79 loc) · 1.82 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package numero
import (
"testing"
)
func TestDigitOnly(t *testing.T) {
tests := []struct {
inputText string
expectedResult bool
}{
{"abc", false},
{"1234", true},
{"۱۲۳۴", true},
{"۱۲بA", false},
}
for _, test := range tests {
result := DigitOnly(test.inputText)
if result != test.expectedResult {
t.Errorf("Expected %v got %v.", test.expectedResult, result)
}
}
}
func TestNormalize(t *testing.T) {
tests := []struct {
inputText, expectedText string
}{
{"abc", "abc"},
{"1234", "1234"},
{"۱۲۳۴", "1234"},
{"۱۲بA", "12بA"},
}
for _, test := range tests {
result := Normalize(test.inputText)
if result != test.expectedText {
t.Errorf("Expected %v got %v.", test.expectedText, result)
}
}
}
func TestNormalizeAsNumber(t *testing.T) {
tests := []struct {
inputText string
expectedNumber interface{}
}{
{"1234", 1234},
{"12.34", 12.34},
{"۱۲۳۴", 1234},
{"۱۲.۳۴", 12.34},
}
for _, test := range tests {
result, _ := NormalizeAsNumber(test.inputText)
if result != test.expectedNumber {
t.Errorf("Expected %v got %v.", test.expectedNumber, result)
}
}
}
func TestRemoveNonDigits(t *testing.T) {
tests := []struct {
inputText string
inputExceptions []rune
expectedResult string
}{
{"1234abcd", []rune{}, "1234"},
{"12.34abcd", []rune{}, "1234"},
{"۱۲🙃۳۴abcd", []rune{}, "1234"},
{"۱۲.۳۴abcd", []rune{}, "1234"},
{"1234abcd", []rune{'b'}, "1234b"},
{"12.34abcd", []rune{'b'}, "1234b"},
}
for _, test := range tests {
var result string
if len(test.inputExceptions) > 0 {
result = RemoveNonDigits(test.inputText, test.inputExceptions...)
} else {
result = RemoveNonDigits(test.inputText)
}
if result != test.expectedResult {
t.Errorf("Expected %v got %v.", test.expectedResult, result)
}
}
}