[antlr-interest] JUnit testing of ASTs
stefan
stefan at amiq.ro
Wed Dec 22 03:03:29 PST 2004
On Tuesday 21 December 2004 20:20, Paul J. Lucas wrote:
> Does anybody do JUnit regression testing on their parsers? If
> so, how, exactly?
>
> For lack of anything better, *a* way of doing it is to have a
> set of files to parse and the pretty-printed output of the
> expected ASTs. Then, when you run the tests, simply diff their
> output with the expected output.
>
> Anything better?
Hello Paul,
you can do more than diff-ing pretty-printed AST. You can
walk the AST and check the node type and node value versus a golden model. I
personally used this kind of checking during parser verification.
The golden model can be something like :
...............................................
// for source code :
2 * (b + a)
// a possible expected/resulted AST would be :
[MUL, “*”]
|--[NUMERIC_LITERAL, “2”]
|--[PLUS, “+”]
| |--[ID, “b”]
| |--[ID, “a”]
................................................
For this kind of testing you can look over Bogdan Mitu's tester (see
files at antlr-interest at yahoo group).
Stefan.
> - Paul
>
> _______________________________________________
> antlr-interest mailing list
> antlr-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/antlr-interest
More information about the antlr-interest
mailing list