| 1 | package astx |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/goccmack/gocc/example/errorrecovery/ast" |
| 8 | "github.com/goccmack/gocc/example/errorrecovery/errors" |
| 9 | "github.com/goccmack/gocc/example/errorrecovery/lexer" |
| 10 | "github.com/goccmack/gocc/example/errorrecovery/parser" |
| 11 | ) |
| 12 | |
| 13 | func TestFail(t *testing.T) { |
| 14 | sml, err := test([]byte("a b ; d e f")) |
| 15 | if err != nil { |
| 16 | t.Fail() |
| 17 | } |
| 18 | fmt.Print("output: [\n") |
| 19 | for _, s := range sml { |
| 20 | switch sym := s.(type) { |
| 21 | case *errors.Error: |
| 22 | fmt.Printf("%s\n", sym) |
| 23 | default: |
| 24 | fmt.Printf("\t%v\n", sym) |
| 25 | } |
| 26 | } |
| 27 | fmt.Println("]") |
| 28 | } |
| 29 | |
| 30 | func test(src []byte) (astree ast.StmtList, err error) { |
| 31 | fmt.Printf("input: %s\n", src) |
| 32 | s := lexer.NewLexer(src) |
| 33 | p := parser.NewParser() |
| 34 | a, err := p.Parse(s) |
| 35 | if err == nil { |
| 36 | astree = a.(ast.StmtList) |
| 37 | } |
| 38 | return |
| 39 | } |