-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathutils_test.go
129 lines (98 loc) · 2.5 KB
/
utils_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
package kolpa
import (
"reflect"
"testing"
)
func compareSlices(a, b []string) bool {
if a == nil && b == nil {
return true
}
if a == nil || b == nil {
return false
}
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
func TestParser(t *testing.T) {
var testString = "{{value}} test"
var testReplacer = map[string]string{
"value": "test",
}
k := C()
if k.parser(testString, testReplacer) != "test test" {
t.Errorf("Parser is failed.")
}
}
func TestAppendMultiple(t *testing.T) {
var testSlice = []string{"test", "testing"}
var resultSlice = []string{"test", "testing", "test", "testing"}
if !compareSlices(appendMultiple(testSlice, testSlice), resultSlice) {
t.Errorf("AppendMultiple function is failed")
}
}
func TestFormatToSlice(t *testing.T) {
var input = "{{prefix_female}} {{female_first_name}}"
var output = []string{"prefix_female", "female_first_name"}
k := C()
if !compareSlices(k.formatToSlice(input), output) {
t.Errorf("FormatToSlice function is failed")
}
}
func TestAppendMultipleWithSlice(t *testing.T) {
var testFile = []string{"phone", "email"}
var wrongTestFile = []string{"test"}
k := C()
result, err := k.appendMultipleWithSlice(testFile)
if reflect.TypeOf(result).Kind() != reflect.Slice || err != nil {
t.Errorf("AppendMultipleWithSlice function failed")
}
result, err = k.appendMultipleWithSlice(wrongTestFile)
if err == nil {
t.Errorf("AppendMultipleWithSlice function failed")
}
}
func TestMapLine(t *testing.T) {
var input = []string{"test", "anothertest"}
var m = map[string]string{}
mapLine(input, m)
if len(m) == 0 {
t.Errorf("MapLine function failed")
}
}
func TestIsNumeric(t *testing.T) {
k := C()
var inputFalse = []string{"test"}
var inputEmpty = []string{}
var inputTrue = []string{"##9##"}
if k.isNumeric(inputFalse) || k.isNumeric(inputEmpty) {
t.Errorf("IsNumeric function failed")
}
if !k.isNumeric(inputTrue) {
t.Errorf("IsNumeric function failed")
}
}
func TestIsParseable(t *testing.T) {
k := C()
var inputFalse = "test"
var inputEmpty = ""
if k.isParseable(inputFalse) || k.isParseable(inputEmpty) {
t.Errorf("IsParseable function failed")
}
}
func TestParseRandomToBoolean(t *testing.T) {
if !parseRandomToBoolean(0.3) || parseRandomToBoolean(0.7) {
t.Errorf("ParseRandomToBoolean function failed")
}
}
func TestRandBool(t *testing.T) {
if reflect.TypeOf(randBool()).Kind() != reflect.Bool {
t.Errorf("RandBool function failed")
}
}