-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_test.go
97 lines (80 loc) · 1.95 KB
/
data_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
package html5tag
import (
"fmt"
"testing"
)
func ExampleToDataAttr() {
s, _ := ToDataAttr("thisIsMyTest")
fmt.Println(s)
// Output: this-is-my-test
}
func ExampleToDataJqKey() {
s, _ := ToDataKey("this-is-my-test")
fmt.Println(s)
// Output: thisIsMyTest
}
func TestToDataAttr(t *testing.T) {
cases := []struct {
in, expected string
err bool
}{
{"ThisThat", "", true},
{"thisANDthat", "", true},
{"That", "", true},
{"", "", false},
{"this", "this", false},
{"thisAndThat", "this-and-that", false},
{"this and that", "", true},
}
for _, c := range cases {
result, err := ToDataAttr(c.in)
if err != nil {
if c.err { // expected an error
continue
} else {
t.Errorf("Unexpected error on (%q): %v", c.in, err)
continue
}
}
if c.err && err == nil { // expected an error, but didn't get one
t.Errorf("Expected error on (%q)", c.in)
continue // no sense in checking other things, since we were expecting an error
}
if result != c.expected {
t.Errorf("ToDataAttr failed on (%q) expected (%q) got (%q)", c.in, c.expected, result)
}
}
}
func TestToDataKey(t *testing.T) {
cases := []struct {
in, expected string
err bool
}{
{"ThisThat", "", true},
{"thisANDthat", "", true},
{"That", "", true},
{"", "", false},
{"this", "this", false},
{"this-and-that", "thisAndThat", false},
{"this and that", "", true},
{"a-b-c", "", true},
}
for _, c := range cases {
result, err := ToDataKey(c.in)
if err != nil {
if c.err { // expected an error
continue
} else {
t.Errorf("Unexpected error on (%q): %v", c.in, err)
continue
}
}
if c.err && err == nil { // expected an error, but didn't get one
t.Errorf("Expected error on (%q)", c.in)
continue // no sense in checking other things, since we were expecting an error
}
if result != c.expected {
t.Errorf("ToDataKey failed on (%q) expected (%q) got (%q)", c.in, c.expected, result)
}
}
}