Sha256: a14fba849c2e5cb9ab65ed81259ee978ae415df69181fd1eaa7336d828895f12

Contents?: true

Size: 1.27 KB

Versions: 11

Compression:

Stored size: 1.27 KB

Contents

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

class ScannerQuantifiers < Test::Unit::TestCase

  tests = {
   'a?'     => [:quantifier,  :zero_or_one,             '?'],
   'a??'    => [:quantifier,  :zero_or_one_reluctant,   '??'],
   'a?+'    => [:quantifier,  :zero_or_one_possessive,  '?+'],

   'a*'     => [:quantifier,  :zero_or_more,            '*'],
   'a*?'    => [:quantifier,  :zero_or_more_reluctant,  '*?'],
   'a*+'    => [:quantifier,  :zero_or_more_possessive, '*+'],

   'a+'     => [:quantifier,  :one_or_more,             '+'],
   'a+?'    => [:quantifier,  :one_or_more_reluctant,   '+?'],
   'a++'    => [:quantifier,  :one_or_more_possessive,  '++'],

   'a{2}'   => [:quantifier,  :interval,                '{2}'],
   'a{2,}'  => [:quantifier,  :interval,                '{2,}'],
   'a{,2}'  => [:quantifier,  :interval,                '{,2}'],
   'a{2,4}' => [:quantifier,  :interval,                '{2,4}'],
  }

  counter = 0
  tests.each do |pattern, test|
    name = (test[1] == :interval ? "interval_#{counter += 1}" : test[1])

    [:type, :token, :text].each_with_index do |member, i|
      define_method "test_scan_#{test[0]}_#{name}_#{member}" do

        token = RS.scan(pattern).last
        assert_equal( test[i], token[i] )

      end
    end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
regexp_parser-0.3.4 test/scanner/test_quantifiers.rb
regexp_parser-0.3.3 test/scanner/test_quantifiers.rb
regexp_parser-0.3.2 test/scanner/test_quantifiers.rb
regexp_parser-0.3.1 test/scanner/test_quantifiers.rb
regexp_parser-0.3.0 test/scanner/test_quantifiers.rb
regexp_parser-0.2.1 test/scanner/test_quantifiers.rb
regexp_parser-0.2.0 test/scanner/test_quantifiers.rb
regexp_parser-0.1.6 test/scanner/test_quantifiers.rb
regexp_parser-0.1.5 test/scanner/test_quantifiers.rb
regexp_parser-0.1.1 test/scanner/test_quantifiers.rb
regexp_parser-0.1.0 test/scanner/test_quantifiers.rb