forked from DataDog/jsonapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
member_names_test.go
64 lines (57 loc) · 1.34 KB
/
member_names_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
package jsonapi
import (
"testing"
"github.com/DataDog/jsonapi/internal/is"
)
func TestIsValidMemberName(t *testing.T) {
t.Parallel()
// associate member name strings with the strictest validation mode they should pass
testValidations := map[MemberNameValidationMode][]string{
StrictValidation: {
"a",
"lowercase",
"lowercase1with2numerals",
"camelCase",
"camel12Case9WithNumera1s",
},
DefaultValidation: {
"A",
"9camelCaseWithNumeralPrefix",
"camelCaseWithNumeralSuffix10",
"4camelCaseWithSurroundingNumerals5",
"camelC",
"PascalCase",
"dash-case",
"snake_case",
"space case",
"cRaZyCasE",
"12",
"ƒunky unicode",
},
DisableValidation: {
"bad%character",
},
}
for mode, names := range testValidations {
mode := mode
for _, name := range names {
name := name
t.Run(name, func(t *testing.T) {
t.Parallel()
passesStrict := isValidMemberName(name, StrictValidation)
passesDefault := isValidMemberName(name, DefaultValidation)
switch mode {
case StrictValidation:
is.Equal(t, true, passesStrict)
is.Equal(t, true, passesDefault)
case DefaultValidation:
is.Equal(t, false, passesStrict)
is.Equal(t, true, passesDefault)
case DisableValidation:
is.Equal(t, false, passesStrict)
is.Equal(t, false, passesDefault)
}
})
}
}
}