-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser_test.go
56 lines (52 loc) · 1.35 KB
/
parser_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
package kdlgo
import (
"strconv"
"testing"
)
func TestParseFromFile(t *testing.T) {
objs, err := ParseFile("test.kdl")
if err != nil {
t.Fatal(err)
}
expected := []string{
`firstkey "first\n\ttab\nnewline\"\nval" "testing\""`,
`numbers 543 234 85720394`,
`thirdkey true null`,
`secondkey 12 "test" null false "testagain"`,
`anotherkey "true" 123.543 null true`,
`moreKeys false true`,
`keyonly`,
`testcomment`,
`objects { node1 12; node2 "string"; node3 null; }`,
`multiline-node "random"`,
`title "Some title"`,
`"quoted node" "quoted value"`,
`"quoted node for numbers" 21 43 465 "string"`,
`smile "😁"`,
`!@#$@$%Q#$%~@!40 "1.2.3" { !!!!! true; }`,
`foo123~!@#$%^&*.:'|/?+ "weeee"`,
`ノード { お名前 "☜(゚ヮ゚☜)"; }`,
`foo { bar true; } "baz" { quux false; } 1 2 3`,
`key "value"`,
`test "value"`,
}
if len(objs.GetValue().Objects) != len(expected) {
t.Fatal(
"There should be " + strconv.Itoa(len(expected)) +
" KDLObjects. Got " + strconv.Itoa(len(objs.GetValue().Objects)) + " instead.",
)
}
for i, obj := range objs.GetValue().Objects {
s, err := RecreateKDLObj(obj)
if err != nil {
t.Fatal(err)
return
}
if s != expected[i] {
t.Error(
"Item number "+strconv.Itoa(i+1)+" is incorrectly parsed.\n",
"Expected: '"+expected[i]+"' but got '"+s+"' instead",
)
}
}
}