soml-parser/test/README.md

60 lines
2.1 KiB
Markdown
Raw Normal View History

2014-06-04 20:07:47 +02:00
##Running Tests
To run all tests, type
ruby test/test_all.rb
2015-05-01 15:26:26 +02:00
to run just a single, replace all with what you want to test. Minitest accept a -n option to run just a single test. So while developing i often write things like
2014-06-04 20:07:47 +02:00
ruby test/test_class.rb -n test_class_ops_parse
2015-05-01 15:26:26 +02:00
Notice tough the "_parse" at the end, while you will find no such function.
The Magic (explained below) generates three functions per case.
Your options are "_parse" , "_transform" , or if it's really bad, "_ast"
(this should really work when the previous two work)
2014-06-04 20:07:47 +02:00
2014-06-26 13:24:24 +02:00
### Directories
2015-05-01 15:26:26 +02:00
Currently we have two directories for test.
2014-06-26 13:24:24 +02:00
- unit tests map to parser modules and specify the parser rule they test
2015-05-01 15:26:26 +02:00
- root test test much of the same functionality, but as root (rule) tests.
2014-06-26 13:24:24 +02:00
2015-05-01 15:26:26 +02:00
The root tests need to be separate to check if separate rules interfere with each other.
2014-06-04 18:56:50 +02:00
2014-06-26 13:24:24 +02:00
Apart from just plain more tests, two additional directories are planned. One is larger tests and the other is failing tests.
###Parsing
2014-06-04 18:56:50 +02:00
Parsing is a two step process with parslet:
- parse takes an input and outputs hashes/arrays with basic types
- transform takes the output of parse and generates an ast (as specified by the transformation)
2014-06-04 18:56:50 +02:00
2015-05-01 15:26:26 +02:00
A test tests both phases separately and again together.
2014-06-04 18:56:50 +02:00
Each test must thus specify (as instance variables):
- the string input
- the parse output
- the transform output
2014-06-04 20:07:47 +02:00
### Magic
2014-06-04 18:56:50 +02:00
Test are grouped by functionality into cases (classes) and define methods test_*
2015-05-01 15:26:26 +02:00
Test cases must include ParserHelper, which includes the magic to write the 3 test methods for each
2014-06-04 18:56:50 +02:00
test method. See test_basic for easy example.
Example:
def test_number
@string_input = '42 '
@test_output = {:integer => '42'}
@transform_output = Parser::IntegerExpression.new(42)
@parser = @parser.integer
end
The first three lines define the data as described above.
The last line tells the parser what to parse. This is off couse only needed when a non-root rule is tested
and should be left out if possible.
2015-05-01 15:26:26 +02:00
As can be seen, there are no asserts. All asserting is done by the created methods, which call
2014-06-04 20:07:47 +02:00
the check_* methods in helper.