Sha256: 2f2e5b0bbd756bd072bd3aedd853c01732c4d670a49c7c053e3285904fe5878a

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

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

class ATestListOperator < Test::Unit::TestCase
  ListTestGrammar = Rockit::DParser::Grammar.new do
    start :S, [list(:Number, ",")], value(0)
    term :Number, [/[0-9]+/]
  end

  Parser = ListTestGrammar.new_parser
  
  def test_01_two_value_list
    ary = Parser.parse("1, 2")
    assert_equal(["1", "2"], ary)
  end

  def test_02_multi_value_list
    ary = Parser.parse("1, 2, 34, 567,890")
    assert_equal(["1", "2", "34", "567", "890"], ary)
  end

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

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

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

  def atest_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_list_operator.rb