-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_test.go
More file actions
63 lines (48 loc) · 2.45 KB
/
parse_test.go
File metadata and controls
63 lines (48 loc) · 2.45 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
package namespace
import (
"strings"
"testing"
"github.com/yehan2002/is/v2"
)
type simpleKeyTest struct{}
func TestSimpleKey(t *testing.T) { is.Suite(t, &simpleKeyTest{}) }
func (s *simpleKeyTest) TestParse(is is.Is) {
test := func(inp string, strict, noSeparator, nsOnly bool, ns, key string, err error) {
is.T().Helper()
ns2, k2, err2 := parseNSK(inp, strict, noSeparator, nsOnly)
is.Err(err2, err, "Expected error to be %v got %v", err, err2)
is(ns2 == ns, "Expected ns to be %#v got %#v", ns, ns2)
is(k2 == key, "Expected key to be %#v got %#v", key, k2)
}
test("minecraft:air", false, false, false, "minecraft", "air", nil)
test("minecraft:blocks/air", false, false, false, "minecraft", "blocks/air", nil)
test("minecraft:blocks/air.2", false, false, false, "minecraft", "blocks/air.2", nil)
test("minecraft:AIR", false, false, false, "minecraft", "air", nil)
test("abc:;;;123", false, false, false, "abc", "___123", nil)
test("a;bc:a", false, false, false, "a_bc", "a", nil)
test("a;bc:a/a", false, false, false, "a_bc", "a/a", nil)
test("a/bc:a", false, false, false, "a_bc", "a", nil)
test("a;:v/a", false, false, false, "a_", "v/a", nil)
test("a:", false, true, false, "minecraft", "a_", nil)
test("a::", false, true, false, "minecraft", "a__", nil)
test("aa:aa", false, true, true, "aa_aa", "", nil)
test("aa:aa", false, false, true, "aa_aa", "", nil)
test("aa:aa", false, true, false, "minecraft", "aa_aa", nil)
test("aa/aa", false, true, false, "minecraft", "aa/aa", nil)
test("aa/aa", false, false, false, "minecraft", "aa/aa", nil)
test("aa.aa", false, false, false, "minecraft", "aa.aa", nil)
test("a/a:b", false, false, false, "a_a", "b", nil)
test("a.a:b", false, false, false, "a_a", "b", nil)
test("aa:", false, false, false, "", "", ErrTrailingSep)
test("aa:", true, false, false, "", "", ErrTrailingSep)
test("", true, false, false, "", "", ErrEmpty)
test("", true, false, true, defaultNamespace, "", nil)
test("a/a:a", true, false, false, "", "", ErrInvalidChar)
test("a:a:a", true, false, false, "", "", ErrInvalidChar)
test("a:a", true, false, true, "", "", ErrInvalidChar)
test(string([]byte{'a', ':', 0}), true, false, false, "", "", ErrInvalidChar)
test(string([]byte{'a', ':', 255}), true, false, false, "", "", ErrInvalidChar)
test("a:𐍈", true, false, false, "", "", ErrInvalidChar)
test("a:𐍈", false, false, false, "a", "_", nil)
test(strings.Repeat("a", maxLength+1), true, false, false, "", "", ErrTooLong)
}