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 ScannerEscapes < Test::Unit::TestCase
1
+ require 'spec_helper'
4
2
 
3
+ RSpec.describe('Escape scanning') do
5
4
  tests = {
6
5
  /c\at/ => [1, :escape, :bell, '\a', 1, 3],
7
6
 
@@ -41,16 +40,15 @@ class ScannerEscapes < Test::Unit::TestCase
41
40
  }
42
41
 
43
42
  tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
44
- define_method "test_scanner_#{type}_#{token}_#{count}" do
43
+ specify("scanner_#{type}_#{token}_#{count}") do
45
44
  tokens = RS.scan(pattern)
46
45
  result = tokens.at(index)
47
46
 
48
- assert_equal type, result[0]
49
- assert_equal token, result[1]
50
- assert_equal text, result[2]
51
- assert_equal ts, result[3]
52
- assert_equal te, result[4]
47
+ expect(result[0]).to eq type
48
+ expect(result[1]).to eq token
49
+ expect(result[2]).to eq text
50
+ expect(result[3]).to eq ts
51
+ expect(result[4]).to eq te
53
52
  end
54
53
  end
55
-
56
54
  end
@@ -1,43 +1,38 @@
1
- require File.expand_path("../../helpers", __FILE__)
1
+ require 'spec_helper'
2
2
 
3
- class ScannerFreeSpace < Test::Unit::TestCase
4
-
5
- def test_scan_free_space_tokens
6
- regexp = %r{
3
+ RSpec.describe('FreeSpace scanning') do
4
+ specify('scan free space tokens') do
5
+ regexp = /
7
6
  a
8
7
  b ? c *
9
8
  d {2,3}
10
9
  e + | f +
11
- }x
10
+ /x
12
11
 
13
12
  tokens = RS.scan(regexp)
14
13
 
15
14
  0.upto(24) do |i|
16
15
  if i.even?
17
- assert_equal :free_space, tokens[i][0]
18
- assert_equal :whitespace, tokens[i][1]
16
+ expect(tokens[i][0]).to eq :free_space
17
+ expect(tokens[i][1]).to eq :whitespace
19
18
  else
20
- refute_equal :free_space, tokens[i][0]
21
- refute_equal :whitespace, tokens[i][1]
19
+ expect(tokens[i][0]).not_to eq :free_space
20
+ expect(tokens[i][1]).not_to eq :whitespace
22
21
  end
23
22
  end
24
23
 
25
- [0, 2, 10, 14].each do |i|
26
- assert_equal "\n ", tokens[i][2]
27
- end
24
+ [0, 2, 10, 14].each { |i| expect(tokens[i][2]).to eq "\n " }
28
25
 
29
- [4, 6, 8, 12].each do |i|
30
- assert_equal ' ', tokens[i][2]
31
- end
26
+ [4, 6, 8, 12].each { |i| expect(tokens[i][2]).to eq ' ' }
32
27
  end
33
28
 
34
- def test_scan_free_space_comments
35
- regexp = %r{
29
+ specify('scan free space comments') do
30
+ regexp = /
36
31
  a + # A + comment
37
32
  b ? # B ? comment
38
33
  c {2,3} # C {2,3} comment
39
34
  d + | e + # D|E comment
40
- }x
35
+ /x
41
36
 
42
37
  tokens = RS.scan(regexp)
43
38
 
@@ -49,17 +44,17 @@ class ScannerFreeSpace < Test::Unit::TestCase
49
44
  ].each do |index, type, token, text, ts, te|
50
45
  result = tokens[index]
51
46
 
52
- assert_equal type, result[0]
53
- assert_equal token, result[1]
54
- assert_equal text, result[2]
55
- assert_equal ts, result[3]
56
- assert_equal te, result[4]
47
+ expect(result[0]).to eq type
48
+ expect(result[1]).to eq token
49
+ expect(result[2]).to eq text
50
+ expect(result[3]).to eq ts
51
+ expect(result[4]).to eq te
57
52
  end
58
53
  end
59
54
 
60
- def test_scan_free_space_inlined
61
- # Matches 'a bcdef g'
55
+ specify('scan free space inlined') do
62
56
  regexp = /a b(?x:c d e)f g/
57
+
63
58
  tokens = RS.scan(regexp)
64
59
 
65
60
  [
@@ -75,17 +70,17 @@ class ScannerFreeSpace < Test::Unit::TestCase
75
70
  ].each do |index, type, token, text, ts, te|
76
71
  result = tokens[index]
77
72
 
78
- assert_equal type, result[0]
79
- assert_equal token, result[1]
80
- assert_equal text, result[2]
81
- assert_equal ts, result[3]
82
- assert_equal te, result[4]
73
+ expect(result[0]).to eq type
74
+ expect(result[1]).to eq token
75
+ expect(result[2]).to eq text
76
+ expect(result[3]).to eq ts
77
+ expect(result[4]).to eq te
83
78
  end
84
79
  end
85
80
 
86
- def test_scan_free_space_nested
87
- # Matches 'a bcde fghi j'
81
+ specify('scan free space nested') do
88
82
  regexp = /a b(?x:c d(?-x:e f)g h)i j/
83
+
89
84
  tokens = RS.scan(regexp)
90
85
 
91
86
  [
@@ -105,17 +100,17 @@ class ScannerFreeSpace < Test::Unit::TestCase
105
100
  ].each do |index, type, token, text, ts, te|
106
101
  result = tokens[index]
107
102
 
108
- assert_equal type, result[0]
109
- assert_equal token, result[1]
110
- assert_equal text, result[2]
111
- assert_equal ts, result[3]
112
- assert_equal te, result[4]
103
+ expect(result[0]).to eq type
104
+ expect(result[1]).to eq token
105
+ expect(result[2]).to eq text
106
+ expect(result[3]).to eq ts
107
+ expect(result[4]).to eq te
113
108
  end
114
109
  end
115
110
 
116
- def test_scan_free_space_nested_groups
117
- # Matches 'a bcde f g hi j'
111
+ specify('scan free space nested groups') do
118
112
  regexp = /(a (b(?x: (c d) (?-x:(e f) )g) h)i j)/
113
+
119
114
  tokens = RS.scan(regexp)
120
115
 
121
116
  [
@@ -146,18 +141,19 @@ class ScannerFreeSpace < Test::Unit::TestCase
146
141
  ].each do |index, type, token, text, ts, te|
147
142
  result = tokens[index]
148
143
 
149
- assert_equal type, result[0]
150
- assert_equal token, result[1]
151
- assert_equal text, result[2]
152
- assert_equal ts, result[3]
153
- assert_equal te, result[4]
144
+ expect(result[0]).to eq type
145
+ expect(result[1]).to eq token
146
+ expect(result[2]).to eq text
147
+ expect(result[3]).to eq ts
148
+ expect(result[4]).to eq te
154
149
  end
155
150
  end
156
151
 
157
- def test_scan_free_space_switch_groups
158
- # Matches 'a bcde f g hi j'
152
+ specify('scan free space switch groups') do
159
153
  regexp = /(a (b((?x) (c d) ((?-x)(e f) )g) h)i j)/
154
+
160
155
  tokens = RS.scan(regexp)
156
+
161
157
  [
162
158
  [ 0, :group, :capture, '(', 0, 1],
163
159
  [ 1, :literal, :literal, 'a ', 1, 3],
@@ -190,11 +186,11 @@ class ScannerFreeSpace < Test::Unit::TestCase
190
186
  ].each do |index, type, token, text, ts, te|
191
187
  result = tokens[index]
192
188
 
193
- assert_equal type, result[0]
194
- assert_equal token, result[1]
195
- assert_equal text, result[2]
196
- assert_equal ts, result[3]
197
- assert_equal te, result[4]
189
+ expect(result[0]).to eq type
190
+ expect(result[1]).to eq token
191
+ expect(result[2]).to eq text
192
+ expect(result[3]).to eq ts
193
+ expect(result[4]).to eq te
198
194
  end
199
195
  end
200
196
  end
@@ -1,18 +1,7 @@
1
- require File.expand_path("../../helpers", __FILE__)
2
-
3
- class ScannerGroups < Test::Unit::TestCase
1
+ require 'spec_helper'
4
2
 
3
+ RSpec.describe('Group scanning') do
5
4
  tests = {
6
- # Options
7
- '(?-mix:abc)' => [0, :group, :options, '(?-mix:', 0, 7],
8
- '(?m-ix:abc)' => [0, :group, :options, '(?m-ix:', 0, 7],
9
- '(?mi-x:abc)' => [0, :group, :options, '(?mi-x:', 0, 7],
10
- '(?mix:abc)' => [0, :group, :options, '(?mix:', 0, 6],
11
- '(?m:)' => [0, :group, :options, '(?m:', 0, 4],
12
- '(?i:)' => [0, :group, :options, '(?i:', 0, 4],
13
- '(?x:)' => [0, :group, :options, '(?x:', 0, 4],
14
- '(?mix)' => [0, :group, :options_switch, '(?mix', 0, 5],
15
-
16
5
  # Group types
17
6
  '(?>abc)' => [0, :group, :atomic, '(?>', 0, 3],
18
7
  '(abc)' => [0, :group, :capture, '(', 0, 1],
@@ -36,44 +25,47 @@ class ScannerGroups < Test::Unit::TestCase
36
25
  '(?!abc)' => [0, :assertion, :nlookahead, '(?!', 0, 3],
37
26
  '(?<=abc)' => [0, :assertion, :lookbehind, '(?<=', 0, 4],
38
27
  '(?<!abc)' => [0, :assertion, :nlookbehind, '(?<!', 0, 4],
39
- }
40
28
 
41
- if RUBY_VERSION >= '2.0'
42
- tests.merge!({
43
- # New options
44
- '(?d-mix:abc)' => [0, :group, :options, '(?d-mix:', 0, 8],
45
- '(?a-mix:abc)' => [0, :group, :options, '(?a-mix:', 0, 8],
46
- '(?u-mix:abc)' => [0, :group, :options, '(?u-mix:', 0, 8],
47
- '(?da-m:abc)' => [0, :group, :options, '(?da-m:', 0, 7],
48
- '(?du-x:abc)' => [0, :group, :options, '(?du-x:', 0, 7],
49
- '(?dau-i:abc)' => [0, :group, :options, '(?dau-i:', 0, 8],
50
- '(?dau:abc)' => [0, :group, :options, '(?dau:', 0, 6],
51
- '(?d:)' => [0, :group, :options, '(?d:', 0, 4],
52
- '(?a:)' => [0, :group, :options, '(?a:', 0, 4],
53
- '(?u:)' => [0, :group, :options, '(?u:', 0, 4],
54
- '(?dau)' => [0, :group, :options_switch, '(?dau', 0, 5],
55
- })
56
- end
29
+ # Options
30
+ '(?-mix:abc)' => [0, :group, :options, '(?-mix:', 0, 7],
31
+ '(?m-ix:abc)' => [0, :group, :options, '(?m-ix:', 0, 7],
32
+ '(?mi-x:abc)' => [0, :group, :options, '(?mi-x:', 0, 7],
33
+ '(?mix:abc)' => [0, :group, :options, '(?mix:', 0, 6],
34
+ '(?m:)' => [0, :group, :options, '(?m:', 0, 4],
35
+ '(?i:)' => [0, :group, :options, '(?i:', 0, 4],
36
+ '(?x:)' => [0, :group, :options, '(?x:', 0, 4],
37
+ '(?mix)' => [0, :group, :options_switch, '(?mix', 0, 5],
38
+ '(?d-mix:abc)' => [0, :group, :options, '(?d-mix:', 0, 8],
39
+ '(?a-mix:abc)' => [0, :group, :options, '(?a-mix:', 0, 8],
40
+ '(?u-mix:abc)' => [0, :group, :options, '(?u-mix:', 0, 8],
41
+ '(?da-m:abc)' => [0, :group, :options, '(?da-m:', 0, 7],
42
+ '(?du-x:abc)' => [0, :group, :options, '(?du-x:', 0, 7],
43
+ '(?dau-i:abc)' => [0, :group, :options, '(?dau-i:', 0, 8],
44
+ '(?dau:abc)' => [0, :group, :options, '(?dau:', 0, 6],
45
+ '(?d:)' => [0, :group, :options, '(?d:', 0, 4],
46
+ '(?a:)' => [0, :group, :options, '(?a:', 0, 4],
47
+ '(?u:)' => [0, :group, :options, '(?u:', 0, 4],
48
+ '(?dau)' => [0, :group, :options_switch, '(?dau', 0, 5],
49
+ }
57
50
 
58
- if RUBY_VERSION >= '2.4.1'
59
- tests.merge!({
51
+ if ruby_version_at_least('2.4.1')
52
+ tests.merge!(
60
53
  # New absence operator
61
54
  '(?~abc)' => [0, :group, :absence, '(?~', 0, 3],
62
- })
55
+ )
63
56
  end
64
57
 
65
58
  tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
66
- define_method "test_scanner_#{type}_#{token}_#{count}" do
59
+ specify("scanner_#{type}_#{token}_#{count}") do
67
60
  tokens = RS.scan(pattern)
68
61
  result = tokens[index]
69
62
 
70
- assert_equal type, result[0]
71
- assert_equal token, result[1]
72
- assert_equal text, result[2]
73
- assert_equal ts, result[3]
74
- assert_equal te, result[4]
75
- assert_equal text, pattern[ts, te]
63
+ expect(result[0]).to eq type
64
+ expect(result[1]).to eq token
65
+ expect(result[2]).to eq text
66
+ expect(result[3]).to eq ts
67
+ expect(result[4]).to eq te
68
+ expect(pattern[ts, te]).to eq text
76
69
  end
77
70
  end
78
-
79
71
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe('Keep scanning') do
4
+ specify('scan keep token') do
5
+ tokens = RS.scan(/ab\Kcd/)
6
+ result = tokens.at(1)
7
+
8
+ expect(result[0]).to eq :keep
9
+ expect(result[1]).to eq :mark
10
+ expect(result[2]).to eq '\\K'
11
+ expect(result[3]).to eq 2
12
+ expect(result[4]).to eq 4
13
+ end
14
+
15
+ specify('scan keep nested') do
16
+ tokens = RS.scan(/(a\Kb)|(c\\\Kd)ef/)
17
+
18
+ first = tokens.at(2)
19
+ second = tokens.at(9)
20
+
21
+ expect(first[0]).to eq :keep
22
+ expect(first[1]).to eq :mark
23
+ expect(first[2]).to eq '\\K'
24
+ expect(first[3]).to eq 2
25
+ expect(first[4]).to eq 4
26
+
27
+ expect(second[0]).to eq :keep
28
+ expect(second[1]).to eq :mark
29
+ expect(second[2]).to eq '\\K'
30
+ expect(second[3]).to eq 11
31
+ expect(second[4]).to eq 13
32
+ end
33
+ end
@@ -1,9 +1,6 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require File.expand_path("../../helpers", __FILE__)
4
-
5
- class ScannerUTF8 < Test::Unit::TestCase
1
+ require 'spec_helper'
6
2
 
3
+ RSpec.describe('UTF8 scanning') do
7
4
  tests = {
8
5
  # ascii, single byte characters
9
6
  'a' => {
@@ -71,19 +68,18 @@ class ScannerUTF8 < Test::Unit::TestCase
71
68
  }
72
69
 
73
70
  tests.each_with_index do |(pattern, checks), count|
74
- define_method "test_scanner_utf8_runs_#{count}" do
71
+ specify("scanner_utf8_runs_#{count}") do
75
72
  tokens = RS.scan(pattern)
76
73
 
77
74
  checks.each do |index, (type, token, text, ts, te)|
78
75
  result = tokens[index]
79
76
 
80
- assert_equal type, result[0]
81
- assert_equal token, result[1]
82
- assert_equal text, result[2]
83
- assert_equal ts, result[3]
84
- assert_equal te, result[4]
77
+ expect(result[0]).to eq type
78
+ expect(result[1]).to eq token
79
+ expect(result[2]).to eq text
80
+ expect(result[3]).to eq ts
81
+ expect(result[4]).to eq te
85
82
  end
86
83
  end
87
84
  end
88
-
89
85
  end
@@ -1,7 +1,6 @@
1
- require File.expand_path("../../helpers", __FILE__)
2
-
3
- class ScannerMeta < Test::Unit::TestCase
1
+ require 'spec_helper'
4
2
 
3
+ RSpec.describe('Meta scanning') do
5
4
  tests = {
6
5
  'abc??|def*+|ghi+' => {
7
6
  0 => [:literal, :literal, 'abc', 0, 3],
@@ -22,19 +21,18 @@ class ScannerMeta < Test::Unit::TestCase
22
21
  }
23
22
 
24
23
  tests.each_with_index do |(pattern, checks), count|
25
- define_method "test_scanner_meta_alternation_#{count}" do
24
+ specify("scanner_meta_alternation_#{count}") do
26
25
  tokens = RS.scan(pattern)
27
26
 
28
27
  checks.each do |index, (type, token, text, ts, te)|
29
28
  result = tokens.at(index)
30
29
 
31
- assert_equal type, result[0]
32
- assert_equal token, result[1]
33
- assert_equal text, result[2]
34
- assert_equal ts, result[3]
35
- assert_equal te, result[4]
30
+ expect(result[0]).to eq type
31
+ expect(result[1]).to eq token
32
+ expect(result[2]).to eq text
33
+ expect(result[3]).to eq ts
34
+ expect(result[4]).to eq te
36
35
  end
37
36
  end
38
37
  end
39
-
40
38
  end
@@ -1,7 +1,6 @@
1
- require File.expand_path("../../helpers", __FILE__)
2
-
3
- class ScannerProperties < Test::Unit::TestCase
1
+ require 'spec_helper'
4
2
 
3
+ RSpec.describe('Property scanning') do
5
4
  tests = {
6
5
  'Alnum' => :alnum,
7
6
 
@@ -277,36 +276,32 @@ class ScannerProperties < Test::Unit::TestCase
277
276
  }
278
277
 
279
278
  tests.each_with_index do |(property, token), count|
280
- define_method "test_scan_property_#{token}_#{count}" do
279
+ specify("scan_property_#{token}_#{count}") do
281
280
  tokens = RS.scan("a\\p{#{property}}c")
282
281
  result = tokens.at(1)
283
-
284
- assert_equal :property, result[0]
285
- assert_equal token, result[1]
282
+ expect(result[0]).to eq :property
283
+ expect(result[1]).to eq token
286
284
  end
287
285
 
288
- define_method "test_scan_nonproperty_#{token}_#{count}" do
286
+ specify("scan_nonproperty_#{token}_#{count}") do
289
287
  tokens = RS.scan("a\\P{#{property}}c")
290
288
  result = tokens.at(1)
291
-
292
- assert_equal :nonproperty, result[0]
293
- assert_equal token, result[1]
289
+ expect(result[0]).to eq :nonproperty
290
+ expect(result[1]).to eq token
294
291
  end
295
292
 
296
- define_method "test_scan_caret_nonproperty_#{token}_#{count}" do
293
+ specify("scan_caret_nonproperty_#{token}_#{count}") do
297
294
  tokens = RS.scan("a\\p{^#{property}}c")
298
295
  result = tokens.at(1)
299
-
300
- assert_equal :nonproperty, result[0]
301
- assert_equal token, result[1]
296
+ expect(result[0]).to eq :nonproperty
297
+ expect(result[1]).to eq token
302
298
  end
303
299
 
304
- define_method "test_scan_double_negated_property_#{token}_#{count}" do
300
+ specify("scan_double_negated_property_#{token}_#{count}") do
305
301
  tokens = RS.scan("a\\P{^#{property}}c")
306
302
  result = tokens.at(1)
307
-
308
- assert_equal :property, result[0]
309
- assert_equal token, result[1]
303
+ expect(result[0]).to eq :property
304
+ expect(result[1]).to eq token
310
305
  end
311
306
  end
312
307
  end