-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
54 lines (44 loc) · 1.06 KB
/
Copy pathparser_test.go
File metadata and controls
54 lines (44 loc) · 1.06 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
package klon
import (
"testing"
"github.com/ProCode-Software/klar/pkg/klon/ast"
)
func TestParser_DashedBlock(t *testing.T) {
input := `
object:
- a: 1
- b: 2
`
doc, errs := Parse([]byte(input))
if len(errs) > 0 {
t.Fatalf("unexpected errors: %v", errs)
}
obj, ok := doc.Body.(*ast.Object)
if !ok {
t.Fatalf("expected *ast.Object, got %T", doc.Body)
}
if len(obj.Fields) != 1 {
t.Fatalf("expected 1 field, got %d", len(obj.Fields))
}
innerObj, ok := obj.Fields[0].Value.(*ast.Object)
if !ok {
t.Fatalf("expected *ast.Object for 'object' value, got %T", obj.Fields[0].Value)
}
if len(innerObj.Fields) != 2 {
t.Fatalf("expected 2 fields in inner object, got %d", len(innerObj.Fields))
}
}
func TestParser_InlineList(t *testing.T) {
input := `[4, 1, 6, 7]`
doc, errs := Parse([]byte(input))
if len(errs) > 0 {
t.Fatalf("unexpected errors: %v", errs)
}
list, ok := doc.Body.(*ast.List)
if !ok {
t.Fatalf("expected *ast.List, got %T", doc.Body)
}
if len(list.Items) != 4 {
t.Fatalf("expected 4 items in list, got %d", len(list.Items))
}
}