|
1 | 1 | package parser |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | 4 | "github.com/planklang/goplank/lexer" |
6 | 5 | "github.com/planklang/goplank/parser/types" |
7 | 6 | "testing" |
@@ -37,18 +36,21 @@ func TestParse(t *testing.T) { |
37 | 36 | if arg.Type() != types.DefaultLiteralType { |
38 | 37 | t.Errorf("Excepted %s, got %s", types.DefaultLiteralType, arg.Type()) |
39 | 38 | } |
40 | | - fmt.Printf("%s %s\n", arg.Type(), arg.Value()) |
41 | | - p, ok := arg.Value().(types.Literal) |
| 39 | + p, ok := arg.Value().(string) |
42 | 40 | if !ok { |
43 | 41 | t.Errorf("Cannot convert %s to literal", arg.Value()) |
44 | 42 | } |
45 | | - if p.Value() != "x" { |
46 | | - t.Error("Expected x, got", p.Value()) |
| 43 | + if p != "x" { |
| 44 | + t.Error("Expected x, got", p) |
47 | 45 | } |
48 | 46 | //TODO: check range |
49 | 47 | if len(axis.Modifiers) != 0 { |
50 | 48 | t.Error("Expected zero modifiers, got", len(axis.Modifiers)) |
51 | 49 | } |
| 50 | + if t.Failed() { |
| 51 | + println(tree) |
| 52 | + t.FailNow() |
| 53 | + } |
52 | 54 |
|
53 | 55 | lex, err = lexer.Lex("axis x 'Label'") |
54 | 56 | if err != nil { |
@@ -79,26 +81,30 @@ func TestParse(t *testing.T) { |
79 | 81 | if arg1.Type() != types.DefaultLiteralType { |
80 | 82 | t.Errorf("Excepted %s, got %s", types.DefaultLiteralType, arg1.Type()) |
81 | 83 | } |
82 | | - p, ok = arg1.Value().(types.Literal) |
| 84 | + p, ok = arg1.Value().(string) |
83 | 85 | if !ok { |
84 | | - t.Errorf("Cannot convert %s to literal", arg1.Value()) |
| 86 | + t.Errorf("Cannot convert %s to literal", arg1.Type()) |
85 | 87 | } |
86 | | - if p.Value() != "x" { |
87 | | - t.Error("Expected x, got", p.Value()) |
| 88 | + if p != "x" { |
| 89 | + t.Error("Expected x, got", p) |
88 | 90 | } |
89 | 91 | arg2 := vs[1] |
90 | 92 | if arg2.Type() != types.StringType { |
91 | 93 | t.Errorf("Excepted %s, got %s", types.StringType, arg1.Type()) |
92 | 94 | } |
93 | | - p2, ok := arg1.Value().(types.String) |
| 95 | + p2, ok := arg2.Value().(string) |
94 | 96 | if !ok { |
95 | | - t.Errorf("Cannot convert %s to literal", arg2.Value()) |
| 97 | + t.Errorf("Cannot convert %s to string", arg2.Type()) |
96 | 98 | } |
97 | | - if p2.Value() != "Label" { |
98 | | - t.Error("Expected Label, got", p2.Value()) |
| 99 | + if p2 != "Label" { |
| 100 | + t.Error("Expected Label, got", p2) |
99 | 101 | } |
100 | 102 | //TODO: check range |
101 | 103 | if len(axis.Modifiers) != 0 { |
102 | 104 | t.Error("Expected zero modifiers, got", len(axis.Modifiers)) |
103 | 105 | } |
| 106 | + if t.Failed() { |
| 107 | + println(tree.String()) |
| 108 | + t.FailNow() |
| 109 | + } |
104 | 110 | } |
0 commit comments