Sha256: 9d7112578ef2b943861c524ce531b26b3164e1aab5f9fb14bb70575984c4215e

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'test/unit'
require 'rockit/dparser'

class ATestMultOperator < Test::Unit::TestCase
  MultTestGrammar = Rockit::DParser::Grammar.new do
    start :S, [mult(:Digit)], value(0)
    term :Digit, [/[0-9]/]
  end

  Parser = MultTestGrammar.new_parser

  def test_01_multiple_occurences
    (2..20).each do |i|
      digit = rand(10).to_s
      ary = Parser.parse(digit * i)
      assert_equal((1..i).map {digit}, ary)
    end
  end

  def test_02_single_occurence
    ary = Parser.parse("7")
    assert_equal(["7"], ary)
  end

  def test_03_no_occurence
    ary = Parser.parse("")
    assert_equal([], ary)
  end

  MultAndAstTestGrammar = Rockit::DParser::Grammar.new do
    start :S, [mult(:Digit)], ast(:S, 0)
    term :Digit, [/[0-9]/]
  end

  AstParser = MultAndAstTestGrammar.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
    ast = AstParser.parse("")
    assert_equal("S", ast.name)
    assert_kind_of(AstParser.astclass_of_name(:S), ast)
    assert_equal(1, ast.num_children)
    assert_equal([], ast[0])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rockit-0.7.1 tests/acceptance/rockit/dparser/atest_mult_operator.rb