regexp_parser 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +6 -0
  3. data/lib/regexp_parser/syntax/ruby/1.9.1.rb +1 -1
  4. data/lib/regexp_parser/syntax/tokens/escape.rb +2 -0
  5. data/lib/regexp_parser/version.rb +1 -1
  6. data/test/expression/test_base.rb +32 -34
  7. data/test/expression/test_clone.rb +49 -47
  8. data/test/expression/test_conditionals.rb +40 -40
  9. data/test/expression/test_free_space.rb +4 -2
  10. data/test/expression/test_set.rb +16 -16
  11. data/test/expression/test_strfregexp.rb +74 -74
  12. data/test/expression/test_subexpression.rb +2 -2
  13. data/test/expression/test_tests.rb +57 -57
  14. data/test/expression/test_to_h.rb +11 -6
  15. data/test/expression/test_to_s.rb +22 -15
  16. data/test/expression/test_traverse.rb +26 -29
  17. data/test/lexer/test_all.rb +9 -7
  18. data/test/lexer/test_conditionals.rb +35 -11
  19. data/test/lexer/test_keep.rb +6 -6
  20. data/test/lexer/test_literals.rb +20 -10
  21. data/test/lexer/test_nesting.rb +14 -7
  22. data/test/lexer/test_refcalls.rb +12 -5
  23. data/test/parser/test_all.rb +15 -13
  24. data/test/parser/test_alternation.rb +29 -26
  25. data/test/parser/test_anchors.rb +7 -8
  26. data/test/parser/test_conditionals.rb +43 -41
  27. data/test/parser/test_escapes.rb +18 -16
  28. data/test/parser/test_free_space.rb +33 -33
  29. data/test/parser/test_groups.rb +46 -46
  30. data/test/parser/test_keep.rb +4 -4
  31. data/test/parser/test_properties.rb +18 -16
  32. data/test/parser/test_quantifiers.rb +184 -163
  33. data/test/parser/test_refcalls.rb +48 -32
  34. data/test/parser/test_sets.rb +102 -88
  35. data/test/parser/test_types.rb +7 -8
  36. data/test/scanner/test_all.rb +6 -4
  37. data/test/scanner/test_anchors.rb +8 -5
  38. data/test/scanner/test_conditionals.rb +38 -20
  39. data/test/scanner/test_escapes.rb +8 -6
  40. data/test/scanner/test_free_space.rb +89 -65
  41. data/test/scanner/test_groups.rb +27 -32
  42. data/test/scanner/test_keep.rb +24 -22
  43. data/test/scanner/test_literals.rb +11 -7
  44. data/test/scanner/test_meta.rb +11 -7
  45. data/test/scanner/test_properties.rb +16 -14
  46. data/test/scanner/test_quantifiers.rb +8 -9
  47. data/test/scanner/test_refcalls.rb +26 -23
  48. data/test/scanner/test_scripts.rb +11 -10
  49. data/test/scanner/test_sets.rb +8 -5
  50. data/test/scanner/test_types.rb +17 -15
  51. data/test/scanner/test_unicode_blocks.rb +11 -10
  52. data/test/syntax/ruby/test_1.8.rb +4 -8
  53. data/test/syntax/ruby/test_1.9.1.rb +1 -7
  54. data/test/syntax/ruby/test_1.9.3.rb +3 -7
  55. data/test/syntax/ruby/test_2.0.0.rb +1 -7
  56. data/test/syntax/ruby/test_2.2.0.rb +1 -7
  57. data/test/token/test_token.rb +29 -31
  58. metadata +3 -3
@@ -22,13 +22,16 @@ class ScannerAnchors < Test::Unit::TestCase
22
22
  "a\\\\Bc" => [1, :escape, :backslash, '\\\\', 1, 3],
23
23
  }
24
24
 
25
- count = 0
26
- tests.each do |pattern, test|
27
- define_method "test_scanner_#{test[1]}_#{test[2]}_#{count+=1}" do
28
-
25
+ tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
26
+ define_method "test_scanner_#{type}_#{token}_#{count}" do
29
27
  tokens = RS.scan(pattern)
30
- assert_equal( test[1,5], tokens[test[0]] )
28
+ result = tokens[index]
31
29
 
30
+ assert_equal type, result[0]
31
+ assert_equal token, result[1]
32
+ assert_equal text, result[2]
33
+ assert_equal ts, result[3]
34
+ assert_equal te, result[4]
32
35
  end
33
36
  end
34
37
 
@@ -22,14 +22,16 @@ class ScannerConditionals < Test::Unit::TestCase
22
22
  /(?'N'A)(?('N')T|F)/ => [5, :conditional, :condition, "'N'", 10, 13],
23
23
  }
24
24
 
25
- count = 0
26
- tests.each do |pattern, test|
27
- define_method "test_scan_#{test[1]}_#{test[2]}_#{count+=1}" do
28
-
25
+ tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
26
+ define_method "test_scanner_#{type}_#{token}_#{count}" do
29
27
  tokens = RS.scan(pattern)
30
- token = tokens[test[0]]
31
- assert_equal( test[1,5], token )
28
+ result = tokens[index]
32
29
 
30
+ assert_equal type, result[0]
31
+ assert_equal token, result[1]
32
+ assert_equal text, result[2]
33
+ assert_equal ts, result[3]
34
+ assert_equal te, result[4]
33
35
  end
34
36
  end
35
37
 
@@ -80,8 +82,14 @@ class ScannerConditionals < Test::Unit::TestCase
80
82
  [40, :conditional, :close, ')', 45, 46],
81
83
  [41, :conditional, :close, ')', 46, 47],
82
84
  [42, :conditional, :close, ')', 47, 48]
83
- ].each do |test|
84
- assert_equal( test[1,5], tokens[test[0]] )
85
+ ].each do |index, type, token, text, ts, te|
86
+ result = tokens[index]
87
+
88
+ assert_equal type, result[0]
89
+ assert_equal token, result[1]
90
+ assert_equal text, result[2]
91
+ assert_equal ts, result[3]
92
+ assert_equal te, result[4]
85
93
  end
86
94
  end
87
95
 
@@ -139,8 +147,14 @@ class ScannerConditionals < Test::Unit::TestCase
139
147
  [47, :conditional, :close, ')', 50, 51],
140
148
  [48, :group, :close, ')', 51, 52],
141
149
  [49, :group, :close, ')', 52, 53]
142
- ].each do |test|
143
- assert_equal( test[1,5], tokens[test[0]] )
150
+ ].each do |index, type, token, text, ts, te|
151
+ result = tokens[index]
152
+
153
+ assert_equal type, result[0]
154
+ assert_equal token, result[1]
155
+ assert_equal text, result[2]
156
+ assert_equal ts, result[3]
157
+ assert_equal te, result[4]
144
158
  end
145
159
  end
146
160
 
@@ -148,18 +162,22 @@ class ScannerConditionals < Test::Unit::TestCase
148
162
  regexp = /(a)(?(1)(b|c|d)|(e|f|g))(h)(?(2)(i|j|k)|(l|m|n))|o|p/
149
163
  tokens = RS.scan(regexp)
150
164
 
151
- [9, 11, 17, 19, 32, 34, 40, 42, 46, 48].each do |token|
152
- assert_equal(:meta, tokens[token][0])
153
- assert_equal(:alternation, tokens[token][1])
154
- assert_equal('|', tokens[token][2])
155
- assert_equal(1, tokens[token][4] - tokens[token][3])
165
+ [9, 11, 17, 19, 32, 34, 40, 42, 46, 48].each do |index|
166
+ result = tokens[index]
167
+
168
+ assert_equal :meta, result[0]
169
+ assert_equal :alternation, result[1]
170
+ assert_equal '|', result[2]
171
+ assert_equal 1, result[4] - result[3]
156
172
  end
157
173
 
158
- [14, 37].each do |token|
159
- assert_equal(:conditional, tokens[token][0])
160
- assert_equal(:separator, tokens[token][1])
161
- assert_equal('|', tokens[token][2])
162
- assert_equal(1, tokens[token][4] - tokens[token][3])
174
+ [14, 37].each do |index|
175
+ result = tokens[index]
176
+
177
+ assert_equal :conditional, result[0]
178
+ assert_equal :separator, result[1]
179
+ assert_equal '|', result[2]
180
+ assert_equal 1, result[4] - result[3]
163
181
  end
164
182
  end
165
183
 
@@ -38,14 +38,16 @@ class ScannerEscapes < Test::Unit::TestCase
38
38
  'ab\\\Kcd' => [1, :escape, :backslash, '\\\\', 2, 4],
39
39
  }
40
40
 
41
- count = 0
42
- tests.each do |pattern, test|
43
- define_method "test_scan_#{test[1]}_#{test[2]}_#{count+=1}" do
44
-
41
+ tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
42
+ define_method "test_scanner_#{type}_#{token}_#{count}" do
45
43
  tokens = RS.scan(pattern)
46
- token = tokens[test[0]]
47
- assert_equal( test[1,5], token )
44
+ result = tokens.at(index)
48
45
 
46
+ assert_equal type, result[0]
47
+ assert_equal token, result[1]
48
+ assert_equal text, result[2]
49
+ assert_equal ts, result[3]
50
+ assert_equal te, result[4]
49
51
  end
50
52
  end
51
53
 
@@ -13,21 +13,21 @@ class ScannerFreeSpace < Test::Unit::TestCase
13
13
  tokens = RS.scan(regexp)
14
14
 
15
15
  0.upto(24) do |i|
16
- if i % 2 == 0
17
- assert_equal( :free_space, tokens[i][0] )
18
- assert_equal( :whitespace, tokens[i][1] )
16
+ if i.even?
17
+ assert_equal :free_space, tokens[i][0]
18
+ assert_equal :whitespace, tokens[i][1]
19
19
  else
20
- assert_not_equal( :free_space, tokens[i][0] )
21
- assert_not_equal( :whitespace, tokens[i][1] )
20
+ refute_equal :free_space, tokens[i][0]
21
+ refute_equal :whitespace, tokens[i][1]
22
22
  end
23
23
  end
24
24
 
25
25
  [0, 2, 10, 14].each do |i|
26
- assert_equal( "\n ", tokens[i][2] )
26
+ assert_equal "\n ", tokens[i][2]
27
27
  end
28
28
 
29
29
  [4, 6, 8, 12].each do |i|
30
- assert_equal( ' ', tokens[i][2] )
30
+ assert_equal ' ', tokens[i][2]
31
31
  end
32
32
  end
33
33
 
@@ -42,12 +42,18 @@ class ScannerFreeSpace < Test::Unit::TestCase
42
42
  tokens = RS.scan(regexp)
43
43
 
44
44
  [
45
- [ 5, [:free_space, :comment, "# A + comment\n", 11, 25]],
46
- [11, [:free_space, :comment, "# B ? comment\n", 37, 51]],
47
- [17, [:free_space, :comment, "# C {2,3} comment\n", 66, 84]],
48
- [29, [:free_space, :comment, "# D|E comment\n", 100, 114]],
49
- ].each do |index, token|
50
- assert_equal( token, tokens[index] )
45
+ [ 5, :free_space, :comment, "# A + comment\n", 11, 25],
46
+ [11, :free_space, :comment, "# B ? comment\n", 37, 51],
47
+ [17, :free_space, :comment, "# C {2,3} comment\n", 66, 84],
48
+ [29, :free_space, :comment, "# D|E comment\n", 100, 114],
49
+ ].each do |index, type, token, text, ts, te|
50
+ result = tokens[index]
51
+
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]
51
57
  end
52
58
  end
53
59
 
@@ -57,17 +63,23 @@ class ScannerFreeSpace < Test::Unit::TestCase
57
63
  tokens = RS.scan(regexp)
58
64
 
59
65
  [
60
- [0, [:literal, :literal, 'a b', 0, 3]],
61
- [1, [:group, :options, '(?x:', 3, 7]],
62
- [2, [:literal, :literal, 'c', 7, 8]],
63
- [3, [:free_space, :whitespace, ' ', 8, 9]],
64
- [4, [:literal, :literal, 'd', 9, 10]],
65
- [5, [:free_space, :whitespace, ' ', 10, 11]],
66
- [6, [:literal, :literal, 'e', 11, 12]],
67
- [7, [:group, :close, ')', 12, 13]],
68
- [8, [:literal, :literal, 'f g', 13, 16]]
69
- ].each do |index, token|
70
- assert_equal( token, tokens[index] )
66
+ [0, :literal, :literal, 'a b', 0, 3],
67
+ [1, :group, :options, '(?x:', 3, 7],
68
+ [2, :literal, :literal, 'c', 7, 8],
69
+ [3, :free_space, :whitespace, ' ', 8, 9],
70
+ [4, :literal, :literal, 'd', 9, 10],
71
+ [5, :free_space, :whitespace, ' ', 10, 11],
72
+ [6, :literal, :literal, 'e', 11, 12],
73
+ [7, :group, :close, ')', 12, 13],
74
+ [8, :literal, :literal, 'f g', 13, 16]
75
+ ].each do |index, type, token, text, ts, te|
76
+ result = tokens[index]
77
+
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]
71
83
  end
72
84
  end
73
85
 
@@ -77,21 +89,27 @@ class ScannerFreeSpace < Test::Unit::TestCase
77
89
  tokens = RS.scan(regexp)
78
90
 
79
91
  [
80
- [ 0, [:literal, :literal, 'a b', 0, 3]],
81
- [ 1, [:group, :options, '(?x:', 3, 7]],
82
- [ 2, [:literal, :literal, 'c', 7, 8]],
83
- [ 3, [:free_space, :whitespace, ' ', 8, 9]],
84
- [ 4, [:literal, :literal, 'd', 9, 10]],
85
- [ 5, [:group, :options, '(?-x:', 10, 15]],
86
- [ 6, [:literal, :literal, 'e f', 15, 18]],
87
- [ 7, [:group, :close, ')', 18, 19]],
88
- [ 8, [:literal, :literal, 'g', 19, 20]],
89
- [ 9, [:free_space, :whitespace, ' ', 20, 21]],
90
- [10, [:literal, :literal, 'h', 21, 22]],
91
- [11, [:group, :close, ')', 22, 23]],
92
- [12, [:literal, :literal, 'i j', 23, 26]]
93
- ].each do |index, token|
94
- assert_equal( token, tokens[index] )
92
+ [ 0, :literal, :literal, 'a b', 0, 3],
93
+ [ 1, :group, :options, '(?x:', 3, 7],
94
+ [ 2, :literal, :literal, 'c', 7, 8],
95
+ [ 3, :free_space, :whitespace, ' ', 8, 9],
96
+ [ 4, :literal, :literal, 'd', 9, 10],
97
+ [ 5, :group, :options, '(?-x:', 10, 15],
98
+ [ 6, :literal, :literal, 'e f', 15, 18],
99
+ [ 7, :group, :close, ')', 18, 19],
100
+ [ 8, :literal, :literal, 'g', 19, 20],
101
+ [ 9, :free_space, :whitespace, ' ', 20, 21],
102
+ [10, :literal, :literal, 'h', 21, 22],
103
+ [11, :group, :close, ')', 22, 23],
104
+ [12, :literal, :literal, 'i j', 23, 26]
105
+ ].each do |index, type, token, text, ts, te|
106
+ result = tokens[index]
107
+
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]
95
113
  end
96
114
  end
97
115
 
@@ -101,32 +119,38 @@ class ScannerFreeSpace < Test::Unit::TestCase
101
119
  tokens = RS.scan(regexp)
102
120
 
103
121
  [
104
- [ 0, [:group, :capture, '(', 0, 1]],
105
- [ 1, [:literal, :literal, 'a ', 1, 3]],
106
- [ 2, [:group, :capture, '(', 3, 4]],
107
- [ 3, [:literal, :literal, 'b', 4, 5]],
108
- [ 4, [:group, :options, '(?x:', 5, 9]],
109
- [ 5, [:free_space, :whitespace, ' ', 9, 10]],
110
- [ 6, [:group, :capture, '(', 10, 11]],
111
- [ 7, [:literal, :literal, 'c', 11, 12]],
112
- [ 8, [:free_space, :whitespace, ' ', 12, 13]],
113
- [ 9, [:literal, :literal, 'd', 13, 14]],
114
- [10, [:group, :close, ')', 14, 15]],
115
- [11, [:free_space, :whitespace, ' ', 15, 16]],
116
- [12, [:group, :options, '(?-x:', 16, 21]],
117
- [13, [:group, :capture, '(', 21, 22]],
118
- [14, [:literal, :literal, 'e f', 22, 25]],
119
- [15, [:group, :close, ')', 25, 26]],
120
- [16, [:literal, :literal, ' ', 26, 27]],
121
- [17, [:group, :close, ')', 27, 28]],
122
- [18, [:literal, :literal, 'g', 28, 29]],
123
- [19, [:group, :close, ')', 29, 30]],
124
- [20, [:literal, :literal, ' h', 30, 32]],
125
- [21, [:group, :close, ')', 32, 33]],
126
- [22, [:literal, :literal, 'i j', 33, 36]],
127
- [23, [:group, :close, ')', 36, 37]]
128
- ].each do |index, token|
129
- assert_equal( token, tokens[index] )
122
+ [ 0, :group, :capture, '(', 0, 1],
123
+ [ 1, :literal, :literal, 'a ', 1, 3],
124
+ [ 2, :group, :capture, '(', 3, 4],
125
+ [ 3, :literal, :literal, 'b', 4, 5],
126
+ [ 4, :group, :options, '(?x:', 5, 9],
127
+ [ 5, :free_space, :whitespace, ' ', 9, 10],
128
+ [ 6, :group, :capture, '(', 10, 11],
129
+ [ 7, :literal, :literal, 'c', 11, 12],
130
+ [ 8, :free_space, :whitespace, ' ', 12, 13],
131
+ [ 9, :literal, :literal, 'd', 13, 14],
132
+ [10, :group, :close, ')', 14, 15],
133
+ [11, :free_space, :whitespace, ' ', 15, 16],
134
+ [12, :group, :options, '(?-x:', 16, 21],
135
+ [13, :group, :capture, '(', 21, 22],
136
+ [14, :literal, :literal, 'e f', 22, 25],
137
+ [15, :group, :close, ')', 25, 26],
138
+ [16, :literal, :literal, ' ', 26, 27],
139
+ [17, :group, :close, ')', 27, 28],
140
+ [18, :literal, :literal, 'g', 28, 29],
141
+ [19, :group, :close, ')', 29, 30],
142
+ [20, :literal, :literal, ' h', 30, 32],
143
+ [21, :group, :close, ')', 32, 33],
144
+ [22, :literal, :literal, 'i j', 33, 36],
145
+ [23, :group, :close, ')', 36, 37]
146
+ ].each do |index, type, token, text, ts, te|
147
+ result = tokens[index]
148
+
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]
130
154
  end
131
155
  end
132
156
 
@@ -3,7 +3,7 @@ require File.expand_path("../../helpers", __FILE__)
3
3
  class ScannerGroups < Test::Unit::TestCase
4
4
 
5
5
  tests = {
6
- ## Options
6
+ # Options
7
7
  '(?-mix:abc)' => [0, :group, :options, '(?-mix:', 0, 7],
8
8
  '(?m-ix:abc)' => [0, :group, :options, '(?m-ix:', 0, 7],
9
9
  '(?mi-x:abc)' => [0, :group, :options, '(?mi-x:', 0, 7],
@@ -38,39 +38,34 @@ class ScannerGroups < Test::Unit::TestCase
38
38
  '(?<!abc)' => [0, :assertion, :nlookbehind, '(?<!', 0, 4],
39
39
  }
40
40
 
41
- count = 0
42
- tests.each do |pattern, test|
43
- define_method "test_scan_#{test[1]}_#{test[2]}_#{count+=1}" do
44
-
45
- tokens = RS.scan(pattern)
46
- assert_equal( test[1,5], tokens[test[0]])
47
- assert_equal( test[3], pattern[tokens[test[0]][3], tokens[test[0]][4]])
48
-
49
- end
50
- end
51
-
52
41
  if RUBY_VERSION >= '2.0'
53
- option_tests = {
54
- '(?m-dau:abc)' => [0, :group, :options, '(?m-dau:', 0, 8],
55
- '(?x-dmu:abc)' => [0, :group, :options, '(?x-dmu:', 0, 8],
56
- '(?-dau:abc)' => [0, :group, :options, '(?-dau:', 0, 7],
57
- '(?d-au:abc)' => [0, :group, :options, '(?d-au:', 0, 7],
58
- '(?da-u:abc)' => [0, :group, :options, '(?da-u:', 0, 7],
59
- '(?dau:abc)' => [0, :group, :options, '(?dau:', 0, 6],
60
- '(?dau)' => [0, :group, :options, '(?dau', 0, 5],
61
- '(?d:)' => [0, :group, :options, '(?d:', 0, 4],
62
- '(?a:)' => [0, :group, :options, '(?a:', 0, 4],
63
- '(?u:)' => [0, :group, :options, '(?u:', 0, 4],
64
- }
65
-
66
- tests.each do |pattern, test|
67
- define_method "test_scan_#{test[1]}_#{test[2]}_#{count+=1}" do
68
-
69
- tokens = RS.scan(pattern)
70
- assert_equal( test[1,5], tokens[test[0]])
71
- assert_equal( test[3], pattern[tokens[test[0]][3], tokens[test[0]][4]])
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
+ '(?dau)' => [0, :group, :options, '(?dau', 0, 5],
52
+ '(?d:)' => [0, :group, :options, '(?d:', 0, 4],
53
+ '(?a:)' => [0, :group, :options, '(?a:', 0, 4],
54
+ '(?u:)' => [0, :group, :options, '(?u:', 0, 4],
55
+ })
56
+ end
72
57
 
73
- end
58
+ tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
59
+ define_method "test_scanner_#{type}_#{token}_#{count}" do
60
+ tokens = RS.scan(pattern)
61
+ result = tokens[index]
62
+
63
+ assert_equal type, result[0]
64
+ assert_equal token, result[1]
65
+ assert_equal text, result[2]
66
+ assert_equal ts, result[3]
67
+ assert_equal te, result[4]
68
+ assert_equal text, pattern[ts, te]
74
69
  end
75
70
  end
76
71
 
@@ -3,31 +3,33 @@ require File.expand_path("../../helpers", __FILE__)
3
3
  class ScannerKeep < Test::Unit::TestCase
4
4
 
5
5
  def test_scan_keep_token
6
- regexp = /ab\Kcd/
7
- tokens = RS.scan(regexp)
8
-
9
- assert_equal( :keep, tokens[1][0] )
10
- assert_equal( :mark, tokens[1][1] )
11
- assert_equal( '\\K', tokens[1][2] )
12
- assert_equal( 2, tokens[1][3] )
13
- assert_equal( 4, tokens[1][4] )
6
+ tokens = RS.scan(/ab\Kcd/)
7
+ result = tokens.at(1)
8
+
9
+ assert_equal :keep, result[0]
10
+ assert_equal :mark, result[1]
11
+ assert_equal '\\K', result[2]
12
+ assert_equal 2, result[3]
13
+ assert_equal 4, result[4]
14
14
  end
15
15
 
16
16
  def test_scan_keep_nested
17
- regexp = /(a\Kb)|(c\\\Kd)ef/
18
- tokens = RS.scan(regexp)
19
-
20
- assert_equal( :keep, tokens[2][0] )
21
- assert_equal( :mark, tokens[2][1] )
22
- assert_equal( '\\K', tokens[2][2] )
23
- assert_equal( 2, tokens[2][3] )
24
- assert_equal( 4, tokens[2][4] )
25
-
26
- assert_equal( :keep, tokens[9][0] )
27
- assert_equal( :mark, tokens[9][1] )
28
- assert_equal( '\\K', tokens[9][2] )
29
- assert_equal( 11, tokens[9][3] )
30
- assert_equal( 13, tokens[9][4] )
17
+ tokens = RS.scan(/(a\Kb)|(c\\\Kd)ef/)
18
+
19
+ first = tokens.at(2)
20
+ second = tokens.at(9)
21
+
22
+ assert_equal :keep, first[0]
23
+ assert_equal :mark, first[1]
24
+ assert_equal '\\K', first[2]
25
+ assert_equal 2, first[3]
26
+ assert_equal 4, first[4]
27
+
28
+ assert_equal :keep, second[0]
29
+ assert_equal :mark, second[1]
30
+ assert_equal '\\K', second[2]
31
+ assert_equal 11, second[3]
32
+ assert_equal 13, second[4]
31
33
  end
32
34
 
33
35
  end