Sha256: 27855a5aed085e05be53c14cb2a142bcd45a3235bca0a429f6014a5a23e53377

Contents?: true

Size: 1.28 KB

Versions: 25

Compression:

Stored size: 1.28 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}'],
  }

  tests.each_with_index do |(pattern, (type, token, text)), count|
    name = (token == :interval ? "interval_#{count}" : token)

    define_method "test_scan_#{type}_#{name}" do
      tokens = RS.scan(pattern)
      result = tokens.last

      assert_equal type,  result[0]
      assert_equal token, result[1]
      assert_equal text,  result[2]
    end
  end

end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
tdiary-5.0.13 vendor/bundle/gems/regexp_parser-1.3.0/test/scanner/test_quantifiers.rb
regexp_parser-1.4.0 test/scanner/test_quantifiers.rb
tdiary-5.0.12.1 vendor/bundle/gems/regexp_parser-1.3.0/test/scanner/test_quantifiers.rb
tdiary-5.0.11 vendor/bundle/gems/regexp_parser-1.3.0/test/scanner/test_quantifiers.rb
regexp_parser-1.3.0 test/scanner/test_quantifiers.rb
regexp_parser-1.2.0 test/scanner/test_quantifiers.rb
regexp_parser-1.1.0 test/scanner/test_quantifiers.rb
regexp_parser-1.0.0 test/scanner/test_quantifiers.rb
regexp_parser-0.5.0 test/scanner/test_quantifiers.rb
regexp_parser-0.4.13 test/scanner/test_quantifiers.rb
regexp_parser-0.4.12 test/scanner/test_quantifiers.rb
regexp_parser-0.4.11 test/scanner/test_quantifiers.rb
regexp_parser-0.4.10 test/scanner/test_quantifiers.rb
regexp_parser-0.4.9 test/scanner/test_quantifiers.rb
regexp_parser-0.4.8 test/scanner/test_quantifiers.rb
regexp_parser-0.4.7 test/scanner/test_quantifiers.rb
regexp_parser-0.4.6 test/scanner/test_quantifiers.rb
regexp_parser-0.4.5 test/scanner/test_quantifiers.rb
regexp_parser-0.4.4 test/scanner/test_quantifiers.rb
regexp_parser-0.4.3 test/scanner/test_quantifiers.rb