regexp_parser 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -1
  3. data/Gemfile +1 -1
  4. data/README.md +9 -13
  5. data/lib/regexp_parser/expression.rb +33 -21
  6. data/lib/regexp_parser/expression/classes/backref.rb +18 -10
  7. data/lib/regexp_parser/expression/classes/conditional.rb +4 -0
  8. data/lib/regexp_parser/expression/classes/group.rb +4 -2
  9. data/lib/regexp_parser/expression/classes/keep.rb +1 -3
  10. data/lib/regexp_parser/expression/methods/match_length.rb +172 -0
  11. data/lib/regexp_parser/expression/quantifier.rb +2 -2
  12. data/lib/regexp_parser/expression/sequence.rb +0 -4
  13. data/lib/regexp_parser/expression/subexpression.rb +3 -5
  14. data/lib/regexp_parser/lexer.rb +31 -24
  15. data/lib/regexp_parser/parser.rb +25 -3
  16. data/lib/regexp_parser/syntax/tokens.rb +2 -10
  17. data/lib/regexp_parser/version.rb +1 -1
  18. data/regexp_parser.gemspec +2 -2
  19. data/spec/expression/base_spec.rb +80 -0
  20. data/spec/expression/clone_spec.rb +120 -0
  21. data/spec/expression/conditional_spec.rb +89 -0
  22. data/spec/expression/free_space_spec.rb +27 -0
  23. data/spec/expression/methods/match_length_spec.rb +141 -0
  24. data/spec/expression/methods/strfregexp_spec.rb +224 -0
  25. data/spec/expression/methods/tests_spec.rb +97 -0
  26. data/spec/expression/methods/traverse_spec.rb +140 -0
  27. data/spec/expression/subexpression_spec.rb +50 -0
  28. data/spec/expression/to_h_spec.rb +26 -0
  29. data/spec/expression/to_s_spec.rb +100 -0
  30. data/spec/lexer/all_spec.rb +22 -0
  31. data/{test/lexer/test_conditionals.rb → spec/lexer/conditionals_spec.rb} +31 -35
  32. data/spec/lexer/escapes_spec.rb +38 -0
  33. data/spec/lexer/keep_spec.rb +22 -0
  34. data/{test/lexer/test_literals.rb → spec/lexer/literals_spec.rb} +20 -24
  35. data/{test/lexer/test_nesting.rb → spec/lexer/nesting_spec.rb} +11 -13
  36. data/spec/lexer/refcalls_spec.rb +54 -0
  37. data/spec/parser/all_spec.rb +31 -0
  38. data/spec/parser/alternation_spec.rb +88 -0
  39. data/{test/parser/test_anchors.rb → spec/parser/anchors_spec.rb} +7 -10
  40. data/spec/parser/conditionals_spec.rb +179 -0
  41. data/spec/parser/errors_spec.rb +51 -0
  42. data/spec/parser/escapes_spec.rb +132 -0
  43. data/spec/parser/free_space_spec.rb +130 -0
  44. data/spec/parser/groups_spec.rb +267 -0
  45. data/spec/parser/keep_spec.rb +19 -0
  46. data/spec/parser/posix_classes_spec.rb +27 -0
  47. data/spec/parser/properties_spec.rb +127 -0
  48. data/spec/parser/quantifiers_spec.rb +293 -0
  49. data/spec/parser/refcalls_spec.rb +237 -0
  50. data/spec/parser/set/intersections_spec.rb +127 -0
  51. data/spec/parser/set/ranges_spec.rb +111 -0
  52. data/spec/parser/sets_spec.rb +178 -0
  53. data/{test/parser/test_types.rb → spec/parser/types_spec.rb} +13 -20
  54. data/spec/scanner/all_spec.rb +18 -0
  55. data/{test/scanner/test_anchors.rb → spec/scanner/anchors_spec.rb} +8 -10
  56. data/{test/scanner/test_conditionals.rb → spec/scanner/conditionals_spec.rb} +49 -53
  57. data/spec/scanner/errors_spec.rb +90 -0
  58. data/{test/scanner/test_escapes.rb → spec/scanner/escapes_spec.rb} +8 -10
  59. data/{test/scanner/test_free_space.rb → spec/scanner/free_space_spec.rb} +48 -52
  60. data/{test/scanner/test_groups.rb → spec/scanner/groups_spec.rb} +33 -41
  61. data/spec/scanner/keep_spec.rb +33 -0
  62. data/{test/scanner/test_literals.rb → spec/scanner/literals_spec.rb} +8 -12
  63. data/{test/scanner/test_meta.rb → spec/scanner/meta_spec.rb} +8 -10
  64. data/{test/scanner/test_properties.rb → spec/scanner/properties_spec.rb} +14 -19
  65. data/{test/scanner/test_quantifiers.rb → spec/scanner/quantifiers_spec.rb} +7 -9
  66. data/{test/scanner/test_refcalls.rb → spec/scanner/refcalls_spec.rb} +9 -9
  67. data/{test/scanner/test_scripts.rb → spec/scanner/scripts_spec.rb} +8 -12
  68. data/{test/scanner/test_sets.rb → spec/scanner/sets_spec.rb} +14 -17
  69. data/spec/scanner/types_spec.rb +29 -0
  70. data/spec/scanner/unicode_blocks_spec.rb +28 -0
  71. data/spec/spec_helper.rb +14 -0
  72. data/{test → spec}/support/runner.rb +9 -8
  73. data/{test → spec}/support/warning_extractor.rb +5 -7
  74. data/spec/syntax/syntax_spec.rb +44 -0
  75. data/spec/syntax/syntax_token_map_spec.rb +23 -0
  76. data/spec/syntax/versions/1.8.6_spec.rb +38 -0
  77. data/spec/syntax/versions/1.9.1_spec.rb +23 -0
  78. data/spec/syntax/versions/1.9.3_spec.rb +22 -0
  79. data/spec/syntax/versions/2.0.0_spec.rb +28 -0
  80. data/spec/syntax/versions/2.2.0_spec.rb +22 -0
  81. data/spec/syntax/versions/aliases_spec.rb +119 -0
  82. data/spec/token/token_spec.rb +85 -0
  83. metadata +131 -140
  84. data/test/expression/test_all.rb +0 -12
  85. data/test/expression/test_base.rb +0 -90
  86. data/test/expression/test_clone.rb +0 -89
  87. data/test/expression/test_conditionals.rb +0 -113
  88. data/test/expression/test_free_space.rb +0 -35
  89. data/test/expression/test_set.rb +0 -84
  90. data/test/expression/test_strfregexp.rb +0 -230
  91. data/test/expression/test_subexpression.rb +0 -58
  92. data/test/expression/test_tests.rb +0 -99
  93. data/test/expression/test_to_h.rb +0 -59
  94. data/test/expression/test_to_s.rb +0 -104
  95. data/test/expression/test_traverse.rb +0 -161
  96. data/test/helpers.rb +0 -10
  97. data/test/lexer/test_all.rb +0 -41
  98. data/test/lexer/test_keep.rb +0 -24
  99. data/test/lexer/test_refcalls.rb +0 -56
  100. data/test/parser/set/test_intersections.rb +0 -127
  101. data/test/parser/set/test_ranges.rb +0 -111
  102. data/test/parser/test_all.rb +0 -64
  103. data/test/parser/test_alternation.rb +0 -92
  104. data/test/parser/test_conditionals.rb +0 -187
  105. data/test/parser/test_errors.rb +0 -63
  106. data/test/parser/test_escapes.rb +0 -134
  107. data/test/parser/test_free_space.rb +0 -139
  108. data/test/parser/test_groups.rb +0 -289
  109. data/test/parser/test_keep.rb +0 -21
  110. data/test/parser/test_posix_classes.rb +0 -27
  111. data/test/parser/test_properties.rb +0 -134
  112. data/test/parser/test_quantifiers.rb +0 -301
  113. data/test/parser/test_refcalls.rb +0 -186
  114. data/test/parser/test_sets.rb +0 -179
  115. data/test/scanner/test_all.rb +0 -38
  116. data/test/scanner/test_errors.rb +0 -91
  117. data/test/scanner/test_keep.rb +0 -35
  118. data/test/scanner/test_types.rb +0 -35
  119. data/test/scanner/test_unicode_blocks.rb +0 -30
  120. data/test/support/disable_autotest.rb +0 -8
  121. data/test/syntax/test_all.rb +0 -6
  122. data/test/syntax/test_syntax.rb +0 -61
  123. data/test/syntax/test_syntax_token_map.rb +0 -25
  124. data/test/syntax/versions/test_1.8.rb +0 -55
  125. data/test/syntax/versions/test_1.9.1.rb +0 -36
  126. data/test/syntax/versions/test_1.9.3.rb +0 -32
  127. data/test/syntax/versions/test_2.0.0.rb +0 -37
  128. data/test/syntax/versions/test_2.2.0.rb +0 -32
  129. data/test/syntax/versions/test_aliases.rb +0 -129
  130. data/test/syntax/versions/test_all.rb +0 -5
  131. data/test/test_all.rb +0 -5
  132. data/test/token/test_all.rb +0 -2
  133. data/test/token/test_token.rb +0 -107
@@ -1,7 +1,6 @@
1
- require File.expand_path("../../helpers", __FILE__)
2
-
3
- class ScannerQuantifiers < Test::Unit::TestCase
1
+ require 'spec_helper'
4
2
 
3
+ RSpec.describe('Quantifier scanning') do
5
4
  tests = {
6
5
  'a?' => [:quantifier, :zero_or_one, '?'],
7
6
  'a??' => [:quantifier, :zero_or_one_reluctant, '??'],
@@ -22,16 +21,15 @@ class ScannerQuantifiers < Test::Unit::TestCase
22
21
  }
23
22
 
24
23
  tests.each_with_index do |(pattern, (type, token, text)), count|
25
- name = (token == :interval ? "interval_#{count}" : token)
24
+ name = token == :interval ? "interval_#{count}" : token
26
25
 
27
- define_method "test_scan_#{type}_#{name}" do
26
+ specify("scan_#{type}_#{name}") do
28
27
  tokens = RS.scan(pattern)
29
28
  result = tokens.last
30
29
 
31
- assert_equal type, result[0]
32
- assert_equal token, result[1]
33
- assert_equal text, result[2]
30
+ expect(result[0]).to eq type
31
+ expect(result[1]).to eq token
32
+ expect(result[2]).to eq text
34
33
  end
35
34
  end
36
-
37
35
  end
@@ -1,6 +1,6 @@
1
- require File.expand_path("../../helpers", __FILE__)
1
+ require 'spec_helper'
2
2
 
3
- class ScannerRefCalls < Test::Unit::TestCase
3
+ RSpec.describe('RefCall scanning') do
4
4
  tests = {
5
5
  # Traditional numerical group back-reference
6
6
  '(abc)\1' => [3, :backref, :number, '\1', 5, 7],
@@ -37,16 +37,16 @@ class ScannerRefCalls < Test::Unit::TestCase
37
37
  }
38
38
 
39
39
  tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
40
- define_method "test_scanner_#{type}_#{token}_#{count}" do
40
+ specify("scanner_#{type}_#{token}_#{count}") do
41
41
  tokens = RS.scan(pattern)
42
42
  result = tokens[index]
43
43
 
44
- assert_equal type, result[0]
45
- assert_equal token, result[1]
46
- assert_equal text, result[2]
47
- assert_equal ts, result[3]
48
- assert_equal te, result[4]
49
- assert_equal text, pattern[ts, te]
44
+ expect(result[0]).to eq type
45
+ expect(result[1]).to eq token
46
+ expect(result[2]).to eq text
47
+ expect(result[3]).to eq ts
48
+ expect(result[4]).to eq te
49
+ expect(pattern[ts, te]).to eq text
50
50
  end
51
51
  end
52
52
  end
@@ -1,7 +1,6 @@
1
- require File.expand_path("../../helpers", __FILE__)
2
-
3
- class ScannerUnicodeScripts < Test::Unit::TestCase
1
+ require 'spec_helper'
4
2
 
3
+ RSpec.describe('UnicodeScript scanning') do
5
4
  tests = {
6
5
  'Aghb' => :caucasian_albanian,
7
6
  'Caucasian Albanian' => :caucasian_albanian,
@@ -33,21 +32,18 @@ class ScannerUnicodeScripts < Test::Unit::TestCase
33
32
  }
34
33
 
35
34
  tests.each_with_index do |(property, token), count|
36
- define_method "test_scanner_property_#{token}_#{count}" do
35
+ specify("scanner_property_#{token}_#{count}") do
37
36
  tokens = RS.scan("a\\p{#{property}}c")
38
37
  result = tokens.at(1)
39
-
40
- assert_equal :property, result[0]
41
- assert_equal token, result[1]
38
+ expect(result[0]).to eq :property
39
+ expect(result[1]).to eq token
42
40
  end
43
41
 
44
- define_method "test_scanner_nonproperty_#{token}_#{count}" do
42
+ specify("scanner_nonproperty_#{token}_#{count}") do
45
43
  tokens = RS.scan("a\\P{#{property}}c")
46
44
  result = tokens.at(1)
47
-
48
- assert_equal :nonproperty, result[0]
49
- assert_equal token, result[1]
45
+ expect(result[0]).to eq :nonproperty
46
+ expect(result[1]).to eq token
50
47
  end
51
48
  end
52
-
53
49
  end
@@ -1,9 +1,6 @@
1
- # encoding: utf-8
2
-
3
- require File.expand_path("../../helpers", __FILE__)
4
-
5
- class ScannerSets < Test::Unit::TestCase
1
+ require 'spec_helper'
6
2
 
3
+ RSpec.describe('Set scanning') do
7
4
  tests = {
8
5
  '[a]' => [0, :set, :open, '[', 0, 1],
9
6
  '[b]' => [2, :set, :close, ']', 2, 3],
@@ -95,25 +92,25 @@ class ScannerSets < Test::Unit::TestCase
95
92
  }
96
93
 
97
94
  tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
98
- define_method "test_scanner_#{type}_#{token}_in_'#{pattern}'_#{count}" do
95
+ specify("scanner_#{type}_#{token}_in_'#{pattern}'_#{count}") do
99
96
  tokens = RS.scan(pattern)
100
97
  result = tokens.at(index)
101
98
 
102
- assert_equal type, result[0]
103
- assert_equal token, result[1]
104
- assert_equal text, result[2]
105
- assert_equal ts, result[3]
106
- assert_equal te, result[4]
99
+ expect(result[0]).to eq type
100
+ expect(result[1]).to eq token
101
+ expect(result[2]).to eq text
102
+ expect(result[3]).to eq ts
103
+ expect(result[4]).to eq te
107
104
  end
108
105
  end
109
106
 
110
- def test_set_literal_encoding
107
+ specify('set literal encoding') do
111
108
  text = RS.scan('[a]')[1][2].to_s
112
- assert_equal 'a', text
113
- assert_equal 'UTF-8', text.encoding.to_s
109
+ expect(text).to eq 'a'
110
+ expect(text.encoding.to_s).to eq 'UTF-8'
114
111
 
115
- text = RS.scan('[😲]')[1][2].to_s
116
- assert_equal '😲', text
117
- assert_equal 'UTF-8', text.encoding.to_s
112
+ text = RS.scan("[\u{1F632}]")[1][2].to_s
113
+ expect(text).to eq "\u{1F632}"
114
+ expect(text.encoding.to_s).to eq 'UTF-8'
118
115
  end
119
116
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe('Type scanning') do
4
+ tests = {
5
+ 'a\\dc' => [1, :type, :digit, '\\d', 1, 3],
6
+ 'a\\Dc' => [1, :type, :nondigit, '\\D', 1, 3],
7
+ 'a\\hc' => [1, :type, :hex, '\\h', 1, 3],
8
+ 'a\\Hc' => [1, :type, :nonhex, '\\H', 1, 3],
9
+ 'a\\sc' => [1, :type, :space, '\\s', 1, 3],
10
+ 'a\\Sc' => [1, :type, :nonspace, '\\S', 1, 3],
11
+ 'a\\wc' => [1, :type, :word, '\\w', 1, 3],
12
+ 'a\\Wc' => [1, :type, :nonword, '\\W', 1, 3],
13
+ 'a\\Rc' => [1, :type, :linebreak, '\\R', 1, 3],
14
+ 'a\\Xc' => [1, :type, :xgrapheme, '\\X', 1, 3],
15
+ }
16
+
17
+ tests.each do |(pattern, (index, type, token, text, ts, te))|
18
+ specify("scanner_#{type}_#{token}") do
19
+ tokens = RS.scan(pattern)
20
+ result = tokens.at(index)
21
+
22
+ expect(result[0]).to eq type
23
+ expect(result[1]).to eq token
24
+ expect(result[2]).to eq text
25
+ expect(result[3]).to eq ts
26
+ expect(result[4]).to eq te
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe('UnicodeBlock scanning') do
4
+ tests = {
5
+ 'InArabic' => :in_arabic,
6
+ 'InCJK_Unified_Ideographs_Extension_A' => :in_cjk_unified_ideographs_extension_a,
7
+ 'In Letterlike Symbols' => :in_letterlike_symbols,
8
+ 'InMiscellaneous_Mathematical_Symbols-A' => :in_miscellaneous_mathematical_symbols_a
9
+ }
10
+
11
+ tests.each_with_index do |(property, token), count|
12
+ specify("scanner_property_#{token}_#{count}") do
13
+ tokens = RS.scan("a\\p{#{property}}c")
14
+ result = tokens.at(1)
15
+
16
+ expect(result[0]).to eq :property
17
+ expect(result[1]).to eq token
18
+ end
19
+
20
+ specify("scanner_nonproperty_#{token}_#{count}") do
21
+ tokens = RS.scan("a\\P{#{property}}c")
22
+ result = tokens.at(1)
23
+
24
+ expect(result[0]).to eq :nonproperty
25
+ expect(result[1]).to eq token
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ require 'regexp_parser'
2
+ require 'regexp_property_values'
3
+
4
+ RS = Regexp::Scanner
5
+ RL = Regexp::Lexer
6
+ RP = Regexp::Parser
7
+ RE = Regexp::Expression
8
+ T = Regexp::Syntax::Token
9
+
10
+ include Regexp::Expression
11
+
12
+ def ruby_version_at_least(version)
13
+ Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new(version)
14
+ end
@@ -1,6 +1,7 @@
1
1
  require 'pathname'
2
+ require 'rspec'
2
3
 
3
- module RegexpParserTest
4
+ module RegexpParserSpec
4
5
  class Runner
5
6
  def initialize(arguments, warning_whitelist)
6
7
  @arguments = arguments
@@ -8,14 +9,14 @@ module RegexpParserTest
8
9
  end
9
10
 
10
11
  def run
11
- test_status = nil
12
+ spec_status = nil
12
13
 
13
14
  Warning::Filter.new(warning_whitelist).assert_expected_warnings_only do
14
15
  setup
15
- test_status = run_test_unit
16
+ spec_status = run_rspec
16
17
  end
17
18
 
18
- test_status
19
+ spec_status
19
20
  end
20
21
 
21
22
  private
@@ -23,14 +24,14 @@ module RegexpParserTest
23
24
  def setup
24
25
  $VERBOSE = true
25
26
 
26
- test_files.each(&method(:require))
27
+ spec_files.each(&method(:require))
27
28
  end
28
29
 
29
- def run_test_unit
30
- Test::Unit::AutoRunner.run
30
+ def run_rspec
31
+ RSpec::Core::Runner.run([])
31
32
  end
32
33
 
33
- def test_files
34
+ def spec_files
34
35
  arguments
35
36
  .map { |path| Pathname.new(path).expand_path.freeze }
36
37
  .select(&:file?)
@@ -1,7 +1,7 @@
1
1
  require 'set'
2
2
  require 'delegate'
3
3
 
4
- module RegexpParserTest
4
+ module RegexpParserSpec
5
5
  class Warning
6
6
  class UnexpectedWarnings < StandardError
7
7
  MSG = 'Unexpected warnings: %s'.freeze
@@ -22,22 +22,20 @@ module RegexpParserTest
22
22
 
23
23
  yield
24
24
 
25
- if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.0.0')
26
- assert_no_warnings($stderr.warnings)
27
- end
25
+ assert_no_warnings($stderr.warnings)
28
26
  ensure
29
27
  $stderr = original
30
28
  end
31
29
 
32
- private
30
+ private
33
31
 
34
32
  def assert_no_warnings(warnings)
35
- fail UnexpectedWarnings, warnings.to_a if warnings.any?
33
+ raise UnexpectedWarnings, warnings.to_a if warnings.any?
36
34
  end
37
35
  end
38
36
 
39
37
  class Extractor < DelegateClass(IO)
40
- PATTERN = /\A(?:.+):(?:\d+): warning: (?:.+)\n\z/.freeze
38
+ PATTERN = /\A(?:.+):(?:\d+): warning: (?:.+)\n\z/
41
39
 
42
40
  def initialize(io, whitelist)
43
41
  @whitelist = whitelist
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe(Regexp::Syntax) do
4
+ specify('unknown name') do
5
+ expect { Regexp::Syntax.new('ruby/1.0') }.to raise_error(Regexp::Syntax::UnknownSyntaxNameError)
6
+ end
7
+
8
+ specify('new') do
9
+ expect(Regexp::Syntax.new('ruby/1.9.3')).to be_instance_of(Regexp::Syntax::V1_9_3)
10
+ end
11
+
12
+ specify('new any') do
13
+ expect(Regexp::Syntax.new('any')).to be_instance_of(Regexp::Syntax::Any)
14
+ expect(Regexp::Syntax.new('*')).to be_instance_of(Regexp::Syntax::Any)
15
+ end
16
+
17
+ specify('not implemented') do
18
+ expect { RP.parse('\\p{alpha}', 'ruby/1.8') }.to raise_error(Regexp::Syntax::NotImplementedError)
19
+ end
20
+
21
+ specify('supported?') do
22
+ expect(Regexp::Syntax.supported?('ruby/1.1.1')).to be false
23
+ expect(Regexp::Syntax.supported?('ruby/2.4.3')).to be true
24
+ expect(Regexp::Syntax.supported?('ruby/2.5')).to be true
25
+ end
26
+
27
+ specify('invalid version') do
28
+ expect { Regexp::Syntax.version_class('2.0.0') }.to raise_error(Regexp::Syntax::InvalidVersionNameError)
29
+
30
+ expect { Regexp::Syntax.version_class('ruby/20') }.to raise_error(Regexp::Syntax::InvalidVersionNameError)
31
+ end
32
+
33
+ specify('version class tiny version') do
34
+ expect(Regexp::Syntax.version_class('ruby/1.9.3')).to eq Regexp::Syntax::V1_9_3
35
+
36
+ expect(Regexp::Syntax.version_class('ruby/2.3.1')).to eq Regexp::Syntax::V2_3_1
37
+ end
38
+
39
+ specify('version class minor version') do
40
+ expect(Regexp::Syntax.version_class('ruby/1.9')).to eq Regexp::Syntax::V1_9
41
+
42
+ expect(Regexp::Syntax.version_class('ruby/2.3')).to eq Regexp::Syntax::V2_3
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe(Regexp::Syntax::Token::Map) do
4
+ let(:map) { Regexp::Syntax::Token::Map }
5
+
6
+ specify('is complete') do
7
+ latest_syntax = Regexp::Syntax.new('ruby/2.9')
8
+
9
+ latest_syntax.features.each do |type, tokens|
10
+ tokens.each { |token| expect(map[type]).to include(token) }
11
+ end
12
+ end
13
+
14
+ specify('contains no duplicate type/token combinations') do
15
+ combinations = map.flat_map do |type, tokens|
16
+ tokens.map { |token| "#{type} #{token}" }
17
+ end
18
+
19
+ non_uniq = combinations.group_by { |str| str }.select { |_, v| v.count > 1 }
20
+
21
+ expect(non_uniq.keys).to be_empty
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe(Regexp::Syntax::V1_8_6) do
4
+ let(:syntax) { Regexp::Syntax.new('ruby/1.8.6') }
5
+
6
+ tests = {
7
+ implements: {
8
+ assertion: T::Assertion::Lookahead,
9
+ backref: [:number],
10
+ escape: T::Escape::Basic + T::Escape::ASCII + T::Escape::Meta + T::Escape::Control,
11
+ group: T::Group::V1_8_6,
12
+ quantifier: T::Quantifier::Greedy + T::Quantifier::Reluctant + T::Quantifier::Interval + T::Quantifier::IntervalReluctant
13
+ },
14
+ excludes: {
15
+ assertion: T::Assertion::Lookbehind,
16
+ backref: T::Backreference::All - [:number] + T::SubexpressionCall::All,
17
+ quantifier: T::Quantifier::Possessive
18
+ }
19
+ }
20
+
21
+ tests.each do |method, types|
22
+ expected = method != :excludes
23
+
24
+ types.each do |type, tokens|
25
+ if tokens.nil? || tokens.empty?
26
+ specify("syntax_V1_8_#{method}_#{type}") do
27
+ expect(syntax.implements?(type, nil)).to eq expected
28
+ end
29
+ else
30
+ tokens.each do |token|
31
+ specify("syntax_V1_8_#{method}_#{type}_#{token}") do
32
+ expect(syntax.implements?(type, token)).to eq expected
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe(Regexp::Syntax::V1_9_1) do
4
+ let(:syntax) { Regexp::Syntax.new('ruby/1.9.1') }
5
+
6
+ tests = {
7
+ implements: {
8
+ escape: T::Escape::Hex + T::Escape::Octal + T::Escape::Unicode,
9
+ type: T::CharacterType::Hex,
10
+ quantifier: T::Quantifier::Greedy + T::Quantifier::Reluctant + T::Quantifier::Possessive
11
+ }
12
+ }
13
+
14
+ tests.each do |method, types|
15
+ types.each do |type, tokens|
16
+ tokens.each do |token|
17
+ specify("syntax_V1_9_1_#{method}_#{type}_#{token}") do
18
+ expect(syntax.implements?(type, token)).to be true
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe(Regexp::Syntax::V1_9_3) do
4
+ let(:syntax) { Regexp::Syntax.new('ruby/1.9.3') }
5
+
6
+ tests = {
7
+ implements: {
8
+ property: T::UnicodeProperty::Script_V1_9_3 + T::UnicodeProperty::Age_V1_9_3,
9
+ nonproperty: T::UnicodeProperty::Script_V1_9_3 + T::UnicodeProperty::Age_V1_9_3
10
+ }
11
+ }
12
+
13
+ tests.each do |method, types|
14
+ types.each do |type, tokens|
15
+ tokens.each do |token|
16
+ specify("syntax_V1_9_3_#{method}_#{type}_#{token}") do
17
+ expect(syntax.implements?(type, token)).to be true
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end