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
@@ -70,15 +70,19 @@ class ScannerUTF8 < Test::Unit::TestCase
70
70
  },
71
71
  }
72
72
 
73
- count = 0
74
- tests.each do |pattern, checks|
75
- define_method "test_scan_utf8_runs_#{count+=1}" do
76
-
73
+ tests.each_with_index do |(pattern, checks), count|
74
+ define_method "test_scanner_utf8_runs_#{count}" do
77
75
  tokens = RS.scan(pattern)
78
- checks.each do |offset, token|
79
- assert_equal( token, tokens[offset] )
80
- end
81
76
 
77
+ checks.each do |index, (type, token, text, ts, te)|
78
+ result = tokens[index]
79
+
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]
85
+ end
82
86
  end
83
87
  end
84
88
 
@@ -21,15 +21,19 @@ class ScannerMeta < Test::Unit::TestCase
21
21
  },
22
22
  }
23
23
 
24
- count = 0
25
- tests.each do |pattern, checks|
26
- define_method "test_scan_meta_alternation_#{count+=1}" do
27
-
24
+ tests.each_with_index do |(pattern, checks), count|
25
+ define_method "test_scanner_meta_alternation_#{count}" do
28
26
  tokens = RS.scan(pattern)
29
- checks.each do |offset, token|
30
- assert_equal( token, tokens[offset] )
31
- end
32
27
 
28
+ checks.each do |index, (type, token, text, ts, te)|
29
+ result = tokens.at(index)
30
+
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]
36
+ end
33
37
  end
34
38
  end
35
39
 
@@ -293,27 +293,29 @@ class ScannerProperties < Test::Unit::TestCase
293
293
  'XID_Continue' => :xid_continue,
294
294
  }
295
295
 
296
- count = 0
297
- tests.each do |property, test|
298
- define_method "test_scan_property_#{test}_#{count+=1}" do
299
- token = RS.scan("a\\p{#{property}}c")[1]
296
+ tests.each_with_index do |(property, token), count|
297
+ define_method "test_scan_property_#{token}_#{count}" do
298
+ tokens = RS.scan("a\\p{#{property}}c")
299
+ result = tokens.at(1)
300
300
 
301
- assert_equal( :property, token[0] )
302
- assert_equal( test, token[1] )
301
+ assert_equal :property, result[0]
302
+ assert_equal token, result[1]
303
303
  end
304
304
 
305
- define_method "test_scan_nonproperty_#{test}_#{count+=1}" do
306
- token = RS.scan("a\\P{#{property}}c")[1]
305
+ define_method "test_scan_nonproperty_#{token}_#{count}" do
306
+ tokens = RS.scan("a\\P{#{property}}c")
307
+ result = tokens.at(1)
307
308
 
308
- assert_equal( :nonproperty, token[0] )
309
- assert_equal( test, token[1] )
309
+ assert_equal :nonproperty, result[0]
310
+ assert_equal token, result[1]
310
311
  end
311
312
 
312
- define_method "test_scan_caret_nonproperty_#{test}_#{count+=1}" do
313
- token = RS.scan("a\\p{^#{property}}c")[1]
313
+ define_method "test_scan_caret_nonproperty_#{token}_#{count}" do
314
+ tokens = RS.scan("a\\p{^#{property}}c")
315
+ result = tokens.at(1)
314
316
 
315
- assert_equal( :nonproperty, token[0] )
316
- assert_equal( test, token[1] )
317
+ assert_equal :nonproperty, result[0]
318
+ assert_equal token, result[1]
317
319
  end
318
320
  end
319
321
  end
@@ -21,17 +21,16 @@ class ScannerQuantifiers < Test::Unit::TestCase
21
21
  'a{2,4}' => [:quantifier, :interval, '{2,4}'],
22
22
  }
23
23
 
24
- counter = 0
25
- tests.each do |pattern, test|
26
- name = (test[1] == :interval ? "interval_#{counter += 1}" : test[1])
24
+ tests.each_with_index do |(pattern, (type, token, text)), count|
25
+ name = (token == :interval ? "interval_#{count}" : token)
27
26
 
28
- [:type, :token, :text].each_with_index do |member, i|
29
- define_method "test_scan_#{test[0]}_#{name}_#{member}" do
27
+ define_method "test_scan_#{type}_#{name}" do
28
+ tokens = RS.scan(pattern)
29
+ result = tokens.last
30
30
 
31
- token = RS.scan(pattern).last
32
- assert_equal( test[i], token[i] )
33
-
34
- end
31
+ assert_equal type, result[0]
32
+ assert_equal token, result[1]
33
+ assert_equal text, result[2]
35
34
  end
36
35
  end
37
36
 
@@ -4,41 +4,44 @@ class ScannerRefCalls < Test::Unit::TestCase
4
4
 
5
5
  tests = {
6
6
  # Group back-references, named, numbered, and relative
7
- '(?<X>abc)\k<X>' => [3, :backref, :name_ref_ab, '\k<X>', 9, 14],
8
- "(?<X>abc)\\k'X'" => [3, :backref, :name_ref_sq, "\\k'X'", 9, 14],
7
+ '(?<X>abc)\k<X>' => [3, :backref, :name_ref_ab, '\k<X>', 9, 14],
8
+ "(?<X>abc)\\k'X'" => [3, :backref, :name_ref_sq, "\\k'X'", 9, 14],
9
9
 
10
- '(abc)\k<1>' => [3, :backref, :number_ref_ab, '\k<1>', 5, 10],
11
- "(abc)\\k'1'" => [3, :backref, :number_ref_sq, "\\k'1'", 5, 10],
10
+ '(abc)\k<1>' => [3, :backref, :number_ref_ab, '\k<1>', 5, 10],
11
+ "(abc)\\k'1'" => [3, :backref, :number_ref_sq, "\\k'1'", 5, 10],
12
12
 
13
- '(abc)\k<-1>' => [3, :backref, :number_rel_ref_ab, '\k<-1>', 5, 11],
14
- "(abc)\\k'-1'" => [3, :backref, :number_rel_ref_sq, "\\k'-1'", 5, 11],
13
+ '(abc)\k<-1>' => [3, :backref, :number_rel_ref_ab, '\k<-1>', 5, 11],
14
+ "(abc)\\k'-1'" => [3, :backref, :number_rel_ref_sq, "\\k'-1'", 5, 11],
15
15
 
16
16
  # Sub-expression invocation, named, numbered, and relative
17
- '(?<X>abc)\g<X>' => [3, :backref, :name_call_ab, '\g<X>', 9, 14],
18
- "(?<X>abc)\\g'X'" => [3, :backref, :name_call_sq, "\\g'X'", 9, 14],
17
+ '(?<X>abc)\g<X>' => [3, :backref, :name_call_ab, '\g<X>', 9, 14],
18
+ "(?<X>abc)\\g'X'" => [3, :backref, :name_call_sq, "\\g'X'", 9, 14],
19
19
 
20
- '(abc)\g<1>' => [3, :backref, :number_call_ab, '\g<1>', 5, 10],
21
- "(abc)\\g'1'" => [3, :backref, :number_call_sq, "\\g'1'", 5, 10],
20
+ '(abc)\g<1>' => [3, :backref, :number_call_ab, '\g<1>', 5, 10],
21
+ "(abc)\\g'1'" => [3, :backref, :number_call_sq, "\\g'1'", 5, 10],
22
22
 
23
- '(abc)\g<-1>' => [3, :backref, :number_rel_call_ab, '\g<-1>', 5, 11],
24
- "(abc)\\g'-1'" => [3, :backref, :number_rel_call_sq, "\\g'-1'", 5, 11],
23
+ '(abc)\g<-1>' => [3, :backref, :number_rel_call_ab, '\g<-1>', 5, 11],
24
+ "(abc)\\g'-1'" => [3, :backref, :number_rel_call_sq, "\\g'-1'", 5, 11],
25
25
 
26
26
  # Group back-references, with nesting level
27
- '(?<X>abc)\k<X-0>' => [3, :backref, :name_nest_ref_ab, '\k<X-0>', 9, 16],
28
- "(?<X>abc)\\k'X-0'" => [3, :backref, :name_nest_ref_sq, "\\k'X-0'", 9, 16],
27
+ '(?<X>abc)\k<X-0>' => [3, :backref, :name_nest_ref_ab, '\k<X-0>', 9, 16],
28
+ "(?<X>abc)\\k'X-0'" => [3, :backref, :name_nest_ref_sq, "\\k'X-0'", 9, 16],
29
29
 
30
- '(abc)\k<1-0>' => [3, :backref, :number_nest_ref_ab, '\k<1-0>', 5, 12],
31
- "(abc)\\k'1-0'" => [3, :backref, :number_nest_ref_sq, "\\k'1-0'", 5, 12],
30
+ '(abc)\k<1-0>' => [3, :backref, :number_nest_ref_ab, '\k<1-0>', 5, 12],
31
+ "(abc)\\k'1-0'" => [3, :backref, :number_nest_ref_sq, "\\k'1-0'", 5, 12],
32
32
  }
33
33
 
34
- count = 0
35
- tests.each do |pattern, test|
36
- define_method "test_scan_#{test[1]}_#{test[2]}_#{count+=1}" do
37
-
34
+ tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
35
+ define_method "test_scanner_#{type}_#{token}_#{count}" do
38
36
  tokens = RS.scan(pattern)
39
- assert_equal( test[1,5], tokens[test[0]])
40
- assert_equal( test[3], pattern[tokens[test[0]][3], tokens[test[0]][4]])
41
-
37
+ result = tokens[index]
38
+
39
+ assert_equal type, result[0]
40
+ assert_equal token, result[1]
41
+ assert_equal text, result[2]
42
+ assert_equal ts, result[3]
43
+ assert_equal te, result[4]
44
+ assert_equal text, pattern[ts, te]
42
45
  end
43
46
  end
44
47
 
@@ -364,20 +364,21 @@ class ScannerUnicodeScripts < Test::Unit::TestCase
364
364
  'Unknown' => :script_unknown,
365
365
  }
366
366
 
367
- count = 0
368
- tests.each do |property, test|
369
- define_method "test_scan_property_#{test}_#{count+=1}" do
370
- token = RS.scan("a\\p{#{property}}c")[1]
367
+ tests.each_with_index do |(property, token), count|
368
+ define_method "test_scanner_property_#{token}_#{count}" do
369
+ tokens = RS.scan("a\\p{#{property}}c")
370
+ result = tokens.at(1)
371
371
 
372
- assert_equal( :property, token[0] )
373
- assert_equal( test, token[1] )
372
+ assert_equal :property, result[0]
373
+ assert_equal token, result[1]
374
374
  end
375
375
 
376
- define_method "test_scan_nonproperty_#{test}_#{count+=1}" do
377
- token = RS.scan("a\\P{#{property}}c")[1]
376
+ define_method "test_scanner_nonproperty_#{token}_#{count}" do
377
+ tokens = RS.scan("a\\P{#{property}}c")
378
+ result = tokens.at(1)
378
379
 
379
- assert_equal( :nonproperty, token[0] )
380
- assert_equal( test, token[1] )
380
+ assert_equal :nonproperty, result[0]
381
+ assert_equal token, result[1]
381
382
  end
382
383
  end
383
384
 
@@ -69,13 +69,16 @@ class ScannerSets < Test::Unit::TestCase
69
69
  '[a-w&&[^c-j]z]' => [6, :subset, :close, ']', 11, 12],
70
70
  }
71
71
 
72
- count = 0
73
- tests.each do |pattern, test|
74
- define_method "test_scan_#{test[1]}_#{test[2]}_#{count+=1}" do
75
-
72
+ tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
73
+ define_method "test_scanner_#{type}_#{token}_#{count}" do
76
74
  tokens = RS.scan(pattern)
77
- assert_equal( test[1,5], tokens[test[0]] )
75
+ result = tokens.at(index)
78
76
 
77
+ assert_equal type, result[0]
78
+ assert_equal token, result[1]
79
+ assert_equal text, result[2]
80
+ assert_equal ts, result[3]
81
+ assert_equal te, result[4]
79
82
  end
80
83
  end
81
84
 
@@ -3,27 +3,29 @@ require File.expand_path("../../helpers", __FILE__)
3
3
  class ScannerTypes < Test::Unit::TestCase
4
4
 
5
5
  tests = {
6
- 'a\dc' => [:type, :digit, '\d', 1],
7
- 'a\Dc' => [:type, :nondigit, '\D', 1],
6
+ 'a\dc' => [1, :type, :digit, '\d', 1, 3],
7
+ 'a\Dc' => [1, :type, :nondigit, '\D', 1, 3],
8
8
 
9
- 'a\hc' => [:type, :hex, '\h', 1],
10
- 'a\Hc' => [:type, :nonhex, '\H', 1],
9
+ 'a\hc' => [1, :type, :hex, '\h', 1, 3],
10
+ 'a\Hc' => [1, :type, :nonhex, '\H', 1, 3],
11
11
 
12
- 'a\sc' => [:type, :space, '\s', 1],
13
- 'a\Sc' => [:type, :nonspace, '\S', 1],
12
+ 'a\sc' => [1, :type, :space, '\s', 1, 3],
13
+ 'a\Sc' => [1, :type, :nonspace, '\S', 1, 3],
14
14
 
15
- 'a\wc' => [:type, :word, '\w', 1],
16
- 'a\Wc' => [:type, :nonword, '\W', 1],
15
+ 'a\wc' => [1, :type, :word, '\w', 1, 3],
16
+ 'a\Wc' => [1, :type, :nonword, '\W', 1, 3],
17
17
  }
18
18
 
19
- tests.each do |pattern, test|
20
- [:type, :token, :text].each_with_index do |member, i|
21
- define_method "test_scan_#{test[0]}_#{test[1]}_#{member}" do
19
+ tests.each do |(pattern, (index, type, token, text, ts, te))|
20
+ define_method "test_scanner_#{type}_#{token}" do
21
+ tokens = RS.scan(pattern)
22
+ result = tokens.at(index)
22
23
 
23
- token = RS.scan(pattern)[test[3]]
24
- assert_equal( test[i], token[i] )
25
-
26
- end
24
+ assert_equal type, result[0]
25
+ assert_equal token, result[1]
26
+ assert_equal text, result[2]
27
+ assert_equal ts, result[3]
28
+ assert_equal te, result[4]
27
29
  end
28
30
  end
29
31
 
@@ -110,20 +110,21 @@ class ScannerUnicodeBlocks < Test::Unit::TestCase
110
110
  'InYijing_Hexagram_Symbols' => :block_inyijing_hexagram_symbols
111
111
  }
112
112
 
113
- count = 0
114
- tests.each do |property, test|
115
- define_method "test_scan_property_#{test}_#{count+=1}" do
116
- token = RS.scan("a\\p{#{property}}c")[1]
113
+ tests.each_with_index do |(property, token), count|
114
+ define_method "test_scanner_property_#{token}_#{count}" do
115
+ tokens = RS.scan("a\\p{#{property}}c")
116
+ result = tokens.at(1)
117
117
 
118
- assert_equal( :property, token[0] )
119
- assert_equal( test, token[1] )
118
+ assert_equal :property, result[0]
119
+ assert_equal token, result[1]
120
120
  end
121
121
 
122
- define_method "test_scan_nonproperty_#{test}_#{count+=1}" do
123
- token = RS.scan("a\\P{#{property}}c")[1]
122
+ define_method "test_scanner_nonproperty_#{token}_#{count}" do
123
+ tokens = RS.scan("a\\P{#{property}}c")
124
+ result = tokens.at(1)
124
125
 
125
- assert_equal( :nonproperty, token[0] )
126
- assert_equal( test, token[1] )
126
+ assert_equal :nonproperty, result[0]
127
+ assert_equal token, result[1]
127
128
  end
128
129
  end
129
130
 
@@ -35,21 +35,17 @@ class TestSyntaxRuby_V18 < Test::Unit::TestCase
35
35
  }
36
36
 
37
37
  tests.each do |method, types|
38
+ expected = method == :excludes ? false : true
39
+
38
40
  types.each do |type, tokens|
39
41
  if tokens.nil? or tokens.empty?
40
42
  define_method "test_syntax_ruby_v18_#{method}_#{type}" do
41
- assert_equal(
42
- method == :excludes ? false : true,
43
- @syntax.implements?(type, nil)
44
- )
43
+ assert_equal expected, @syntax.implements?(type, nil)
45
44
  end
46
45
  else
47
46
  tokens.each do |token|
48
47
  define_method "test_syntax_ruby_v18_#{method}_#{type}_#{token}" do
49
- assert_equal(
50
- method == :excludes ? false : true,
51
- @syntax.implements?(type, token)
52
- )
48
+ assert_equal expected, @syntax.implements?(type, token)
53
49
  end
54
50
  end
55
51
  end
@@ -22,19 +22,13 @@ class TestSyntaxRuby_V191 < Test::Unit::TestCase
22
22
  Quantifier::Possessive
23
23
  ].flatten,
24
24
  },
25
-
26
- :excludes => {
27
- },
28
25
  }
29
26
 
30
27
  tests.each do |method, types|
31
28
  types.each do |type, tokens|
32
29
  tokens.each do |token|
33
30
  define_method "test_syntax_ruby_v191_#{method}_#{type}_#{token}" do
34
- assert_equal(
35
- method == :excludes ? false : true,
36
- @syntax.implements?(type, token)
37
- )
31
+ assert_equal true, @syntax.implements?(type, token)
38
32
  end
39
33
  end
40
34
  end
@@ -17,19 +17,15 @@ class TestSyntaxRuby_V193 < Test::Unit::TestCase
17
17
  UnicodeProperty::Script_6_0 + UnicodeProperty::Age_V193
18
18
  ].flatten,
19
19
  },
20
-
21
- :excludes => {
22
- },
23
20
  }
24
21
 
25
22
  tests.each do |method, types|
23
+ expected = method == :excludes ? false : true
24
+
26
25
  types.each do |type, tokens|
27
26
  tokens.each do |token|
28
27
  define_method "test_syntax_ruby_v193_#{method}_#{type}_#{token}" do
29
- assert_equal(
30
- method == :excludes ? false : true,
31
- @syntax.implements?(type, token)
32
- )
28
+ assert_equal true, @syntax.implements?(type, token)
33
29
  end
34
30
  end
35
31
  end
@@ -17,19 +17,13 @@ class TestSyntaxRuby_V200 < Test::Unit::TestCase
17
17
  UnicodeProperty::Age_V200
18
18
  ].flatten,
19
19
  },
20
-
21
- :excludes => {
22
- },
23
20
  }
24
21
 
25
22
  tests.each do |method, types|
26
23
  types.each do |type, tokens|
27
24
  tokens.each do |token|
28
25
  define_method "test_syntax_ruby_v200_#{method}_#{type}_#{token}" do
29
- assert_equal(
30
- method == :excludes ? false : true,
31
- @syntax.implements?(type, token)
32
- )
26
+ assert_equal true, @syntax.implements?(type, token)
33
27
  end
34
28
  end
35
29
  end
@@ -17,19 +17,13 @@ class TestSyntaxRuby_V220 < Test::Unit::TestCase
17
17
  UnicodeProperty::Script_7_0 + UnicodeProperty::Age_V220
18
18
  ].flatten,
19
19
  },
20
-
21
- :excludes => {
22
- },
23
20
  }
24
21
 
25
22
  tests.each do |method, types|
26
23
  types.each do |type, tokens|
27
24
  tokens.each do |token|
28
25
  define_method "test_syntax_ruby_v220_#{method}_#{type}_#{token}" do
29
- assert_equal(
30
- method == :excludes ? false : true,
31
- @syntax.implements?(type, token)
32
- )
26
+ assert_equal true, @syntax.implements?(type, token)
33
27
  end
34
28
  end
35
29
  end
@@ -6,38 +6,38 @@ class Token < Test::Unit::TestCase
6
6
  regexp = /ab?cd/
7
7
  tokens = RL.lex(regexp)
8
8
 
9
- assert_equal( 'b', tokens[1].text )
10
- assert_equal( [1, 2], tokens[1].offset )
9
+ assert_equal 'b', tokens[1].text
10
+ assert_equal [1, 2], tokens[1].offset
11
11
 
12
- assert_equal( '?', tokens[2].text )
13
- assert_equal( [2, 3], tokens[2].offset )
12
+ assert_equal '?', tokens[2].text
13
+ assert_equal [2, 3], tokens[2].offset
14
14
 
15
- assert_equal( 'cd', tokens[3].text )
16
- assert_equal( [3, 5], tokens[3].offset )
15
+ assert_equal 'cd', tokens[3].text
16
+ assert_equal [3, 5], tokens[3].offset
17
17
  end
18
18
 
19
19
  def test_token_length
20
20
  regexp = /abc?def/
21
21
  tokens = RL.lex(regexp)
22
22
 
23
- assert_equal( 'ab', tokens[0].text )
24
- assert_equal( 2, tokens[0].length )
23
+ assert_equal 'ab', tokens[0].text
24
+ assert_equal 2, tokens[0].length
25
25
 
26
- assert_equal( 'c', tokens[1].text )
27
- assert_equal( 1, tokens[1].length )
26
+ assert_equal 'c', tokens[1].text
27
+ assert_equal 1, tokens[1].length
28
28
 
29
- assert_equal( '?', tokens[2].text )
30
- assert_equal( 1, tokens[2].length )
29
+ assert_equal '?', tokens[2].text
30
+ assert_equal 1, tokens[2].length
31
31
 
32
- assert_equal( 'def', tokens[3].text )
33
- assert_equal( 3, tokens[3].length )
32
+ assert_equal 'def', tokens[3].text
33
+ assert_equal 3, tokens[3].length
34
34
  end
35
35
 
36
36
  def test_token_to_h
37
37
  regexp = /abc?def/
38
38
  tokens = RL.lex(regexp)
39
39
 
40
- assert_equal( 'ab', tokens[0].text )
40
+ assert_equal 'ab', tokens[0].text
41
41
  assert_equal({
42
42
  :type => :literal,
43
43
  :token => :literal,
@@ -47,11 +47,10 @@ class Token < Test::Unit::TestCase
47
47
  :level => 0,
48
48
  :set_level => 0,
49
49
  :conditional_level => 0
50
- },
51
- tokens[0].to_h
50
+ }, tokens[0].to_h
52
51
  )
53
52
 
54
- assert_equal( '?', tokens[2].text )
53
+ assert_equal '?', tokens[2].text
55
54
  assert_equal({
56
55
  :type => :quantifier,
57
56
  :token => :zero_or_one,
@@ -61,8 +60,7 @@ class Token < Test::Unit::TestCase
61
60
  :level => 0,
62
61
  :set_level => 0,
63
62
  :conditional_level => 0
64
- },
65
- tokens[2].to_h
63
+ }, tokens[2].to_h
66
64
  )
67
65
  end
68
66
 
@@ -71,18 +69,18 @@ class Token < Test::Unit::TestCase
71
69
  tokens = RL.lex(regexp)
72
70
 
73
71
  a = tokens.first
74
- assert_equal( 'a', a.text )
72
+ assert_equal 'a', a.text
75
73
 
76
74
  plus = a.next
77
- assert_equal( '+', plus.text )
75
+ assert_equal '+', plus.text
78
76
 
79
77
  b = plus.next
80
- assert_equal( 'b', b.text )
78
+ assert_equal 'b', b.text
81
79
 
82
80
  interval = tokens.last
83
- assert_equal( '{2,3}', interval.text )
81
+ assert_equal '{2,3}', interval.text
84
82
 
85
- assert_equal( nil, interval.next )
83
+ assert_equal nil, interval.next
86
84
  end
87
85
 
88
86
  def test_token_previous
@@ -90,20 +88,20 @@ class Token < Test::Unit::TestCase
90
88
  tokens = RL.lex(regexp)
91
89
 
92
90
  interval = tokens.last
93
- assert_equal( '{2,3}', interval.text )
91
+ assert_equal '{2,3}', interval.text
94
92
 
95
93
  d = interval.previous
96
- assert_equal( 'd', d.text )
94
+ assert_equal 'd', d.text
97
95
 
98
96
  star = d.previous
99
- assert_equal( '*', star.text )
97
+ assert_equal '*', star.text
100
98
 
101
99
  c = star.previous
102
- assert_equal( 'c', c.text )
100
+ assert_equal 'c', c.text
103
101
 
104
102
  a = tokens.first
105
- assert_equal( 'a', a.text )
106
- assert_equal( nil, a.previous )
103
+ assert_equal 'a', a.text
104
+ assert_equal nil, a.previous
107
105
  end
108
106
 
109
107
  end