regexp_parser 1.3.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +72 -1
  3. data/Gemfile +3 -3
  4. data/README.md +12 -19
  5. data/Rakefile +3 -4
  6. data/lib/regexp_parser/expression.rb +28 -53
  7. data/lib/regexp_parser/expression/classes/backref.rb +18 -10
  8. data/lib/regexp_parser/expression/classes/conditional.rb +7 -2
  9. data/lib/regexp_parser/expression/classes/escape.rb +0 -4
  10. data/lib/regexp_parser/expression/classes/group.rb +4 -2
  11. data/lib/regexp_parser/expression/classes/keep.rb +1 -3
  12. data/lib/regexp_parser/expression/methods/match.rb +13 -0
  13. data/lib/regexp_parser/expression/methods/match_length.rb +172 -0
  14. data/lib/regexp_parser/expression/methods/options.rb +35 -0
  15. data/lib/regexp_parser/expression/methods/strfregexp.rb +0 -1
  16. data/lib/regexp_parser/expression/methods/tests.rb +6 -15
  17. data/lib/regexp_parser/expression/methods/traverse.rb +3 -1
  18. data/lib/regexp_parser/expression/quantifier.rb +2 -2
  19. data/lib/regexp_parser/expression/sequence.rb +3 -6
  20. data/lib/regexp_parser/expression/sequence_operation.rb +2 -6
  21. data/lib/regexp_parser/expression/subexpression.rb +3 -5
  22. data/lib/regexp_parser/lexer.rb +30 -44
  23. data/lib/regexp_parser/parser.rb +47 -24
  24. data/lib/regexp_parser/scanner.rb +1228 -1367
  25. data/lib/regexp_parser/scanner/char_type.rl +0 -3
  26. data/lib/regexp_parser/scanner/properties/long.yml +34 -1
  27. data/lib/regexp_parser/scanner/properties/short.yml +12 -0
  28. data/lib/regexp_parser/scanner/scanner.rl +101 -194
  29. data/lib/regexp_parser/syntax/tokens.rb +2 -10
  30. data/lib/regexp_parser/syntax/tokens/unicode_property.rb +72 -21
  31. data/lib/regexp_parser/syntax/versions/2.6.0.rb +10 -0
  32. data/lib/regexp_parser/syntax/versions/2.6.2.rb +10 -0
  33. data/lib/regexp_parser/syntax/versions/2.6.3.rb +10 -0
  34. data/lib/regexp_parser/version.rb +1 -1
  35. data/regexp_parser.gemspec +3 -3
  36. data/spec/expression/base_spec.rb +94 -0
  37. data/spec/expression/clone_spec.rb +120 -0
  38. data/spec/expression/conditional_spec.rb +89 -0
  39. data/spec/expression/free_space_spec.rb +27 -0
  40. data/spec/expression/methods/match_length_spec.rb +161 -0
  41. data/spec/expression/methods/match_spec.rb +25 -0
  42. data/spec/expression/methods/strfregexp_spec.rb +224 -0
  43. data/spec/expression/methods/tests_spec.rb +99 -0
  44. data/spec/expression/methods/traverse_spec.rb +161 -0
  45. data/spec/expression/options_spec.rb +128 -0
  46. data/spec/expression/root_spec.rb +9 -0
  47. data/spec/expression/sequence_spec.rb +9 -0
  48. data/spec/expression/subexpression_spec.rb +50 -0
  49. data/spec/expression/to_h_spec.rb +26 -0
  50. data/spec/expression/to_s_spec.rb +100 -0
  51. data/spec/lexer/all_spec.rb +22 -0
  52. data/spec/lexer/conditionals_spec.rb +53 -0
  53. data/spec/lexer/delimiters_spec.rb +68 -0
  54. data/spec/lexer/escapes_spec.rb +14 -0
  55. data/spec/lexer/keep_spec.rb +10 -0
  56. data/spec/lexer/literals_spec.rb +89 -0
  57. data/spec/lexer/nesting_spec.rb +99 -0
  58. data/spec/lexer/refcalls_spec.rb +55 -0
  59. data/spec/parser/all_spec.rb +43 -0
  60. data/spec/parser/alternation_spec.rb +88 -0
  61. data/spec/parser/anchors_spec.rb +17 -0
  62. data/spec/parser/conditionals_spec.rb +179 -0
  63. data/spec/parser/errors_spec.rb +30 -0
  64. data/spec/parser/escapes_spec.rb +121 -0
  65. data/spec/parser/free_space_spec.rb +130 -0
  66. data/spec/parser/groups_spec.rb +108 -0
  67. data/spec/parser/keep_spec.rb +6 -0
  68. data/spec/parser/posix_classes_spec.rb +8 -0
  69. data/spec/parser/properties_spec.rb +115 -0
  70. data/spec/parser/quantifiers_spec.rb +52 -0
  71. data/spec/parser/refcalls_spec.rb +112 -0
  72. data/spec/parser/set/intersections_spec.rb +127 -0
  73. data/spec/parser/set/ranges_spec.rb +111 -0
  74. data/spec/parser/sets_spec.rb +178 -0
  75. data/spec/parser/types_spec.rb +18 -0
  76. data/spec/scanner/all_spec.rb +18 -0
  77. data/spec/scanner/anchors_spec.rb +21 -0
  78. data/spec/scanner/conditionals_spec.rb +128 -0
  79. data/spec/scanner/delimiters_spec.rb +52 -0
  80. data/spec/scanner/errors_spec.rb +67 -0
  81. data/spec/scanner/escapes_spec.rb +53 -0
  82. data/spec/scanner/free_space_spec.rb +133 -0
  83. data/spec/scanner/groups_spec.rb +52 -0
  84. data/spec/scanner/keep_spec.rb +10 -0
  85. data/spec/scanner/literals_spec.rb +49 -0
  86. data/spec/scanner/meta_spec.rb +18 -0
  87. data/spec/scanner/properties_spec.rb +64 -0
  88. data/spec/scanner/quantifiers_spec.rb +20 -0
  89. data/spec/scanner/refcalls_spec.rb +36 -0
  90. data/spec/scanner/sets_spec.rb +102 -0
  91. data/spec/scanner/types_spec.rb +14 -0
  92. data/spec/spec_helper.rb +15 -0
  93. data/{test → spec}/support/runner.rb +9 -8
  94. data/spec/support/shared_examples.rb +77 -0
  95. data/{test → spec}/support/warning_extractor.rb +5 -7
  96. data/spec/syntax/syntax_spec.rb +48 -0
  97. data/spec/syntax/syntax_token_map_spec.rb +23 -0
  98. data/spec/syntax/versions/1.8.6_spec.rb +17 -0
  99. data/spec/syntax/versions/1.9.1_spec.rb +10 -0
  100. data/spec/syntax/versions/1.9.3_spec.rb +9 -0
  101. data/spec/syntax/versions/2.0.0_spec.rb +13 -0
  102. data/spec/syntax/versions/2.2.0_spec.rb +9 -0
  103. data/spec/syntax/versions/aliases_spec.rb +37 -0
  104. data/spec/token/token_spec.rb +85 -0
  105. metadata +151 -146
  106. data/test/expression/test_all.rb +0 -12
  107. data/test/expression/test_base.rb +0 -90
  108. data/test/expression/test_clone.rb +0 -89
  109. data/test/expression/test_conditionals.rb +0 -113
  110. data/test/expression/test_free_space.rb +0 -35
  111. data/test/expression/test_set.rb +0 -84
  112. data/test/expression/test_strfregexp.rb +0 -230
  113. data/test/expression/test_subexpression.rb +0 -58
  114. data/test/expression/test_tests.rb +0 -99
  115. data/test/expression/test_to_h.rb +0 -59
  116. data/test/expression/test_to_s.rb +0 -104
  117. data/test/expression/test_traverse.rb +0 -161
  118. data/test/helpers.rb +0 -10
  119. data/test/lexer/test_all.rb +0 -41
  120. data/test/lexer/test_conditionals.rb +0 -127
  121. data/test/lexer/test_keep.rb +0 -24
  122. data/test/lexer/test_literals.rb +0 -130
  123. data/test/lexer/test_nesting.rb +0 -132
  124. data/test/lexer/test_refcalls.rb +0 -56
  125. data/test/parser/set/test_intersections.rb +0 -127
  126. data/test/parser/set/test_ranges.rb +0 -111
  127. data/test/parser/test_all.rb +0 -64
  128. data/test/parser/test_alternation.rb +0 -92
  129. data/test/parser/test_anchors.rb +0 -34
  130. data/test/parser/test_conditionals.rb +0 -187
  131. data/test/parser/test_errors.rb +0 -63
  132. data/test/parser/test_escapes.rb +0 -134
  133. data/test/parser/test_free_space.rb +0 -139
  134. data/test/parser/test_groups.rb +0 -289
  135. data/test/parser/test_keep.rb +0 -21
  136. data/test/parser/test_posix_classes.rb +0 -27
  137. data/test/parser/test_properties.rb +0 -133
  138. data/test/parser/test_quantifiers.rb +0 -301
  139. data/test/parser/test_refcalls.rb +0 -186
  140. data/test/parser/test_sets.rb +0 -179
  141. data/test/parser/test_types.rb +0 -50
  142. data/test/scanner/test_all.rb +0 -38
  143. data/test/scanner/test_anchors.rb +0 -38
  144. data/test/scanner/test_conditionals.rb +0 -184
  145. data/test/scanner/test_errors.rb +0 -91
  146. data/test/scanner/test_escapes.rb +0 -56
  147. data/test/scanner/test_free_space.rb +0 -200
  148. data/test/scanner/test_groups.rb +0 -79
  149. data/test/scanner/test_keep.rb +0 -35
  150. data/test/scanner/test_literals.rb +0 -89
  151. data/test/scanner/test_meta.rb +0 -40
  152. data/test/scanner/test_properties.rb +0 -312
  153. data/test/scanner/test_quantifiers.rb +0 -37
  154. data/test/scanner/test_refcalls.rb +0 -52
  155. data/test/scanner/test_scripts.rb +0 -53
  156. data/test/scanner/test_sets.rb +0 -119
  157. data/test/scanner/test_types.rb +0 -35
  158. data/test/scanner/test_unicode_blocks.rb +0 -30
  159. data/test/support/disable_autotest.rb +0 -8
  160. data/test/syntax/test_all.rb +0 -6
  161. data/test/syntax/test_syntax.rb +0 -61
  162. data/test/syntax/test_syntax_token_map.rb +0 -25
  163. data/test/syntax/versions/test_1.8.rb +0 -55
  164. data/test/syntax/versions/test_1.9.1.rb +0 -36
  165. data/test/syntax/versions/test_1.9.3.rb +0 -32
  166. data/test/syntax/versions/test_2.0.0.rb +0 -37
  167. data/test/syntax/versions/test_2.2.0.rb +0 -32
  168. data/test/syntax/versions/test_aliases.rb +0 -129
  169. data/test/syntax/versions/test_all.rb +0 -5
  170. data/test/test_all.rb +0 -5
  171. data/test/token/test_all.rb +0 -2
  172. data/test/token/test_token.rb +0 -107
@@ -1,301 +0,0 @@
1
- require File.expand_path("../../helpers", __FILE__)
2
-
3
- class TestRegexpParserQuantifiers < Test::Unit::TestCase
4
-
5
- # ?: zero-or-one
6
- def test_parse_zero_or_one_greedy
7
- root = RP.parse('a?bc')
8
- exp = root.expressions.first
9
-
10
- assert_equal true, exp.quantified?
11
- assert_equal :zero_or_one, exp.quantifier.token
12
- assert_equal 0, exp.quantifier.min
13
- assert_equal 1, exp.quantifier.max
14
- assert_equal :greedy, exp.quantifier.mode
15
- assert_equal true, exp.quantifier.greedy?
16
- assert_equal true, exp.greedy?
17
-
18
- assert_equal false, exp.quantifier.reluctant?
19
- assert_equal false, exp.reluctant?
20
- assert_equal false, exp.quantifier.possessive?
21
- assert_equal false, exp.possessive?
22
- end
23
-
24
- def test_parse_zero_or_one_reluctant
25
- root = RP.parse('a??bc')
26
- exp = root.expressions.first
27
-
28
- assert_equal true, exp.quantified?
29
- assert_equal :zero_or_one, exp.quantifier.token
30
- assert_equal 0, exp.quantifier.min
31
- assert_equal 1, exp.quantifier.max
32
- assert_equal :reluctant, exp.quantifier.mode
33
- assert_equal true, exp.quantifier.reluctant?
34
- assert_equal true, exp.reluctant?
35
-
36
- assert_equal false, exp.quantifier.greedy?
37
- assert_equal false, exp.greedy?
38
- assert_equal false, exp.quantifier.possessive?
39
- assert_equal false, exp.possessive?
40
- end
41
-
42
- def test_parse_zero_or_one_possessive
43
- root = RP.parse('a?+bc', 'ruby/1.9')
44
- exp = root.expressions.first
45
-
46
- assert_equal true, exp.quantified?
47
- assert_equal :zero_or_one, exp.quantifier.token
48
- assert_equal 0, exp.quantifier.min
49
- assert_equal 1, exp.quantifier.max
50
- assert_equal :possessive, exp.quantifier.mode
51
- assert_equal true, exp.quantifier.possessive?
52
- assert_equal true, exp.possessive?
53
-
54
- assert_equal false, exp.quantifier.greedy?
55
- assert_equal false, exp.greedy?
56
- assert_equal false, exp.quantifier.reluctant?
57
- assert_equal false, exp.reluctant?
58
- end
59
-
60
- # *: zero-or-more
61
- def test_parse_zero_or_more_greedy
62
- root = RP.parse('a*bc')
63
- exp = root.expressions.first
64
-
65
- assert_equal true, exp.quantified?
66
- assert_equal :zero_or_more, exp.quantifier.token
67
- assert_equal 0, exp.quantifier.min
68
- assert_equal(-1, exp.quantifier.max)
69
- assert_equal :greedy, exp.quantifier.mode
70
- assert_equal true, exp.quantifier.greedy?
71
- assert_equal true, exp.greedy?
72
- end
73
-
74
- def test_parse_zero_or_more_reluctant
75
- root = RP.parse('a*?bc')
76
- exp = root.expressions.first
77
-
78
- assert_equal true, exp.quantified?
79
- assert_equal :zero_or_more, exp.quantifier.token
80
- assert_equal 0, exp.quantifier.min
81
- assert_equal(-1, exp.quantifier.max)
82
- assert_equal :reluctant, exp.quantifier.mode
83
- assert_equal true, exp.quantifier.reluctant?
84
- assert_equal true, exp.reluctant?
85
- end
86
-
87
- def test_parse_zero_or_more_possessive
88
- root = RP.parse('a*+bc', 'ruby/1.9')
89
- exp = root.expressions.first
90
-
91
- assert_equal true, exp.quantified?
92
- assert_equal :zero_or_more, exp.quantifier.token
93
- assert_equal 0, exp.quantifier.min
94
- assert_equal(-1, exp.quantifier.max)
95
- assert_equal :possessive, exp.quantifier.mode
96
- assert_equal true, exp.quantifier.possessive?
97
- assert_equal true, exp.possessive?
98
- end
99
-
100
- # +: one-or-more
101
- def test_parse_one_or_more_greedy
102
- root = RP.parse('a+bc')
103
- exp = root.expressions.first
104
-
105
- assert_equal true, exp.quantified?
106
- assert_equal :one_or_more, exp.quantifier.token
107
- assert_equal 1, exp.quantifier.min
108
- assert_equal(-1, exp.quantifier.max)
109
- assert_equal :greedy, exp.quantifier.mode
110
- assert_equal true, exp.quantifier.greedy?
111
- assert_equal true, exp.greedy?
112
- end
113
-
114
- def test_parse_one_or_more_reluctant
115
- root = RP.parse('a+?bc')
116
- exp = root.expressions.first
117
-
118
- assert_equal true, exp.quantified?
119
- assert_equal :one_or_more, exp.quantifier.token
120
- assert_equal 1, exp.quantifier.min
121
- assert_equal(-1, exp.quantifier.max)
122
- assert_equal :reluctant, exp.quantifier.mode
123
- assert_equal true, exp.quantifier.reluctant?
124
- assert_equal true, exp.reluctant?
125
- end
126
-
127
- def test_parse_one_or_more_possessive
128
- root = RP.parse('a++bc', 'ruby/1.9')
129
- exp = root.expressions.first
130
-
131
- assert_equal true, exp.quantified?
132
- assert_equal :one_or_more, exp.quantifier.token
133
- assert_equal 1, exp.quantifier.min
134
- assert_equal(-1, exp.quantifier.max)
135
- assert_equal :possessive, exp.quantifier.mode
136
- assert_equal true, exp.quantifier.possessive?
137
- assert_equal true, exp.possessive?
138
- end
139
-
140
- # interval: min and max
141
- def test_parse_intervals_min_max_greedy
142
- root = RP.parse('a{2,4}bc')
143
- exp = root.expressions.first
144
-
145
- assert_equal true, exp.quantified?
146
- assert_equal :interval, exp.quantifier.token
147
- assert_equal 2, exp.quantifier.min
148
- assert_equal 4, exp.quantifier.max
149
- assert_equal :greedy, exp.quantifier.mode
150
- assert_equal true, exp.quantifier.greedy?
151
- assert_equal true, exp.greedy?
152
- end
153
-
154
- def test_parse_intervals_min_max_reluctant
155
- root = RP.parse('a{3,5}?bc')
156
- exp = root.expressions.first
157
-
158
- assert_equal true, exp.quantified?
159
- assert_equal :interval, exp.quantifier.token
160
- assert_equal 3, exp.quantifier.min
161
- assert_equal 5, exp.quantifier.max
162
- assert_equal :reluctant, exp.quantifier.mode
163
- assert_equal true, exp.quantifier.reluctant?
164
- assert_equal true, exp.reluctant?
165
- end
166
-
167
- def test_parse_intervals_min_max_possessive
168
- root = RP.parse('a{2,4}+bc', 'ruby/1.9')
169
- exp = root.expressions.first
170
-
171
- assert_equal true, exp.quantified?
172
- assert_equal :interval, exp.quantifier.token
173
- assert_equal 2, exp.quantifier.min
174
- assert_equal 4, exp.quantifier.max
175
- assert_equal :possessive, exp.quantifier.mode
176
- assert_equal true, exp.quantifier.possessive?
177
- assert_equal true, exp.possessive?
178
- end
179
-
180
- # interval: min only
181
- def test_parse_intervals_min_only_greedy
182
- root = RP.parse('a{2,}bc')
183
- exp = root.expressions.first
184
-
185
- assert_equal true, exp.quantified?
186
- assert_equal :interval, exp.quantifier.token
187
- assert_equal 2, exp.quantifier.min
188
- assert_equal(-1, exp.quantifier.max)
189
- assert_equal :greedy, exp.quantifier.mode
190
- assert_equal true, exp.quantifier.greedy?
191
- assert_equal true, exp.greedy?
192
- end
193
-
194
- def test_parse_intervals_min_only_reluctant
195
- root = RP.parse('a{2,}?bc')
196
- exp = root.expressions.first
197
-
198
- assert_equal true, exp.quantified?
199
- assert_equal :interval, exp.quantifier.token
200
- assert_equal '{2,}?', exp.quantifier.text
201
- assert_equal 2, exp.quantifier.min
202
- assert_equal(-1, exp.quantifier.max)
203
- assert_equal :reluctant, exp.quantifier.mode
204
- assert_equal true, exp.quantifier.reluctant?
205
- assert_equal true, exp.reluctant?
206
- end
207
-
208
- def test_parse_intervals_min_only_possessive
209
- root = RP.parse('a{3,}+bc', 'ruby/1.9')
210
- exp = root.expressions.first
211
-
212
- assert_equal true, exp.quantified?
213
- assert_equal :interval, exp.quantifier.token
214
- assert_equal '{3,}+', exp.quantifier.text
215
- assert_equal 3, exp.quantifier.min
216
- assert_equal(-1, exp.quantifier.max)
217
- assert_equal :possessive, exp.quantifier.mode
218
- assert_equal true, exp.quantifier.possessive?
219
- assert_equal true, exp.possessive?
220
- end
221
-
222
- # interval: max only
223
- def test_parse_intervals_max_only_greedy
224
- root = RP.parse('a{,2}bc')
225
- exp = root.expressions.first
226
-
227
- assert_equal true, exp.quantified?
228
- assert_equal :interval, exp.quantifier.token
229
- assert_equal 0, exp.quantifier.min
230
- assert_equal 2, exp.quantifier.max
231
- assert_equal :greedy, exp.quantifier.mode
232
- assert_equal true, exp.quantifier.greedy?
233
- assert_equal true, exp.greedy?
234
- end
235
-
236
- def test_parse_intervals_max_only_reluctant
237
- root = RP.parse('a{,4}?bc')
238
- exp = root.expressions.first
239
-
240
- assert_equal true, exp.quantified?
241
- assert_equal :interval, exp.quantifier.token
242
- assert_equal 0, exp.quantifier.min
243
- assert_equal 4, exp.quantifier.max
244
- assert_equal :reluctant, exp.quantifier.mode
245
- assert_equal true, exp.quantifier.reluctant?
246
- assert_equal true, exp.reluctant?
247
- end
248
-
249
- def test_parse_intervals_max_only_possessive
250
- root = RP.parse('a{,3}+bc', 'ruby/1.9')
251
- exp = root.expressions.first
252
-
253
- assert_equal true, exp.quantified?
254
- assert_equal :interval, exp.quantifier.token
255
- assert_equal 0, exp.quantifier.min
256
- assert_equal 3, exp.quantifier.max
257
- assert_equal :possessive, exp.quantifier.mode
258
- assert_equal true, exp.quantifier.possessive?
259
- assert_equal true, exp.possessive?
260
- end
261
-
262
- # interval: exact
263
- def test_parse_intervals_exact_greedy
264
- root = RP.parse('a{2}bc')
265
- exp = root.expressions.first
266
-
267
- assert_equal true, exp.quantified?
268
- assert_equal :interval, exp.quantifier.token
269
- assert_equal 2, exp.quantifier.min
270
- assert_equal 2, exp.quantifier.max
271
- assert_equal :greedy, exp.quantifier.mode
272
- assert_equal true, exp.quantifier.greedy?
273
- assert_equal true, exp.greedy?
274
- end
275
-
276
- def test_parse_intervals_exact_reluctant
277
- root = RP.parse('a{3}?bc')
278
- exp = root.expressions.first
279
-
280
- assert_equal true, exp.quantified?
281
- assert_equal :interval, exp.quantifier.token
282
- assert_equal 3, exp.quantifier.min
283
- assert_equal 3, exp.quantifier.max
284
- assert_equal :reluctant, exp.quantifier.mode
285
- assert_equal true, exp.quantifier.reluctant?
286
- assert_equal true, exp.reluctant?
287
- end
288
-
289
- def test_parse_intervals_exact_possessive
290
- root = RP.parse('a{3}+bc', 'ruby/1.9')
291
- exp = root.expressions.first
292
-
293
- assert_equal true, exp.quantified?
294
- assert_equal :interval, exp.quantifier.token
295
- assert_equal 3, exp.quantifier.min
296
- assert_equal 3, exp.quantifier.max
297
- assert_equal :possessive, exp.quantifier.mode
298
- assert_equal true, exp.quantifier.possessive?
299
- assert_equal true, exp.possessive?
300
- end
301
- end
@@ -1,186 +0,0 @@
1
- require File.expand_path("../../helpers", __FILE__)
2
-
3
- class TestParserRefcalls < Test::Unit::TestCase
4
- def test_parse_traditional_number_backref
5
- root = RP.parse('(abc)\1', 'ruby/1.9')
6
- exp = root[1]
7
-
8
- assert_instance_of Backreference::Number, exp
9
- assert_equal 1, exp.number
10
- end
11
-
12
- def test_parse_backref_named_ab
13
- root = RP.parse('(?<X>abc)\k<X>', 'ruby/1.9')
14
- exp = root[1]
15
-
16
- assert_instance_of Backreference::Name, exp
17
- assert_equal 'X', exp.name
18
- end
19
-
20
- def test_parse_backref_named_sq
21
- root = RP.parse("(?<X>abc)\\k'X'", 'ruby/1.9')
22
- exp = root[1]
23
-
24
- assert_instance_of Backreference::Name, exp
25
- assert_equal 'X', exp.name
26
- end
27
-
28
- def test_parse_backref_number_ab
29
- root = RP.parse('(abc)\k<1>', 'ruby/1.9')
30
- exp = root[1]
31
-
32
- assert_instance_of Backreference::Number, exp
33
- assert_equal 1, exp.number
34
- end
35
-
36
- def test_parse_backref_number_sq
37
- root = RP.parse("(abc)\\k'1'", 'ruby/1.9')
38
- exp = root[1]
39
-
40
- assert_instance_of Backreference::Number, exp
41
- assert_equal 1, exp.number
42
- end
43
-
44
- def test_parse_backref_number_relative_ab
45
- root = RP.parse('(abc)\k<-1>', 'ruby/1.9')
46
- exp = root[1]
47
-
48
- assert_instance_of Backreference::NumberRelative, exp
49
- assert_equal(-1, exp.number)
50
- end
51
-
52
- def test_parse_backref_number_relative_sq
53
- root = RP.parse("(abc)\\k'-1'", 'ruby/1.9')
54
- exp = root[1]
55
-
56
- assert_instance_of Backreference::NumberRelative, exp
57
- assert_equal(-1, exp.number)
58
- end
59
-
60
- def test_parse_backref_name_call_ab
61
- root = RP.parse('(?<X>abc)\g<X>', 'ruby/1.9')
62
- exp = root[1]
63
-
64
- assert_instance_of Backreference::NameCall, exp
65
- assert_equal 'X', exp.name
66
- end
67
-
68
- def test_parse_backref_name_call_sq
69
- root = RP.parse("(?<X>abc)\\g'X'", 'ruby/1.9')
70
- exp = root[1]
71
-
72
- assert_instance_of Backreference::NameCall, exp
73
- assert_equal 'X', exp.name
74
- end
75
-
76
- def test_parse_backref_number_call_ab
77
- root = RP.parse('(abc)\g<1>', 'ruby/1.9')
78
- exp = root[1]
79
-
80
- assert_instance_of Backreference::NumberCall, exp
81
- assert_equal 1, exp.number
82
- end
83
-
84
- def test_parse_backref_number_call_sq
85
- root = RP.parse("(abc)\\g'1'", 'ruby/1.9')
86
- exp = root[1]
87
-
88
- assert_instance_of Backreference::NumberCall, exp
89
- assert_equal 1, exp.number
90
- end
91
-
92
- def test_parse_backref_number_relative_call_ab
93
- root = RP.parse('(abc)\g<-1>', 'ruby/1.9')
94
- exp = root[1]
95
-
96
- assert_instance_of Backreference::NumberCallRelative, exp
97
- assert_equal(-1, exp.number)
98
- end
99
-
100
- def test_parse_backref_number_relative_call_sq
101
- root = RP.parse("(abc)\\g'-1'", 'ruby/1.9')
102
- exp = root[1]
103
-
104
- assert_instance_of Backreference::NumberCallRelative, exp
105
- assert_equal(-1, exp.number)
106
- end
107
-
108
- def test_parse_backref_number_relative_forward_call_ab
109
- root = RP.parse('\g<+1>(abc)', 'ruby/1.9')
110
- exp = root[0]
111
-
112
- assert_instance_of Backreference::NumberCallRelative, exp
113
- assert_equal 1, exp.number
114
- end
115
-
116
- def test_parse_backref_number_relative_forward_call_sq
117
- root = RP.parse("\\g'+1'(abc)", 'ruby/1.9')
118
- exp = root[0]
119
-
120
- assert_instance_of Backreference::NumberCallRelative, exp
121
- assert_equal 1, exp.number
122
- end
123
-
124
- def test_parse_backref_name_recursion_level_ab
125
- root = RP.parse('(?<X>abc)\k<X-0>', 'ruby/1.9')
126
- exp = root[1]
127
-
128
- assert_instance_of Backreference::NameRecursionLevel, exp
129
- assert_equal 'X', exp.name
130
- assert_equal 0, exp.recursion_level
131
- end
132
-
133
- def test_parse_backref_name_recursion_level_sq
134
- root = RP.parse("(?<X>abc)\\k'X-0'", 'ruby/1.9')
135
- exp = root[1]
136
-
137
- assert_instance_of Backreference::NameRecursionLevel, exp
138
- assert_equal 'X', exp.name
139
- assert_equal 0, exp.recursion_level
140
- end
141
-
142
- def test_parse_backref_number_recursion_level_ab
143
- root = RP.parse('(abc)\k<1-0>', 'ruby/1.9')
144
- exp = root[1]
145
-
146
- assert_instance_of Backreference::NumberRecursionLevel, exp
147
- assert_equal 1, exp.number
148
- assert_equal 0, exp.recursion_level
149
- end
150
-
151
- def test_parse_backref_number_recursion_level_sq
152
- root = RP.parse("(abc)\\k'1-0'", 'ruby/1.9')
153
- exp = root[1]
154
-
155
- assert_instance_of Backreference::NumberRecursionLevel, exp
156
- assert_equal 1, exp.number
157
- assert_equal 0, exp.recursion_level
158
- end
159
-
160
- def test_parse_backref_negative_number_recursion_level
161
- root = RP.parse("(abc)\\k'-1+0'", 'ruby/1.9')
162
- exp = root[1]
163
-
164
- assert_instance_of Backreference::NumberRecursionLevel, exp
165
- assert_equal(-1, exp.number)
166
- assert_equal 0, exp.recursion_level
167
- end
168
-
169
- def test_parse_backref_number_positive_recursion_level
170
- root = RP.parse("(abc)\\k'1+1'", 'ruby/1.9')
171
- exp = root[1]
172
-
173
- assert_instance_of Backreference::NumberRecursionLevel, exp
174
- assert_equal 1, exp.number
175
- assert_equal 1, exp.recursion_level
176
- end
177
-
178
- def test_parse_backref_number_negative_recursion_level
179
- root = RP.parse("(abc)\\k'1-1'", 'ruby/1.9')
180
- exp = root[1]
181
-
182
- assert_instance_of Backreference::NumberRecursionLevel, exp
183
- assert_equal 1, exp.number
184
- assert_equal(-1, exp.recursion_level)
185
- end
186
- end