-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
ident_test.go
112 lines (103 loc) · 2.69 KB
/
ident_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
package flect
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_New(t *testing.T) {
table := []Ident{
{"", []string{}},
{"widget", []string{"widget"}},
{"widget_id", []string{"widget", "ID"}},
{"WidgetID", []string{"Widget", "ID"}},
{"Widget_ID", []string{"Widget", "ID"}},
{"widget_ID", []string{"widget", "ID"}},
{"widget/ID", []string{"widget", "ID"}},
{"widgetID", []string{"widget", "ID"}},
{"widgetName", []string{"widget", "Name"}},
{"JWTName", []string{"JWT", "Name"}},
{"JWTname", []string{"JWTname"}},
{"jwtname", []string{"jwtname"}},
{"sql", []string{"SQL"}},
{"sQl", []string{"SQL"}},
{"id", []string{"ID"}},
{"Id", []string{"ID"}},
{"iD", []string{"ID"}},
{"html", []string{"HTML"}},
{"Html", []string{"HTML"}},
{"HTML", []string{"HTML"}},
{"with `code` inside", []string{"with", "`code`", "inside"}},
{"Donald E. Knuth", []string{"Donald", "E.", "Knuth"}},
{"Random text with *(bad)* characters", []string{"Random", "text", "with", "*(bad)*", "characters"}},
{"Allow_Under_Scores", []string{"Allow", "Under", "Scores"}},
{"Trailing bad characters!@#", []string{"Trailing", "bad", "characters!@#"}},
{"!@#Leading bad characters", []string{"!@#", "Leading", "bad", "characters"}},
{"Squeeze separators", []string{"Squeeze", "separators"}},
{"Test with + sign", []string{"Test", "with", "sign"}},
{"Malmö", []string{"Malmö"}},
{"Garçons", []string{"Garçons"}},
{"Opsů", []string{"Opsů"}},
{"Ærøskøbing", []string{"Ærøskøbing"}},
{"Aßlar", []string{"Aßlar"}},
{"Japanese: 日本語", []string{"Japanese", "日本語"}},
}
for _, tt := range table {
t.Run(tt.Original, func(st *testing.T) {
r := require.New(st)
i := New(tt.Original)
r.Equal(tt.Original, i.Original)
r.Equal(tt.Parts, i.Parts)
})
}
}
func Test_MarshalText(t *testing.T) {
r := require.New(t)
n := New("mark")
b, err := n.MarshalText()
r.NoError(err)
r.Equal("mark", string(b))
r.NoError((&n).UnmarshalText([]byte("bates")))
r.Equal("bates", n.String())
}
func Benchmark_New(b *testing.B) {
table := []string{
"",
"widget",
"widget_id",
"WidgetID",
"Widget_ID",
"widget_ID",
"widget/ID",
"widgetID",
"widgetName",
"JWTName",
"JWTname",
"jwtname",
"sql",
"sQl",
"id",
"Id",
"iD",
"html",
"Html",
"HTML",
"with `code` inside",
"Donald E. Knuth",
"Random text with *(bad)* characters",
"Allow_Under_Scores",
"Trailing bad characters!@#",
"!@#Leading bad characters",
"Squeeze separators",
"Test with + sign",
"Malmö",
"Garçons",
"Opsů",
"Ærøskøbing",
"Aßlar",
"Japanese: 日本語",
}
for n := 0; n < b.N; n++ {
for i := range table {
New(table[i])
}
}
}