regexp_parser 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -7,13 +7,13 @@ class ParserFreeSpace < Test::Unit::TestCase
7
7
  root = RP.parse(regexp)
8
8
 
9
9
  0.upto(6) do |i|
10
- if i%2 == 1
10
+ if i.odd?
11
11
  # Consecutive spaces get merged by the parser, thus the two spaces.
12
- assert_equal( WhiteSpace, root[i].class )
13
- assert_equal( ' ', root[i].text )
12
+ assert_equal WhiteSpace, root[i].class
13
+ assert_equal ' ', root[i].text
14
14
  else
15
- assert_equal( Literal, root[i].class )
16
- assert_equal( true, root[i].quantified? )
15
+ assert_equal Literal, root[i].class
16
+ assert_equal true, root[i].quantified?
17
17
  end
18
18
  end
19
19
  end
@@ -22,8 +22,8 @@ class ParserFreeSpace < Test::Unit::TestCase
22
22
  regexp = /a b c d/
23
23
  root = RP.parse(regexp)
24
24
 
25
- assert_equal( Literal, root.first.class )
26
- assert_equal( 'a b c d', root.first.text )
25
+ assert_equal Literal, root.first.class
26
+ assert_equal 'a b c d', root.first.text
27
27
  end
28
28
 
29
29
  def test_parse_free_space_comments
@@ -39,29 +39,29 @@ class ParserFreeSpace < Test::Unit::TestCase
39
39
  root = RP.parse(regexp)
40
40
 
41
41
  alt = root.first
42
- assert_equal( Alternation, alt.class )
42
+ assert_equal Alternation, alt.class
43
43
 
44
44
  alt_1 = alt.alternatives.first
45
- assert_equal( Alternative, alt_1.class )
46
- assert_equal( 15, alt_1.length )
45
+ assert_equal Alternative, alt_1.class
46
+ assert_equal 15, alt_1.length
47
47
 
48
48
  [0, 2, 4, 6, 8, 12, 14].each do |i|
49
- assert_equal( WhiteSpace, alt_1[i].class )
49
+ assert_equal WhiteSpace, alt_1[i].class
50
50
  end
51
51
 
52
52
  [3, 7, 11].each do |i|
53
- assert_equal( Comment, alt_1[i].class )
53
+ assert_equal Comment, alt_1[i].class
54
54
  end
55
55
 
56
56
  alt_2 = alt.alternatives.last
57
- assert_equal( Alternative, alt_2.class )
58
- assert_equal( 7, alt_2.length )
57
+ assert_equal Alternative, alt_2.class
58
+ assert_equal 7, alt_2.length
59
59
 
60
60
  [0, 2, 4, 6].each do |i|
61
- assert_equal( WhiteSpace, alt_2[i].class )
61
+ assert_equal WhiteSpace, alt_2[i].class
62
62
  end
63
63
 
64
- assert_equal( Comment, alt_2[1].class )
64
+ assert_equal Comment, alt_2[1].class
65
65
  end
66
66
 
67
67
  def test_parse_free_space_nested_comments
@@ -83,14 +83,14 @@ class ParserFreeSpace < Test::Unit::TestCase
83
83
  root = RP.parse(regexp)
84
84
 
85
85
  top_comment_1 = root[1]
86
- assert_equal( Comment, top_comment_1.class )
87
- assert_equal( "# Group one\n", top_comment_1.text )
88
- assert_equal( 7, top_comment_1.starts_at )
86
+ assert_equal Comment, top_comment_1.class
87
+ assert_equal "# Group one\n", top_comment_1.text
88
+ assert_equal 7, top_comment_1.starts_at
89
89
 
90
90
  top_comment_2 = root[5]
91
- assert_equal( Comment, top_comment_2.class )
92
- assert_equal( "# Group two\n", top_comment_2.text )
93
- assert_equal( 95, top_comment_2.starts_at )
91
+ assert_equal Comment, top_comment_2.class
92
+ assert_equal "# Group two\n", top_comment_2.text
93
+ assert_equal 95, top_comment_2.starts_at
94
94
 
95
95
  # Nested comments
96
96
  [3, 7].each_with_index do |g, i|
@@ -98,8 +98,8 @@ class ParserFreeSpace < Test::Unit::TestCase
98
98
 
99
99
  [3, 7].each do |c|
100
100
  comment = group[c]
101
- assert_equal( Comment, comment.class )
102
- assert_equal( 14, comment.text.length )
101
+ assert_equal Comment, comment.class
102
+ assert_equal 14, comment.text.length
103
103
  end
104
104
  end
105
105
  end
@@ -121,19 +121,19 @@ class ParserFreeSpace < Test::Unit::TestCase
121
121
  root = RP.parse(regexp)
122
122
 
123
123
  literal_1 = root[1]
124
- assert_equal( Literal, literal_1.class )
125
- assert_equal( true, literal_1.quantified? )
126
- assert_equal( :zero_or_one, literal_1.quantifier.token )
124
+ assert_equal Literal, literal_1.class
125
+ assert_equal true, literal_1.quantified?
126
+ assert_equal :zero_or_one, literal_1.quantifier.token
127
127
 
128
128
  group = root[5]
129
- assert_equal( Group::Capture, group.class )
130
- assert_equal( true, group.quantified? )
131
- assert_equal( :zero_or_more, group.quantifier.token )
129
+ assert_equal Group::Capture, group.class
130
+ assert_equal true, group.quantified?
131
+ assert_equal :zero_or_more, group.quantifier.token
132
132
 
133
133
  literal_2 = group[1]
134
- assert_equal( Literal, literal_2.class )
135
- assert_equal( true, literal_2.quantified? )
136
- assert_equal( :one_or_more, literal_2.quantifier.token )
134
+ assert_equal Literal, literal_2.class
135
+ assert_equal true, literal_2.quantified?
136
+ assert_equal :one_or_more, literal_2.quantifier.token
137
137
  end
138
138
 
139
139
  end
@@ -5,104 +5,104 @@ class TestParserGroups < Test::Unit::TestCase
5
5
  def test_parse_root_options_mi
6
6
  t = RP.parse((/[abc]/mi).to_s, 'ruby/1.8')
7
7
 
8
- assert_equal( true, t.m? )
9
- assert_equal( true, t.i? )
10
- assert_equal( false, t.x? )
8
+ assert_equal true, t.m?
9
+ assert_equal true, t.i?
10
+ assert_equal false, t.x?
11
11
  end
12
12
 
13
13
  def test_parse_nested_options_m
14
14
  t = RP.parse('(?xi-m:a(?m-ix:b))', 'ruby/1.8')
15
15
 
16
- assert_equal( true, t.expressions[0].expressions[1].m? )
17
- assert_equal( false, t.expressions[0].expressions[1].i? )
18
- assert_equal( false, t.expressions[0].expressions[1].x? )
16
+ assert_equal true, t.expressions[0].expressions[1].m?
17
+ assert_equal false, t.expressions[0].expressions[1].i?
18
+ assert_equal false, t.expressions[0].expressions[1].x?
19
19
  end
20
20
 
21
21
  def test_parse_nested_options_xm
22
22
  t = RP.parse(/(?i-xm:a(?mx-i:b))/, 'ruby/1.8')
23
23
 
24
- assert_equal( true, t.expressions[0].expressions[1].m? )
25
- assert_equal( false, t.expressions[0].expressions[1].i? )
26
- assert_equal( true, t.expressions[0].expressions[1].x? )
24
+ assert_equal true, t.expressions[0].expressions[1].m?
25
+ assert_equal false, t.expressions[0].expressions[1].i?
26
+ assert_equal true, t.expressions[0].expressions[1].x?
27
27
  end
28
28
 
29
29
  def test_parse_nested_options_im
30
30
  t = RP.parse(/(?x-mi:a(?mi-x:b))/, 'ruby/1.8')
31
31
 
32
- assert_equal( true, t.expressions[0].expressions[1].m? )
33
- assert_equal( true, t.expressions[0].expressions[1].i? )
34
- assert_equal( false, t.expressions[0].expressions[1].x? )
32
+ assert_equal true, t.expressions[0].expressions[1].m?
33
+ assert_equal true, t.expressions[0].expressions[1].i?
34
+ assert_equal false, t.expressions[0].expressions[1].x?
35
35
  end
36
36
 
37
37
  if RUBY_VERSION >= '2.0'
38
38
  def test_parse_options_dau
39
39
  t = RP.parse('(?dua:abc)')
40
40
 
41
- assert_equal( true, t.expressions[0].d? )
42
- assert_equal( true, t.expressions[0].a? )
43
- assert_equal( true, t.expressions[0].u? )
41
+ assert_equal true, t.expressions[0].d?
42
+ assert_equal true, t.expressions[0].a?
43
+ assert_equal true, t.expressions[0].u?
44
44
  end
45
45
 
46
46
  def test_parse_nested_options_dau
47
47
  t = RP.parse('(?u:a(?d:b))')
48
48
 
49
- assert_equal( true, t.expressions[0].u? )
50
- assert_equal( false, t.expressions[0].d? )
51
- assert_equal( false, t.expressions[0].a? )
49
+ assert_equal true, t.expressions[0].u?
50
+ assert_equal false, t.expressions[0].d?
51
+ assert_equal false, t.expressions[0].a?
52
52
 
53
- assert_equal( true, t.expressions[0].expressions[1].d? )
54
- assert_equal( false, t.expressions[0].expressions[1].a? )
55
- assert_equal( false, t.expressions[0].expressions[1].u? )
53
+ assert_equal true, t.expressions[0].expressions[1].d?
54
+ assert_equal false, t.expressions[0].expressions[1].a?
55
+ assert_equal false, t.expressions[0].expressions[1].u?
56
56
  end
57
57
 
58
58
  def test_parse_nested_options_da
59
59
  t = RP.parse('(?di-xm:a(?da-x:b))')
60
60
 
61
- assert_equal( true, t.expressions[0].d? )
62
- assert_equal( true, t.expressions[0].i? )
63
- assert_equal( false, t.expressions[0].m? )
64
- assert_equal( false, t.expressions[0].x? )
65
- assert_equal( false, t.expressions[0].a? )
66
- assert_equal( false, t.expressions[0].u? )
67
-
68
- assert_equal( true, t.expressions[0].expressions[1].d? )
69
- assert_equal( true, t.expressions[0].expressions[1].a? )
70
- assert_equal( false, t.expressions[0].expressions[1].u? )
71
- assert_equal( false, t.expressions[0].expressions[1].x? )
72
- assert_equal( false, t.expressions[0].expressions[1].m? )
73
- assert_equal( false, t.expressions[0].expressions[1].i? )
61
+ assert_equal true, t.expressions[0].d?
62
+ assert_equal true, t.expressions[0].i?
63
+ assert_equal false, t.expressions[0].m?
64
+ assert_equal false, t.expressions[0].x?
65
+ assert_equal false, t.expressions[0].a?
66
+ assert_equal false, t.expressions[0].u?
67
+
68
+ assert_equal true, t.expressions[0].expressions[1].d?
69
+ assert_equal true, t.expressions[0].expressions[1].a?
70
+ assert_equal false, t.expressions[0].expressions[1].u?
71
+ assert_equal false, t.expressions[0].expressions[1].x?
72
+ assert_equal false, t.expressions[0].expressions[1].m?
73
+ assert_equal false, t.expressions[0].expressions[1].i?
74
74
  end
75
75
  end
76
76
 
77
77
  def test_parse_lookahead
78
78
  t = RP.parse('(?=abc)(?!def)', 'ruby/1.8')
79
79
 
80
- assert( t.expressions[0].is_a?(Assertion::Lookahead),
81
- "Expected lookahead, but got #{t.expressions[0].class.name}")
80
+ assert t.expressions[0].is_a?(Assertion::Lookahead),
81
+ "Expected lookahead, but got #{t.expressions[0].class.name}"
82
82
 
83
- assert( t.expressions[1].is_a?(Assertion::NegativeLookahead),
84
- "Expected negative lookahead, but got #{t.expressions[0].class.name}")
83
+ assert t.expressions[1].is_a?(Assertion::NegativeLookahead),
84
+ "Expected negative lookahead, but got #{t.expressions[0].class.name}"
85
85
  end
86
86
 
87
87
  def test_parse_lookbehind
88
88
  t = RP.parse('(?<=abc)(?<!def)', 'ruby/1.9')
89
89
 
90
- assert( t.expressions[0].is_a?(Assertion::Lookbehind),
91
- "Expected lookbehind, but got #{t.expressions[0].class.name}")
90
+ assert t.expressions[0].is_a?(Assertion::Lookbehind),
91
+ "Expected lookbehind, but got #{t.expressions[0].class.name}"
92
92
 
93
- assert( t.expressions[1].is_a?(Assertion::NegativeLookbehind),
94
- "Expected negative lookbehind, but got #{t.expressions[0].class.name}")
93
+ assert t.expressions[1].is_a?(Assertion::NegativeLookbehind),
94
+ "Expected negative lookbehind, but got #{t.expressions[0].class.name}"
95
95
  end
96
96
 
97
97
  def test_parse_comment
98
98
  t = RP.parse('a(?# is for apple)b(?# for boy)c(?# cat)')
99
99
 
100
100
  [1,3,5].each do |i|
101
- assert( t.expressions[i].is_a?(Group::Comment),
102
- "Expected comment, but got #{t.expressions[i].class.name}")
101
+ assert t.expressions[i].is_a?(Group::Comment),
102
+ "Expected comment, but got #{t.expressions[i].class.name}"
103
103
 
104
- assert_equal( :group, t.expressions[i].type )
105
- assert_equal( :comment, t.expressions[i].token )
104
+ assert_equal :group, t.expressions[i].type
105
+ assert_equal :comment, t.expressions[i].token
106
106
  end
107
107
  end
108
108
 
@@ -6,16 +6,16 @@ class ParserKeep < Test::Unit::TestCase
6
6
  regexp = /ab\Kcd/
7
7
  root = RP.parse(regexp)
8
8
 
9
- assert_equal( Keep::Mark, root[1].class )
10
- assert_equal( '\\K', root[1].text )
9
+ assert_equal Keep::Mark, root[1].class
10
+ assert_equal '\\K', root[1].text
11
11
  end
12
12
 
13
13
  def test_parse_keep_nested
14
14
  regexp = /(a\\\Kb)/
15
15
  root = RP.parse(regexp)
16
16
 
17
- assert_equal( Keep::Mark, root[0][2].class )
18
- assert_equal( '\\K', root[0][2].text )
17
+ assert_equal Keep::Mark, root[0][2].class
18
+ assert_equal '\\K', root[0][2].text
19
19
  end
20
20
 
21
21
  end
@@ -297,57 +297,59 @@ class ParserProperties < Test::Unit::TestCase
297
297
  define_method "test_parse_#{token_type}_#{property}" do
298
298
  t = RP.parse "ab\\#{mode}{#{property}}", 'ruby/1.9'
299
299
 
300
- assert( t.expressions.last.is_a?(UnicodeProperty::Base),
301
- "Expected property, but got #{t.expressions.last.class.name}")
300
+ assert t.expressions.last.is_a?(UnicodeProperty::Base),
301
+ "Expected property, but got #{t.expressions.last.class.name}"
302
302
 
303
- assert_equal( token_type, t.expressions.last.type )
304
- assert_equal( property, t.expressions.last.name )
303
+ assert_equal token_type, t.expressions.last.type
304
+ assert_equal property, t.expressions.last.name
305
305
  end
306
306
  end
307
307
  end
308
308
 
309
309
  def test_parse_property_negative
310
310
  t = RP.parse 'ab\p{L}cd', 'ruby/1.9'
311
- assert_equal( false, t.expressions[1].negative? )
311
+
312
+ assert_equal false, t.expressions[1].negative?
312
313
  end
313
314
 
314
315
  def test_parse_nonproperty_negative
315
316
  t = RP.parse 'ab\P{L}cd', 'ruby/1.9'
316
- assert_equal( true, t.expressions[1].negative? )
317
+
318
+ assert_equal true, t.expressions[1].negative?
317
319
  end
318
320
 
319
321
  def test_parse_property_age
320
322
  t = RP.parse 'ab\p{age=5.2}cd', 'ruby/1.9'
321
323
 
322
- assert( t.expressions[1].is_a?(UnicodeProperty::Age),
323
- "Expected Age property, but got #{t.expressions[1].class.name}")
324
+ assert t.expressions[1].is_a?(UnicodeProperty::Age),
325
+ "Expected Age property, but got #{t.expressions[1].class.name}"
324
326
  end
325
327
 
326
328
  def test_parse_property_derived
327
329
  t = RP.parse 'ab\p{Math}cd', 'ruby/1.9'
328
330
 
329
- assert( t.expressions[1].is_a?(UnicodeProperty::Derived),
330
- "Expected Derived property, but got #{t.expressions[1].class.name}")
331
+ assert t.expressions[1].is_a?(UnicodeProperty::Derived),
332
+ "Expected Derived property, but got #{t.expressions[1].class.name}"
331
333
  end
332
334
 
333
335
  def test_parse_property_script
334
336
  t = RP.parse 'ab\p{Hiragana}cd', 'ruby/1.9'
335
337
 
336
- assert( t.expressions[1].is_a?(UnicodeProperty::Script),
337
- "Expected Script property, but got #{t.expressions[1].class.name}")
338
+ assert t.expressions[1].is_a?(UnicodeProperty::Script),
339
+ "Expected Script property, but got #{t.expressions[1].class.name}"
338
340
  end
339
341
 
340
342
  def test_parse_property_block
341
343
  t = RP.parse 'ab\p{InArmenian}cd', 'ruby/1.9'
342
344
 
343
- assert( t.expressions[1].is_a?(UnicodeProperty::Block),
344
- "Expected Block property, but got #{t.expressions[1].class.name}")
345
+ assert t.expressions[1].is_a?(UnicodeProperty::Block),
346
+ "Expected Block property, but got #{t.expressions[1].class.name}"
345
347
  end
346
348
 
347
349
  def test_parse_property_following_literal
348
350
  t = RP.parse 'ab\p{Lu}cd', 'ruby/1.9'
349
351
 
350
- assert( t.expressions[2].is_a?(Literal),
351
- "Expected Literal, but got #{t.expressions[2].class.name}")
352
+ assert t.expressions[2].is_a?(Literal),
353
+ "Expected Literal, but got #{t.expressions[2].class.name}"
352
354
  end
353
355
  end
@@ -4,235 +4,256 @@ class TestRegexpParserQuantifiers < Test::Unit::TestCase
4
4
 
5
5
  # ?: zero-or-one
6
6
  def test_parse_zero_or_one_greedy
7
- t = RP.parse('a?bc')
8
-
9
- assert_equal( true, t.expressions.first.quantified? )
10
- assert_equal( :zero_or_one, t.expressions.first.quantifier.token )
11
- assert_equal( 0, t.expressions.first.quantifier.min )
12
- assert_equal( 1, t.expressions.first.quantifier.max )
13
- assert_equal( :greedy, t.expressions.first.quantifier.mode )
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
14
15
  end
15
16
 
16
17
  def test_parse_zero_or_one_reluctant
17
- t = RP.parse('a??bc')
18
-
19
- assert_equal( true, t.expressions.first.quantified? )
20
- assert_equal( :zero_or_one, t.expressions.first.quantifier.token )
21
- assert_equal( 0, t.expressions.first.quantifier.min )
22
- assert_equal( 1, t.expressions.first.quantifier.max )
23
- assert_equal( :reluctant, t.expressions.first.quantifier.mode )
24
- assert_equal( true, t.expressions.first.reluctant? )
18
+ root = RP.parse('a??bc')
19
+ exp = root.expressions.first
20
+
21
+ assert_equal true, exp.quantified?
22
+ assert_equal :zero_or_one, exp.quantifier.token
23
+ assert_equal 0, exp.quantifier.min
24
+ assert_equal 1, exp.quantifier.max
25
+ assert_equal :reluctant, exp.quantifier.mode
26
+ assert_equal true, exp.reluctant?
25
27
  end
26
28
 
27
29
  def test_parse_zero_or_one_possessive
28
- t = RP.parse('a?+bc', 'ruby/1.9')
29
-
30
- assert_equal( true, t.expressions.first.quantified? )
31
- assert_equal( :zero_or_one, t.expressions.first.quantifier.token )
32
- assert_equal( 0, t.expressions.first.quantifier.min )
33
- assert_equal( 1, t.expressions.first.quantifier.max )
34
- assert_equal( :possessive, t.expressions.first.quantifier.mode )
35
- assert_equal( true, t.expressions.first.possessive? )
30
+ root = RP.parse('a?+bc', 'ruby/1.9')
31
+ exp = root.expressions.first
32
+
33
+ assert_equal true, exp.quantified?
34
+ assert_equal :zero_or_one, exp.quantifier.token
35
+ assert_equal 0, exp.quantifier.min
36
+ assert_equal 1, exp.quantifier.max
37
+ assert_equal :possessive, exp.quantifier.mode
38
+ assert_equal true, exp.possessive?
36
39
  end
37
40
 
38
41
  # *: zero-or-more
39
42
  def test_parse_zero_or_more_greedy
40
- t = RP.parse('a*bc')
41
-
42
- assert_equal( true, t.expressions.first.quantified? )
43
- assert_equal( :zero_or_more, t.expressions.first.quantifier.token )
44
- assert_equal( 0, t.expressions.first.quantifier.min )
45
- assert_equal( -1, t.expressions.first.quantifier.max )
46
- assert_equal( :greedy, t.expressions.first.quantifier.mode )
43
+ root = RP.parse('a*bc')
44
+ exp = root.expressions.first
45
+
46
+ assert_equal true, exp.quantified?
47
+ assert_equal :zero_or_more, exp.quantifier.token
48
+ assert_equal 0, exp.quantifier.min
49
+ assert_equal -1, exp.quantifier.max
50
+ assert_equal :greedy, exp.quantifier.mode
47
51
  end
48
52
 
49
53
  def test_parse_zero_or_more_reluctant
50
- t = RP.parse('a*?bc')
51
-
52
- assert_equal( true, t.expressions.first.quantified? )
53
- assert_equal( :zero_or_more, t.expressions.first.quantifier.token )
54
- assert_equal( 0, t.expressions.first.quantifier.min )
55
- assert_equal( -1, t.expressions.first.quantifier.max )
56
- assert_equal( :reluctant, t.expressions.first.quantifier.mode )
57
- assert_equal( true, t.expressions.first.reluctant? )
54
+ root = RP.parse('a*?bc')
55
+ exp = root.expressions.first
56
+
57
+ assert_equal true, exp.quantified?
58
+ assert_equal :zero_or_more, exp.quantifier.token
59
+ assert_equal 0, exp.quantifier.min
60
+ assert_equal -1, exp.quantifier.max
61
+ assert_equal :reluctant, exp.quantifier.mode
62
+ assert_equal true, exp.reluctant?
58
63
  end
59
64
 
60
65
  def test_parse_zero_or_more_possessive
61
- t = RP.parse('a*+bc', 'ruby/1.9')
62
-
63
- assert_equal( true, t.expressions.first.quantified? )
64
- assert_equal( :zero_or_more, t.expressions.first.quantifier.token )
65
- assert_equal( 0, t.expressions.first.quantifier.min )
66
- assert_equal( -1, t.expressions.first.quantifier.max )
67
- assert_equal( :possessive, t.expressions.first.quantifier.mode )
68
- assert_equal( true, t.expressions.first.possessive? )
66
+ root = RP.parse('a*+bc', 'ruby/1.9')
67
+ exp = root.expressions.first
68
+
69
+ assert_equal true, exp.quantified?
70
+ assert_equal :zero_or_more, exp.quantifier.token
71
+ assert_equal 0, exp.quantifier.min
72
+ assert_equal -1, exp.quantifier.max
73
+ assert_equal :possessive, exp.quantifier.mode
74
+ assert_equal true, exp.possessive?
69
75
  end
70
76
 
71
77
  # +: one-or-more
72
78
  def test_parse_one_or_more_greedy
73
- t = RP.parse('a+bc')
74
-
75
- assert_equal( true, t.expressions.first.quantified? )
76
- assert_equal( :one_or_more, t.expressions.first.quantifier.token )
77
- assert_equal( 1, t.expressions.first.quantifier.min )
78
- assert_equal( -1, t.expressions.first.quantifier.max )
79
- assert_equal( :greedy, t.expressions.first.quantifier.mode )
79
+ root = RP.parse('a+bc')
80
+ exp = root.expressions.first
81
+
82
+ assert_equal true, exp.quantified?
83
+ assert_equal :one_or_more, exp.quantifier.token
84
+ assert_equal 1, exp.quantifier.min
85
+ assert_equal -1, exp.quantifier.max
86
+ assert_equal :greedy, exp.quantifier.mode
80
87
  end
81
88
 
82
89
  def test_parse_one_or_more_reluctant
83
- t = RP.parse('a+?bc')
84
-
85
- assert_equal( true, t.expressions.first.quantified? )
86
- assert_equal( :one_or_more, t.expressions.first.quantifier.token )
87
- assert_equal( 1, t.expressions.first.quantifier.min )
88
- assert_equal( -1, t.expressions.first.quantifier.max )
89
- assert_equal( :reluctant, t.expressions.first.quantifier.mode )
90
- assert_equal( true, t.expressions.first.reluctant? )
90
+ root = RP.parse('a+?bc')
91
+ exp = root.expressions.first
92
+
93
+ assert_equal true, exp.quantified?
94
+ assert_equal :one_or_more, exp.quantifier.token
95
+ assert_equal 1, exp.quantifier.min
96
+ assert_equal -1, exp.quantifier.max
97
+ assert_equal :reluctant, exp.quantifier.mode
98
+ assert_equal true, exp.reluctant?
91
99
  end
92
100
 
93
101
  def test_parse_one_or_more_possessive
94
- t = RP.parse('a++bc', 'ruby/1.9')
95
-
96
- assert_equal( true, t.expressions.first.quantified? )
97
- assert_equal( :one_or_more, t.expressions.first.quantifier.token )
98
- assert_equal( 1, t.expressions.first.quantifier.min )
99
- assert_equal( -1, t.expressions.first.quantifier.max )
100
- assert_equal( :possessive, t.expressions.first.quantifier.mode )
101
- assert_equal( true, t.expressions.first.possessive? )
102
+ root = RP.parse('a++bc', 'ruby/1.9')
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 :possessive, exp.quantifier.mode
110
+ assert_equal true, exp.possessive?
102
111
  end
103
112
 
104
113
  # interval: min and max
105
114
  def test_parse_intervals_min_max_greedy
106
- t = RP.parse('a{2,4}bc')
107
-
108
- assert_equal( true, t.expressions.first.quantified? )
109
- assert_equal( :interval, t.expressions.first.quantifier.token )
110
- assert_equal( 2, t.expressions.first.quantifier.min)
111
- assert_equal( 4, t.expressions.first.quantifier.max)
112
- assert_equal( :greedy, t.expressions.first.quantifier.mode )
115
+ root = RP.parse('a{2,4}bc')
116
+ exp = root.expressions.first
117
+
118
+ assert_equal true, exp.quantified?
119
+ assert_equal :interval, exp.quantifier.token
120
+ assert_equal 2, exp.quantifier.min
121
+ assert_equal 4, exp.quantifier.max
122
+ assert_equal :greedy, exp.quantifier.mode
113
123
  end
114
124
 
115
125
  def test_parse_intervals_min_max_reluctant
116
- t = RP.parse('a{3,5}?bc')
117
-
118
- assert_equal( true, t.expressions.first.quantified? )
119
- assert_equal( :interval, t.expressions.first.quantifier.token )
120
- assert_equal( 3, t.expressions.first.quantifier.min)
121
- assert_equal( 5, t.expressions.first.quantifier.max)
122
- assert_equal( :reluctant, t.expressions.first.quantifier.mode )
123
- assert_equal( true, t.expressions.first.reluctant? )
126
+ root = RP.parse('a{3,5}?bc')
127
+ exp = root.expressions.first
128
+
129
+ assert_equal true, exp.quantified?
130
+ assert_equal :interval, exp.quantifier.token
131
+ assert_equal 3, exp.quantifier.min
132
+ assert_equal 5, exp.quantifier.max
133
+ assert_equal :reluctant, exp.quantifier.mode
134
+ assert_equal true, exp.reluctant?
124
135
  end
125
136
 
126
137
  def test_parse_intervals_min_max_possessive
127
- t = RP.parse('a{2,4}+bc', 'ruby/1.9')
128
-
129
- assert_equal( true, t.expressions.first.quantified? )
130
- assert_equal( :interval, t.expressions.first.quantifier.token )
131
- assert_equal( 2, t.expressions.first.quantifier.min)
132
- assert_equal( 4, t.expressions.first.quantifier.max)
133
- assert_equal( :possessive, t.expressions.first.quantifier.mode )
134
- assert_equal( true, t.expressions.first.possessive? )
138
+ root = RP.parse('a{2,4}+bc', 'ruby/1.9')
139
+ exp = root.expressions.first
140
+
141
+ assert_equal true, exp.quantified?
142
+ assert_equal :interval, exp.quantifier.token
143
+ assert_equal 2, exp.quantifier.min
144
+ assert_equal 4, exp.quantifier.max
145
+ assert_equal :possessive, exp.quantifier.mode
146
+ assert_equal true, exp.possessive?
135
147
  end
136
148
 
137
149
  # interval: min only
138
150
  def test_parse_intervals_min_only_greedy
139
- t = RP.parse('a{2,}bc')
140
-
141
- assert_equal( true, t.expressions.first.quantified? )
142
- assert_equal( :interval, t.expressions.first.quantifier.token )
143
- assert_equal( 2, t.expressions.first.quantifier.min)
144
- assert_equal( -1, t.expressions.first.quantifier.max)
145
- assert_equal( :greedy, t.expressions.first.quantifier.mode )
151
+ root = RP.parse('a{2,}bc')
152
+ exp = root.expressions.first
153
+
154
+ assert_equal true, exp.quantified?
155
+ assert_equal :interval, exp.quantifier.token
156
+ assert_equal 2, exp.quantifier.min
157
+ assert_equal -1, exp.quantifier.max
158
+ assert_equal :greedy, exp.quantifier.mode
146
159
  end
147
160
 
148
161
  def test_parse_intervals_min_only_reluctant
149
- t = RP.parse('a{2,}?bc')
150
-
151
- assert_equal( true, t.expressions.first.quantified? )
152
- assert_equal( :interval, t.expressions.first.quantifier.token )
153
- assert_equal( '{2,}?', t.expressions.first.quantifier.text )
154
- assert_equal( 2, t.expressions.first.quantifier.min)
155
- assert_equal( -1, t.expressions.first.quantifier.max)
156
- assert_equal( :reluctant, t.expressions.first.quantifier.mode )
157
- assert_equal( true, t.expressions.first.reluctant? )
162
+ root = RP.parse('a{2,}?bc')
163
+ exp = root.expressions.first
164
+
165
+ assert_equal true, exp.quantified?
166
+ assert_equal :interval, exp.quantifier.token
167
+ assert_equal '{2,}?', exp.quantifier.text
168
+ assert_equal 2, exp.quantifier.min
169
+ assert_equal -1, exp.quantifier.max
170
+ assert_equal :reluctant, exp.quantifier.mode
171
+ assert_equal true, exp.reluctant?
158
172
  end
159
173
 
160
174
  def test_parse_intervals_min_only_possessive
161
- t = RP.parse('a{3,}+bc', 'ruby/1.9')
162
-
163
- assert_equal( true, t.expressions.first.quantified? )
164
- assert_equal( :interval, t.expressions.first.quantifier.token )
165
- assert_equal( '{3,}+', t.expressions.first.quantifier.text )
166
- assert_equal( 3, t.expressions.first.quantifier.min)
167
- assert_equal( -1, t.expressions.first.quantifier.max)
168
- assert_equal( :possessive, t.expressions.first.quantifier.mode )
169
- assert_equal( true, t.expressions.first.possessive? )
175
+ root = RP.parse('a{3,}+bc', 'ruby/1.9')
176
+ exp = root.expressions.first
177
+
178
+ assert_equal true, exp.quantified?
179
+ assert_equal :interval, exp.quantifier.token
180
+ assert_equal '{3,}+', exp.quantifier.text
181
+ assert_equal 3, exp.quantifier.min
182
+ assert_equal -1, exp.quantifier.max
183
+ assert_equal :possessive, exp.quantifier.mode
184
+ assert_equal true, exp.possessive?
170
185
  end
171
186
 
172
187
  # interval: max only
173
188
  def test_parse_intervals_max_only_greedy
174
- t = RP.parse('a{,2}bc')
175
-
176
- assert_equal( true, t.expressions.first.quantified? )
177
- assert_equal( :interval, t.expressions.first.quantifier.token )
178
- assert_equal( 0, t.expressions.first.quantifier.min)
179
- assert_equal( 2, t.expressions.first.quantifier.max)
180
- assert_equal( :greedy, t.expressions.first.quantifier.mode )
189
+ root = RP.parse('a{,2}bc')
190
+ exp = root.expressions.first
191
+
192
+ assert_equal true, exp.quantified?
193
+ assert_equal :interval, exp.quantifier.token
194
+ assert_equal 0, exp.quantifier.min
195
+ assert_equal 2, exp.quantifier.max
196
+ assert_equal :greedy, exp.quantifier.mode
181
197
  end
182
198
 
183
199
  def test_parse_intervals_max_only_reluctant
184
- t = RP.parse('a{,4}?bc')
185
-
186
- assert_equal( true, t.expressions.first.quantified? )
187
- assert_equal( :interval, t.expressions.first.quantifier.token )
188
- assert_equal( 0, t.expressions.first.quantifier.min)
189
- assert_equal( 4, t.expressions.first.quantifier.max)
190
- assert_equal( :reluctant, t.expressions.first.quantifier.mode )
191
- assert_equal( true, t.expressions.first.reluctant? )
200
+ root = RP.parse('a{,4}?bc')
201
+ exp = root.expressions.first
202
+
203
+ assert_equal true, exp.quantified?
204
+ assert_equal :interval, exp.quantifier.token
205
+ assert_equal 0, exp.quantifier.min
206
+ assert_equal 4, exp.quantifier.max
207
+ assert_equal :reluctant, exp.quantifier.mode
208
+ assert_equal true, exp.reluctant?
192
209
  end
193
210
 
194
211
  def test_parse_intervals_max_only_possessive
195
- t = RP.parse('a{,3}+bc', 'ruby/1.9')
196
-
197
- assert_equal( true, t.expressions.first.quantified? )
198
- assert_equal( :interval, t.expressions.first.quantifier.token )
199
- assert_equal( 0, t.expressions.first.quantifier.min)
200
- assert_equal( 3, t.expressions.first.quantifier.max)
201
- assert_equal( :possessive, t.expressions.first.quantifier.mode )
202
- assert_equal( true, t.expressions.first.possessive? )
212
+ root = RP.parse('a{,3}+bc', 'ruby/1.9')
213
+ exp = root.expressions.first
214
+
215
+ assert_equal true, exp.quantified?
216
+ assert_equal :interval, exp.quantifier.token
217
+ assert_equal 0, exp.quantifier.min
218
+ assert_equal 3, exp.quantifier.max
219
+ assert_equal :possessive, exp.quantifier.mode
220
+ assert_equal true, exp.possessive?
203
221
  end
204
222
 
205
223
  # interval: exact
206
224
  def test_parse_intervals_exact_greedy
207
- t = RP.parse('a{2}bc')
208
-
209
- assert_equal( true, t.expressions.first.quantified? )
210
- assert_equal( :interval, t.expressions.first.quantifier.token )
211
- assert_equal( 2, t.expressions.first.quantifier.min)
212
- assert_equal( 2, t.expressions.first.quantifier.max)
213
- assert_equal( :greedy, t.expressions.first.quantifier.mode )
225
+ root = RP.parse('a{2}bc')
226
+ exp = root.expressions.first
227
+
228
+ assert_equal true, exp.quantified?
229
+ assert_equal :interval, exp.quantifier.token
230
+ assert_equal 2, exp.quantifier.min
231
+ assert_equal 2, exp.quantifier.max
232
+ assert_equal :greedy, exp.quantifier.mode
214
233
  end
215
234
 
216
235
  def test_parse_intervals_exact_reluctant
217
- t = RP.parse('a{3}?bc')
218
-
219
- assert_equal( true, t.expressions.first.quantified? )
220
- assert_equal( :interval, t.expressions.first.quantifier.token )
221
- assert_equal( 3, t.expressions.first.quantifier.min)
222
- assert_equal( 3, t.expressions.first.quantifier.max)
223
- assert_equal( :reluctant, t.expressions.first.quantifier.mode )
224
- assert_equal( true, t.expressions.first.reluctant? )
236
+ root = RP.parse('a{3}?bc')
237
+ exp = root.expressions.first
238
+
239
+ assert_equal true, exp.quantified?
240
+ assert_equal :interval, exp.quantifier.token
241
+ assert_equal 3, exp.quantifier.min
242
+ assert_equal 3, exp.quantifier.max
243
+ assert_equal :reluctant, exp.quantifier.mode
244
+ assert_equal true, exp.reluctant?
225
245
  end
226
246
 
227
247
  def test_parse_intervals_exact_possessive
228
- t = RP.parse('a{3}+bc', 'ruby/1.9')
229
-
230
- assert_equal( true, t.expressions.first.quantified? )
231
- assert_equal( :interval, t.expressions.first.quantifier.token )
232
- assert_equal( 3, t.expressions.first.quantifier.min)
233
- assert_equal( 3, t.expressions.first.quantifier.max)
234
- assert_equal( :possessive, t.expressions.first.quantifier.mode )
235
- assert_equal( true, t.expressions.first.possessive? )
248
+ root = RP.parse('a{3}+bc', 'ruby/1.9')
249
+ exp = root.expressions.first
250
+
251
+ assert_equal true, exp.quantified?
252
+ assert_equal :interval, exp.quantifier.token
253
+ assert_equal 3, exp.quantifier.min
254
+ assert_equal 3, exp.quantifier.max
255
+ assert_equal :possessive, exp.quantifier.mode
256
+ assert_equal true, exp.possessive?
236
257
  end
237
258
 
238
259
  end