I am writing antlr4 grammar for a closed programming language. The application code i would be writing in python.
Now, i would like to unit/integration test all the grammar rules against the possible combinations of the language. For unit testing i am thinking of the below approaches. If anyone has worked on something similar can you give me directions on which method would be suitable ?
- Files with lots of possible combination and their respective tree output in another file.So in python i would be reading all the files generating parse tree and then comparing the tree result with the output file.
- For every grammar rule creating a test file in that writing many methods which would give the input in string and match the tree output with string. But i am thinking this would be becoming too complex for rules supporting many combinations.It would too many test function calls and in that creating parse tree.
- In this method it would be similar to method 2 but instead of comparing the tree strings to the output i would be checking whether each token/subrule in the grammar is identified as per the expectations or not. But over here it would be complicated for rules which are supporting multiple options as i would need to check which option passed and then again test accordingly.
Any help for this would be very much appreciated.