Sha256: d75f3bef51caf7f215ab5d2f7afc0c31bbe7d428f29132bca3015918ca15ce25
Contents?: true
Size: 836 Bytes
Versions: 1
Compression:
Stored size: 836 Bytes
Contents
require 'test/unit' require 'rockit/dparser' class ATestArithmeticGrammar < Test::Unit::TestCase ArithmeticTestGrammar = Rockit::DParser::Grammar.new do start :Expr, [ [:Digit, "+", :Digit, ast(:Add, 0, 2)], [:Digit, "*", :Digit, ast(:Mult, 0, 2)], ] term :Digit, /[0-9]+/ end def test_03_use_parser parser = ArithmeticTestGrammar.new_parser ast = parser.parse "12+34" assert_equal("Add", ast.name) assert_kind_of(parser.astclass_of_name(:Add), ast) assert_equal(2, ast.num_children) assert_equal("12", ast[0]) assert_equal("34", ast[1]) ast = parser.parse "567*980" assert_equal("Mult", ast.name) assert_kind_of(parser.astclass_of_name(:Mult), ast) assert_equal(2, ast.num_children) assert_equal("567", ast[0]) assert_equal("980", ast[1]) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rockit-0.7.1 | tests/acceptance/rockit/dparser/atest_arithmetic_grammar.rb |