Sha256: 31c3f7932c98bfbb5145853c9c4e8037fb194697e8fdb3942dee061d9e9fccba
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
require 'test/unit' require 'rockit/dparser' class ATestPlusOperator < Test::Unit::TestCase PlusTestGrammar = Rockit::DParser::Grammar.new do start :S, [plus(:A)], value(0) term :A, ["a"] end Parser = PlusTestGrammar.new_parser def test_01_multiple_occurences (2..20).each do |i| ary = Parser.parse("a" * i) assert_equal((1..i).map {"a"}, ary) end end def test_02_single_occurence ary = Parser.parse("a") assert_equal(["a"], ary) end def test_03_no_occurence assert_raises(RuntimeError) {Parser.parse("b")} end PlusAndAstTestGrammar = Rockit::DParser::Grammar.new do start :S, [plus(:Digit)], ast(:S, 0) term :Digit, [/[0-9]/] end AstParser = PlusAndAstTestGrammar.new_parser def test_04_multiple_occurences_and_ast ast = AstParser.parse("7 5 6 9") assert_equal("S", ast.name) assert_kind_of(AstParser.astclass_of_name(:S), ast) assert_equal(1, ast.num_children) assert_equal(["7", "5", "6", "9"], ast[0]) end def test_05_single_occurence_and_ast ast = AstParser.parse("7") assert_equal("S", ast.name) assert_kind_of(AstParser.astclass_of_name(:S), ast) assert_equal(1, ast.num_children) assert_equal(["7"], ast[0]) end def test_06_no_occurence_and_ast assert_raises(RuntimeError) {AstParser.parse("b")} end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rockit-0.7.1 | tests/acceptance/rockit/dparser/atest_plus_operator.rb |