Sha256: 1241f7e01d83476d430a56601b10ac947a9f90ba88fcaa435a46036eff3c636c

Contents?: true

Size: 1.57 KB

Versions: 17

Compression:

Stored size: 1.57 KB

Contents

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

class TestParserTypes < Test::Unit::TestCase

  tests = {
    /a\dc/    => [1, :type,   :digit,     CharacterType::Digit],
    /a\Dc/    => [1, :type,   :nondigit,  CharacterType::NonDigit],

    /a\sc/    => [1, :type,   :space,     CharacterType::Space],
    /a\Sc/    => [1, :type,   :nonspace,  CharacterType::NonSpace],

    /a\hc/    => [1, :type,   :hex,       CharacterType::Hex],
    /a\Hc/    => [1, :type,   :nonhex,    CharacterType::NonHex],

    /a\wc/    => [1, :type,   :word,      CharacterType::Word],
    /a\Wc/    => [1, :type,   :nonword,   CharacterType::NonWord],
  }

  tests.each_with_index do |(pattern, (index, type, token, klass)), count|
    define_method "test_parse_type_#{token}_#{count}" do
      root = RP.parse(pattern, 'ruby/1.9')
      exp  = root.expressions.at(index)

      assert exp.is_a?( klass ),
             "Expected #{klass}, but got #{exp.class.name}"

      assert_equal type,  exp.type
      assert_equal token, exp.token
    end
  end

  tests_2_0 = {
    'a\Rc'    => [1, :type,   :linebreak, CharacterType::Linebreak],
    'a\Xc'    => [1, :type,   :xgrapheme, CharacterType::ExtendedGrapheme],
  }

  tests_2_0.each_with_index do |(pattern, (index, type, token, klass)), count|
    define_method "test_parse_type_#{token}_#{count}" do
      root = RP.parse(pattern, 'ruby/2.0')
      exp  = root.expressions.at(index)

      assert exp.is_a?( klass ),
             "Expected #{klass}, but got #{exp.class.name}"

      assert_equal type,  exp.type
      assert_equal token, exp.token
    end
  end

end

Version data entries

17 entries across 17 versions & 2 rubygems

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