-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig_test.go
More file actions
78 lines (69 loc) · 1.98 KB
/
config_test.go
File metadata and controls
78 lines (69 loc) · 1.98 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
package validator
import (
"errors"
"testing"
)
func TestChangeDefaultLanguage(t *testing.T) {
var tests = []struct {
input, expected string
}{
//Unsupported Languages
{"ch", "en"},
{"fa", "en"},
// Supported Languages
{"tr", "tr"},
{"de", "de"},
{"en", "en"},
}
for _, test := range tests {
if output := ChangeDefaultLanguage(test.input); output != test.expected {
t.Errorf("Test Failed! Input:%s Expected:%s Output:%s", test.input, test.expected, output)
}
}
}
func TestChangeTagName(t *testing.T) {
var tests = []struct {
input, expected string
}{
{"=", "validate"},
{"validator", "validator"},
{"tagName", "tagName"},
{"validate", "validate"},
}
for _, test := range tests {
if output := ChangeTagName(test.input); output != test.expected {
t.Errorf("Test Failed! Input:%s Expected:%s Output:%s", test.input, test.expected, output)
}
}
}
func TestChangeMessage(t *testing.T) {
var tests = []struct {
inputValidation, inputMessage string
expected error
}{
{"notNull", "new message for notNull", nil},
{"eqString", "new message for eq", nil},
{"gteNumber", "new message fot gte", nil},
{"contains", "new message for contains", nil},
{"something_else", "new message", errors.New("unknown validation tag")},
}
for _, test := range tests {
output := ChangeMessage(test.inputValidation, test.inputMessage)
if (output == nil && output != test.expected) || (output != nil && errors.Is(output, test.expected)) {
t.Errorf("Test Failed: InputValidation: %s Expected: %v Output: %v", test.inputValidation, test.expected, output)
}
}
}
func TestChangeSpecialChars(t *testing.T) {
var tests = []struct {
input, expected string
}{
{"@#$%^&+!?.,;:=", "@#$%^&+!?.,;:"}, // "=" not allowed
{"@#$%^&+!?", "@#$%^&+!?"},
}
for _, test := range tests {
if output := ChangeSpecialChars(test.input); output != test.expected {
t.Errorf("Test Failed! Input:%s Expected:%s Output:%s", test.input, test.expected, output)
}
}
}