Sha256: 69507b2afc691bfe2780b0526db99b3af4bc04744d843bebda0b15bc1a987cfb

Contents?: true

Size: 1.18 KB

Versions: 83

Compression:

Stored size: 1.18 KB

Contents

# encoding: UTF-8

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 ä time.')
    rescue ParseError => e
      assert_equal(10, e.offset)
      assert_equal('Once upon ä 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

83 entries across 83 versions & 2 rubygems

Version Path
harbr-0.1.70 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.69 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.68 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.64 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.63 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.62 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/parse_error_test.rb