Grammar Testing
Unit testing is the best way I've found to really develop a grammar. It allows you to focus on very specific pieces of the grammar at a time, then later put it all together by parsing an entire document.
This library depends upon php-tests for testing.
Links:
- Writing a Grammar: doc/GrammarWriting.md
- Grammar Example: doc/GrammarExample.md
- Grammar Commands: doc/GrammarCommands.md
Howto
- Extend
\Tlf\Lexer\Test\Tester
which extends from\Tlf\Tester
or copy the methods from it & modify as needed for a different testing library. - Implement a
testGrammarName()
method that uses the test runner - Implement the data structure for defining the unit tests.
Example of 2.
:
public function testPhpDirectives() {
Cannot find 'body' part of 'methods.testPhpDirectives.body' on 'Tlf\Lexer\Test\PhpGrammar'. You may try one of: type, modifiers, docblock, name, definition, arglist
}
Example of 3.
:
-- whatever goes here