Sha256: a9a6987a10a21d5704c87c0df94bac9cf56869365b88327d63a0df734a8db9d0

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

require File.expand_path('../helper', __FILE__)

class ParseErrorTest < Test::Unit::TestCase
  Sentence = Grammar.new do
    include Words

    rule :sentence do
      all(:capital_word, one_or_more([ :space, :word ]), :period)
    end

    rule :capital_word do
      all(/[A-Z]/, zero_or_more(:alpha))
    end

    rule :space do
      one_or_more(any(" ", "\n", "\r\n"))
    end

    rule :period, '.'
  end

  def test_basic
    begin
      TestGrammar.parse('#')
    rescue ParseError => e
      assert_equal(0, e.offset)
      assert_equal('#', e.line)
      assert_equal(1, e.line_number)
      assert_equal(0, e.line_offset)
    end
  end

  def test_single_line
    begin
      Sentence.parse('Once upon 4 time.')
    rescue ParseError => e
      assert_equal(10, e.offset)
      assert_equal('Once upon 4 time.', e.line)
      assert_equal(1, e.line_number)
      assert_equal(10, e.line_offset)
    end
  end

  def test_multi_line
    begin
      Sentence.parse("Once\nupon a\r\ntim3.")
    rescue ParseError => e
      assert_equal(16, e.offset)
      assert_equal('tim3.', e.line)
      assert_equal(3, e.line_number)
      assert_equal(3, e.line_offset)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
citrus-2.3.2 test/parse_error_test.rb
citrus-2.3.1 test/parse_error_test.rb
citrus-2.3.0 test/parse_error_test.rb
citrus-2.2.2 test/parse_error_test.rb
citrus-2.2.1 test/parse_error_test.rb
citrus-2.2.0 test/parse_error_test.rb