Sha256: 15703e716ce3e0163ad32b124918a0847f51e9ea33d35ddb8592dcb7c7f266e4

Contents?: true

Size: 1.6 KB

Versions: 17

Compression:

Stored size: 1.6 KB

Contents

require File.expand_path("../../helpers", __FILE__)

%w{
  alternation anchors errors escapes free_space groups
  properties quantifiers refcalls sets types
}.each do|tc|
  require File.expand_path("../test_#{tc}", __FILE__)
end

if RUBY_VERSION >= '2.0.0'
  %w{conditionals keep}.each do|tc|
    require File.expand_path("../test_#{tc}", __FILE__)
  end
end

class TestParser < Test::Unit::TestCase

  def test_parse_returns_a_root_expression
    assert_instance_of Regexp::Expression::Root, RP.parse('abc')
  end


  def test_parse_root_contains_expressions
    root = RP.parse(/^a.c+[^one]{2,3}\b\d\\\C-C$/)

    all_base = root.expressions.all? do |exp|
      exp.kind_of?(Regexp::Expression::Base)
    end

    assert all_base, "Not all nodes are instances of Regexp::Expression"
  end


  def test_parse_node_types
    root = RP.parse('^(one){2,3}([^d\]efm-qz\,\-]*)(ghi)+$')

    assert root.expressions[1].expressions[0].is_a?(Literal),
          "Not a literal node, but should be"

    assert root.expressions[1].quantified?, "Not quanfified, but should be"

    assert root.expressions[2].expressions[0].is_a?(CharacterSet),
          "Not a caracter set, but it should be"

    assert_equal false, root.expressions[2].quantified?

    assert root.expressions[3].is_a?(Group::Capture),
          "Not a group, but should be"

    assert_equal true, root.expressions[3].quantified?
  end

  def test_parse_no_quantifier_target_raises_error
    assert_raise( ArgumentError ) { RP.parse('?abc') }
  end

  def test_parse_sequence_no_quantifier_target_raises_error
    assert_raise( ArgumentError ) { RP.parse('abc|?def') }
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
regexp_parser-0.5.0 test/parser/test_all.rb
regexp_parser-0.4.13 test/parser/test_all.rb
regexp_parser-0.4.12 test/parser/test_all.rb
regexp_parser-0.4.11 test/parser/test_all.rb
regexp_parser-0.4.10 test/parser/test_all.rb
regexp_parser-0.4.9 test/parser/test_all.rb
regexp_parser-0.4.8 test/parser/test_all.rb
regexp_parser-0.4.7 test/parser/test_all.rb
regexp_parser-0.4.6 test/parser/test_all.rb
regexp_parser-0.4.5 test/parser/test_all.rb
regexp_parser-0.4.4 test/parser/test_all.rb
regexp_parser-0.4.3 test/parser/test_all.rb
regexp_parser-0.4.2 test/parser/test_all.rb
regexp_parser-0.4.1 test/parser/test_all.rb
regexp_parser-0.4.0 test/parser/test_all.rb
regexp_parser-0.3.6 test/parser/test_all.rb
regexp_parser-0.3.5 test/parser/test_all.rb