(t *testing.T)
| 104 | } |
| 105 | |
| 106 | func TestParser(t *testing.T) { |
| 107 | for _, test := range parserTests { |
| 108 | parser, err := Parse(test.name, test.text) |
| 109 | if test.shouldError { |
| 110 | if err == nil { |
| 111 | t.Errorf("unexpected non-error when parsing %s", test.name) |
| 112 | } |
| 113 | continue |
| 114 | } |
| 115 | if err != nil { |
| 116 | t.Errorf("parse %s error %v", test.name, err) |
| 117 | } |
| 118 | result := collectNode([]Node{}, parser.Root)[1:] |
| 119 | if len(result) != len(test.nodes) { |
| 120 | t.Errorf("in %s, expect to get %d nodes, got %d nodes", test.name, len(test.nodes), len(result)) |
| 121 | t.Error(result) |
| 122 | } |
| 123 | for i, expect := range test.nodes { |
| 124 | if result[i].String() != expect.String() { |
| 125 | t.Errorf("in %s, %dth node, expect %v, got %v", test.name, i, expect, result[i]) |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | type failParserTest struct { |
| 132 | name string |
nothing calls this directly
no test coverage detected