[antlr-interest] check validity of single rule
David Holroyd
dave at badgers-in-foil.co.uk
Sun Dec 30 12:58:03 PST 2007
On Sun, Dec 30, 2007 at 07:16:57PM +0100, Philippe Faes wrote:
> e.g. I want this to pass:
> createParserFromString("a:=b;").assignment();
>
> but this should fail:
> createParserFromString("a:=b").assignment(); // no semicolon
> createParserFromString("a:=b; #$%").assignment(); // junk after statement
>
> From the return value I can see if an 'assignment' is matched from the text,
> but I cannot detect if there is junk after the valid assignment.
If you arrange for the test code to have access to the TokenStream, you
could assert that the next token is EOF.
If you put each of these fragments into separate JUnit test methods, you
could additionally extract the EOF-assertion into the tearDown() method
for the TestCase too.
ta,
dave
--
http://david.holroyd.me.uk/
More information about the antlr-interest
mailing list