Sha256: a03a9f49dae68f779df26a7ce60127bfbd312af42ea78f0977c1425d643b8cee

Contents?: true

Size: 1.14 KB

Versions: 9

Compression:

Stored size: 1.14 KB

Contents

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

class TestParserAnchors < Test::Unit::TestCase

  tests = {
    '^a'      => [0, :anchor,   :bol,                 Anchor::BOL],
    'a$'      => [1, :anchor,   :eol,                 Anchor::EOL],

    '\Aa'     => [0, :anchor,   :bos,                 Anchor::BOS],
    'a\z'     => [1, :anchor,   :eos,                 Anchor::EOS],
    'a\Z'     => [1, :anchor,   :eos_ob_eol,          Anchor::EOSobEOL],

    'a\b'     => [1, :anchor,   :word_boundary,       Anchor::WordBoundary],
    'a\B'     => [1, :anchor,   :nonword_boundary,    Anchor::NonWordBoundary],

    'a\G'     => [1, :anchor,   :match_start,         Anchor::MatchStart],

    "\\\\Aa"  => [0, :escape,   :backslash,           EscapeSequence::Literal],
  }

  count = 0
  tests.each do |pattern, test|
    define_method "test_parse_anchor_#{test[2]}_#{count+=1}" do
      root = RP.parse(pattern, 'ruby/1.9')
      exp  = root.expressions[test[0]]

      assert( exp.is_a?( test[3] ),
             "Expected #{test[3]}, but got #{exp.class.name}")

      assert_equal( test[1], exp.type )
      assert_equal( test[2], exp.token )
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
regexp_parser-0.3.4 test/parser/test_anchors.rb
regexp_parser-0.3.3 test/parser/test_anchors.rb
regexp_parser-0.3.2 test/parser/test_anchors.rb
regexp_parser-0.3.1 test/parser/test_anchors.rb
regexp_parser-0.3.0 test/parser/test_anchors.rb
regexp_parser-0.2.1 test/parser/test_anchors.rb
regexp_parser-0.2.0 test/parser/test_anchors.rb
regexp_parser-0.1.6 test/parser/test_anchors.rb
regexp_parser-0.1.5 test/parser/test_anchors.rb