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.
- checksums.yaml +4 -4
- data/ChangeLog +6 -0
- data/lib/regexp_parser/syntax/ruby/1.9.1.rb +1 -1
- data/lib/regexp_parser/syntax/tokens/escape.rb +2 -0
- data/lib/regexp_parser/version.rb +1 -1
- data/test/expression/test_base.rb +32 -34
- data/test/expression/test_clone.rb +49 -47
- data/test/expression/test_conditionals.rb +40 -40
- data/test/expression/test_free_space.rb +4 -2
- data/test/expression/test_set.rb +16 -16
- data/test/expression/test_strfregexp.rb +74 -74
- data/test/expression/test_subexpression.rb +2 -2
- data/test/expression/test_tests.rb +57 -57
- data/test/expression/test_to_h.rb +11 -6
- data/test/expression/test_to_s.rb +22 -15
- data/test/expression/test_traverse.rb +26 -29
- data/test/lexer/test_all.rb +9 -7
- data/test/lexer/test_conditionals.rb +35 -11
- data/test/lexer/test_keep.rb +6 -6
- data/test/lexer/test_literals.rb +20 -10
- data/test/lexer/test_nesting.rb +14 -7
- data/test/lexer/test_refcalls.rb +12 -5
- data/test/parser/test_all.rb +15 -13
- data/test/parser/test_alternation.rb +29 -26
- data/test/parser/test_anchors.rb +7 -8
- data/test/parser/test_conditionals.rb +43 -41
- data/test/parser/test_escapes.rb +18 -16
- data/test/parser/test_free_space.rb +33 -33
- data/test/parser/test_groups.rb +46 -46
- data/test/parser/test_keep.rb +4 -4
- data/test/parser/test_properties.rb +18 -16
- data/test/parser/test_quantifiers.rb +184 -163
- data/test/parser/test_refcalls.rb +48 -32
- data/test/parser/test_sets.rb +102 -88
- data/test/parser/test_types.rb +7 -8
- data/test/scanner/test_all.rb +6 -4
- data/test/scanner/test_anchors.rb +8 -5
- data/test/scanner/test_conditionals.rb +38 -20
- data/test/scanner/test_escapes.rb +8 -6
- data/test/scanner/test_free_space.rb +89 -65
- data/test/scanner/test_groups.rb +27 -32
- data/test/scanner/test_keep.rb +24 -22
- data/test/scanner/test_literals.rb +11 -7
- data/test/scanner/test_meta.rb +11 -7
- data/test/scanner/test_properties.rb +16 -14
- data/test/scanner/test_quantifiers.rb +8 -9
- data/test/scanner/test_refcalls.rb +26 -23
- data/test/scanner/test_scripts.rb +11 -10
- data/test/scanner/test_sets.rb +8 -5
- data/test/scanner/test_types.rb +17 -15
- data/test/scanner/test_unicode_blocks.rb +11 -10
- data/test/syntax/ruby/test_1.8.rb +4 -8
- data/test/syntax/ruby/test_1.9.1.rb +1 -7
- data/test/syntax/ruby/test_1.9.3.rb +3 -7
- data/test/syntax/ruby/test_2.0.0.rb +1 -7
- data/test/syntax/ruby/test_2.2.0.rb +1 -7
- data/test/token/test_token.rb +29 -31
- metadata +3 -3
@@ -3,99 +3,115 @@ require File.expand_path("../../helpers", __FILE__)
|
|
3
3
|
class TestParserRefcalls < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_parse_backref_named_ab
|
6
|
-
|
6
|
+
root = RP.parse('(?<X>abc)\k<X>', 'ruby/1.9')
|
7
|
+
exp = root.expressions.at(1)
|
7
8
|
|
8
|
-
assert_equal
|
9
|
+
assert_equal true, exp.is_a?(Backreference::Name)
|
9
10
|
end
|
10
11
|
|
11
12
|
def test_parse_backref_named_sq
|
12
|
-
|
13
|
+
root = RP.parse("(?<X>abc)\\k'X'", 'ruby/1.9')
|
14
|
+
exp = root.expressions.at(1)
|
13
15
|
|
14
|
-
assert_equal
|
16
|
+
assert_equal true, exp.is_a?(Backreference::Name)
|
15
17
|
end
|
16
18
|
|
17
19
|
def test_parse_backref_number_ab
|
18
|
-
|
20
|
+
root = RP.parse('(abc)\k<1>', 'ruby/1.9')
|
21
|
+
exp = root.expressions.at(1)
|
19
22
|
|
20
|
-
assert_equal
|
23
|
+
assert_equal true, exp.is_a?(Backreference::Number)
|
21
24
|
end
|
22
25
|
|
23
26
|
def test_parse_backref_number_sq
|
24
|
-
|
27
|
+
root = RP.parse("(abc)\\k'1'", 'ruby/1.9')
|
28
|
+
exp = root.expressions.at(1)
|
25
29
|
|
26
|
-
assert_equal
|
30
|
+
assert_equal true, exp.is_a?(Backreference::Number)
|
27
31
|
end
|
28
32
|
|
29
33
|
def test_parse_backref_number_relative_ab
|
30
|
-
|
34
|
+
root = RP.parse('(abc)\k<-1>', 'ruby/1.9')
|
35
|
+
exp = root.expressions.at(1)
|
31
36
|
|
32
|
-
assert_equal
|
37
|
+
assert_equal true, exp.is_a?(Backreference::NumberRelative)
|
33
38
|
end
|
34
39
|
|
35
40
|
def test_parse_backref_number_relative_sq
|
36
|
-
|
41
|
+
root = RP.parse("(abc)\\k'-1'", 'ruby/1.9')
|
42
|
+
exp = root.expressions.at(1)
|
37
43
|
|
38
|
-
assert_equal
|
44
|
+
assert_equal true, exp.is_a?(Backreference::NumberRelative)
|
39
45
|
end
|
40
46
|
|
41
47
|
def test_parse_backref_name_call_ab
|
42
|
-
|
48
|
+
root = RP.parse('(?<X>abc)\g<X>', 'ruby/1.9')
|
49
|
+
exp = root.expressions.at(1)
|
43
50
|
|
44
|
-
assert_equal
|
51
|
+
assert_equal true, exp.is_a?(Backreference::NameCall)
|
45
52
|
end
|
46
53
|
|
47
54
|
def test_parse_backref_name_call_sq
|
48
|
-
|
55
|
+
root = RP.parse("(?<X>abc)\\g'X'", 'ruby/1.9')
|
56
|
+
exp = root.expressions.at(1)
|
49
57
|
|
50
|
-
assert_equal
|
58
|
+
assert_equal true, exp.is_a?(Backreference::NameCall)
|
51
59
|
end
|
52
60
|
|
53
61
|
def test_parse_backref_number_call_ab
|
54
|
-
|
62
|
+
root = RP.parse('(abc)\g<1>', 'ruby/1.9')
|
63
|
+
exp = root.expressions.at(1)
|
55
64
|
|
56
|
-
assert_equal
|
65
|
+
assert_equal true, exp.is_a?(Backreference::NumberCall)
|
57
66
|
end
|
58
67
|
|
59
68
|
def test_parse_backref_number_call_sq
|
60
|
-
|
69
|
+
root = RP.parse("(abc)\\g'1'", 'ruby/1.9')
|
70
|
+
exp = root.expressions.at(1)
|
61
71
|
|
62
|
-
assert_equal
|
72
|
+
assert_equal true, exp.is_a?(Backreference::NumberCall)
|
63
73
|
end
|
64
74
|
|
65
75
|
def test_parse_backref_number_relative_call_ab
|
66
|
-
|
76
|
+
root = RP.parse('(abc)\g<-1>', 'ruby/1.9')
|
77
|
+
exp = root.expressions.at(1)
|
67
78
|
|
68
|
-
assert_equal
|
79
|
+
assert_equal true, exp.is_a?(Backreference::NumberCallRelative)
|
69
80
|
end
|
70
81
|
|
71
82
|
def test_parse_backref_number_relative_call_sq
|
72
|
-
|
83
|
+
root = RP.parse("(abc)\\g'-1'", 'ruby/1.9')
|
84
|
+
exp = root.expressions.at(1)
|
73
85
|
|
74
|
-
assert_equal
|
86
|
+
assert_equal true, exp.is_a?(Backreference::NumberCallRelative)
|
75
87
|
end
|
76
88
|
|
77
89
|
def test_parse_backref_name_nest_level_ab
|
78
|
-
|
90
|
+
root = RP.parse('(?<X>abc)\k<X-0>', 'ruby/1.9')
|
91
|
+
exp = root.expressions.at(1)
|
79
92
|
|
80
|
-
assert_equal
|
93
|
+
assert_equal true, exp.is_a?(Backreference::NameNestLevel)
|
81
94
|
end
|
82
95
|
|
83
96
|
def test_parse_backref_name_nest_level_sq
|
84
|
-
|
97
|
+
root = RP.parse("(?<X>abc)\\k'X-0'", 'ruby/1.9')
|
98
|
+
exp = root.expressions.at(1)
|
85
99
|
|
86
|
-
assert_equal
|
100
|
+
assert_equal true, exp.is_a?(Backreference::NameNestLevel)
|
87
101
|
end
|
88
102
|
|
89
103
|
def test_parse_backref_number_nest_level_ab
|
90
|
-
|
104
|
+
root = RP.parse('(abc)\k<1-0>', 'ruby/1.9')
|
105
|
+
exp = root.expressions.at(1)
|
91
106
|
|
92
|
-
assert_equal
|
107
|
+
assert_equal true, exp.is_a?(Backreference::NumberNestLevel)
|
93
108
|
end
|
94
109
|
|
95
110
|
def test_parse_backref_number_nest_level_sq
|
96
|
-
|
111
|
+
root = RP.parse("(abc)\\k'1-0'", 'ruby/1.9')
|
112
|
+
exp = root.expressions.at(1)
|
97
113
|
|
98
|
-
assert_equal
|
114
|
+
assert_equal true, exp.is_a?(Backreference::NumberNestLevel)
|
99
115
|
end
|
100
116
|
|
101
117
|
end
|
data/test/parser/test_sets.rb
CHANGED
@@ -3,149 +3,163 @@ require File.expand_path("../../helpers", __FILE__)
|
|
3
3
|
class TestParserSets < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_parse_set_basic
|
6
|
-
|
6
|
+
root = RP.parse('[a-c]+', :any)
|
7
|
+
exp = root.expressions.at(0)
|
7
8
|
|
8
|
-
assert_equal
|
9
|
-
assert_equal
|
9
|
+
assert_equal true, exp.is_a?(CharacterSet)
|
10
|
+
assert_equal true, exp.include?('a-c')
|
10
11
|
|
11
|
-
assert_equal
|
12
|
-
assert_equal
|
13
|
-
assert_equal
|
12
|
+
assert_equal true, exp.quantified?
|
13
|
+
assert_equal 1, exp.quantifier.min
|
14
|
+
assert_equal -1, exp.quantifier.max
|
14
15
|
end
|
15
16
|
|
16
17
|
def test_parse_set_posix_class
|
17
|
-
|
18
|
+
root = RP.parse('[[:digit:][:lower:]]+', 'ruby/1.9')
|
19
|
+
exp = root.expressions.at(0)
|
18
20
|
|
19
|
-
assert_equal
|
21
|
+
assert_equal true, exp.is_a?(CharacterSet)
|
20
22
|
|
21
|
-
assert_equal
|
22
|
-
assert_equal
|
23
|
+
assert_equal true, exp.include?('[:digit:]')
|
24
|
+
assert_equal true, exp.include?('[:lower:]')
|
23
25
|
|
24
|
-
assert_equal
|
26
|
+
assert_equal true, exp.matches?("6")
|
25
27
|
|
26
|
-
assert_equal
|
27
|
-
assert_equal
|
28
|
+
assert_equal true, exp.matches?("v")
|
29
|
+
assert_equal false, exp.matches?("\x48")
|
28
30
|
end
|
29
31
|
|
30
32
|
def test_parse_set_members
|
31
|
-
|
33
|
+
root = RP.parse('[ac-eh]', :any)
|
34
|
+
exp = root.expressions.at(0)
|
32
35
|
|
33
|
-
assert_equal
|
34
|
-
assert_equal
|
35
|
-
assert_equal
|
36
|
-
assert_equal
|
36
|
+
assert_equal true, exp.include?('a')
|
37
|
+
assert_equal true, exp.include?('c-e')
|
38
|
+
assert_equal true, exp.include?('h')
|
39
|
+
assert_equal false, exp.include?(']')
|
37
40
|
end
|
38
41
|
|
39
42
|
def test_parse_chat_type_set_members
|
40
|
-
|
43
|
+
root = RP.parse('[\da-z]', :any)
|
44
|
+
exp = root.expressions.at(0)
|
41
45
|
|
42
|
-
assert_equal
|
43
|
-
assert_equal
|
46
|
+
assert_equal true, exp.include?('\d')
|
47
|
+
assert_equal true, exp.include?('a-z')
|
44
48
|
end
|
45
49
|
|
46
50
|
def test_parse_set_collating_sequence
|
47
|
-
|
51
|
+
root = RP.parse('[a[.span-ll.]h]', :any)
|
52
|
+
exp = root.expressions.at(0)
|
48
53
|
|
49
|
-
assert_equal
|
50
|
-
assert_equal
|
54
|
+
assert_equal true, exp.include?('[.span-ll.]')
|
55
|
+
assert_equal false, exp.include?(']')
|
51
56
|
end
|
52
57
|
|
53
58
|
def test_parse_set_character_equivalents
|
54
|
-
|
59
|
+
root = RP.parse('[a[=e=]h]', :any)
|
60
|
+
exp = root.expressions.at(0)
|
55
61
|
|
56
|
-
assert_equal
|
57
|
-
assert_equal
|
62
|
+
assert_equal true, exp.include?('[=e=]')
|
63
|
+
assert_equal false, exp.include?(']')
|
58
64
|
end
|
59
65
|
|
60
66
|
def test_parse_set_nesting_tos
|
61
67
|
pattern = '[a[b[^c]]]'
|
68
|
+
root = RP.parse(pattern, 'ruby/1.9')
|
62
69
|
|
63
|
-
assert_equal
|
70
|
+
assert_equal pattern, root.to_s
|
64
71
|
end
|
65
72
|
|
66
73
|
def test_parse_set_nesting_include
|
67
|
-
|
74
|
+
root = RP.parse('[a[b[^c]]]', 'ruby/1.9')
|
75
|
+
exp = root.expressions.at(0)
|
68
76
|
|
69
|
-
assert_equal
|
70
|
-
assert_equal
|
71
|
-
assert_equal
|
72
|
-
assert_equal
|
77
|
+
assert_equal true, exp.is_a?(CharacterSet)
|
78
|
+
assert_equal true, exp.include?('a')
|
79
|
+
assert_equal true, exp.include?('b')
|
80
|
+
assert_equal true, exp.include?('c')
|
73
81
|
end
|
74
82
|
|
75
83
|
def test_parse_set_nesting_include_at_depth
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
assert_equal
|
80
|
-
assert_equal
|
81
|
-
assert_equal
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
assert_equal
|
86
|
-
assert_equal
|
87
|
-
assert_equal
|
84
|
+
root = RP.parse('[a[b]c]', 'ruby/1.9')
|
85
|
+
|
86
|
+
exp = root.expressions.at(0)
|
87
|
+
assert_equal true, exp.is_a?(CharacterSet)
|
88
|
+
assert_equal true, exp.include?('a')
|
89
|
+
assert_equal true, exp.include?('b')
|
90
|
+
assert_equal false, exp.include?('b', true) # should not include b directly
|
91
|
+
|
92
|
+
sub = exp.members.at(1)
|
93
|
+
assert_equal false, sub.include?('a')
|
94
|
+
assert_equal true, sub.include?('b')
|
95
|
+
assert_equal true, sub.include?('b', true)
|
96
|
+
assert_equal false, sub.include?('c')
|
88
97
|
end
|
89
98
|
|
90
99
|
def test_parse_set_nesting_include_at_depth_2
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
assert_equal
|
95
|
-
assert_equal
|
96
|
-
assert_equal
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
assert_equal
|
101
|
-
assert_equal
|
102
|
-
assert_equal
|
103
|
-
assert_equal
|
104
|
-
assert_equal
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
assert_equal
|
109
|
-
assert_equal
|
110
|
-
assert_equal
|
111
|
-
assert_equal
|
112
|
-
assert_equal
|
113
|
-
assert_equal
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
assert_equal
|
118
|
-
assert_equal
|
119
|
-
assert_equal
|
120
|
-
assert_equal
|
121
|
-
assert_equal
|
122
|
-
assert_equal
|
123
|
-
assert_equal
|
100
|
+
root = RP.parse('[a[b[c[d]e]f]g]', 'ruby/1.9')
|
101
|
+
|
102
|
+
exp = root.expressions.at(0)
|
103
|
+
assert_equal true, exp.is_a?(CharacterSet)
|
104
|
+
assert_equal true, exp.include?('a')
|
105
|
+
assert_equal true, exp.include?('b')
|
106
|
+
assert_equal false, exp.include?('b', true) # should not include b directly
|
107
|
+
|
108
|
+
sub = exp.members.at(1)
|
109
|
+
assert_equal false, sub.include?('a')
|
110
|
+
assert_equal true, sub.include?('b')
|
111
|
+
assert_equal true, sub.include?('b', true)
|
112
|
+
assert_equal true, sub.include?('f', true)
|
113
|
+
assert_equal true, sub.include?('c')
|
114
|
+
assert_equal false, sub.include?('c', true)
|
115
|
+
|
116
|
+
sub2 = sub.members.at(1)
|
117
|
+
assert_equal false, sub2.include?('a')
|
118
|
+
assert_equal false, sub2.include?('b')
|
119
|
+
assert_equal true, sub2.include?('c')
|
120
|
+
assert_equal true, sub2.include?('c', true)
|
121
|
+
assert_equal true, sub2.include?('e', true)
|
122
|
+
assert_equal true, sub2.include?('d')
|
123
|
+
assert_equal false, sub2.include?('d', true)
|
124
|
+
|
125
|
+
sub3 = sub2.members.at(1)
|
126
|
+
assert_equal false, sub3.include?('a')
|
127
|
+
assert_equal false, sub3.include?('g')
|
128
|
+
assert_equal false, sub3.include?('b')
|
129
|
+
assert_equal false, sub3.include?('f')
|
130
|
+
assert_equal false, sub3.include?('c')
|
131
|
+
assert_equal false, sub3.include?('e')
|
132
|
+
assert_equal true, sub3.include?('d')
|
133
|
+
assert_equal true, sub3.include?('d', true)
|
124
134
|
end
|
125
135
|
|
126
136
|
# character subsets and negated posix classes are not available in ruby 1.8
|
127
137
|
if RUBY_VERSION >= '1.9'
|
128
138
|
def test_parse_set_nesting_matches
|
129
|
-
|
139
|
+
root = RP.parse('[a[b[^c]]]', 'ruby/1.9')
|
140
|
+
exp = root.expressions.at(0)
|
130
141
|
|
131
|
-
assert_equal
|
132
|
-
assert_equal
|
142
|
+
assert_equal true, exp.matches?('b')
|
143
|
+
assert_equal false, exp.matches?('c')
|
133
144
|
end
|
134
145
|
|
135
146
|
def test_parse_set_nesting_not_matches
|
136
|
-
|
137
|
-
|
147
|
+
root = RP.parse('[a[b[^c]]]', 'ruby/1.9')
|
148
|
+
exp = root.expressions.at(0)
|
149
|
+
|
150
|
+
assert_equal false, exp.matches?('c')
|
138
151
|
end
|
139
152
|
|
140
153
|
def test_parse_set_negated_posix_class
|
141
|
-
|
154
|
+
root = RP.parse('[[:^xdigit:][:^lower:]]+', 'ruby/1.9')
|
155
|
+
exp = root.expressions.at(0)
|
142
156
|
|
143
|
-
assert_equal
|
157
|
+
assert_equal true, exp.is_a?(CharacterSet)
|
144
158
|
|
145
|
-
assert_equal
|
146
|
-
assert_equal
|
159
|
+
assert_equal true, exp.include?('[:^xdigit:]')
|
160
|
+
assert_equal true, exp.include?('[:^lower:]')
|
147
161
|
|
148
|
-
assert_equal
|
162
|
+
assert_equal true, exp.matches?('GT')
|
149
163
|
end
|
150
164
|
end
|
151
165
|
|
data/test/parser/test_types.rb
CHANGED
@@ -16,17 +16,16 @@ class TestParserTypes < Test::Unit::TestCase
|
|
16
16
|
/a\Wc/ => [1, :type, :nonword, CharacterType::NonWord],
|
17
17
|
}
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
define_method "test_parse_type_#{test[2]}_#{count+=1}" do
|
19
|
+
tests.each_with_index do |(pattern, (index, type, token, klass)), count|
|
20
|
+
define_method "test_parse_type_#{token}_#{count}" do
|
22
21
|
root = RP.parse(pattern, 'ruby/1.9')
|
23
|
-
exp = root.expressions
|
22
|
+
exp = root.expressions.at(index)
|
24
23
|
|
25
|
-
assert
|
26
|
-
"Expected #{
|
24
|
+
assert exp.is_a?( klass ),
|
25
|
+
"Expected #{klass}, but got #{exp.class.name}"
|
27
26
|
|
28
|
-
assert_equal
|
29
|
-
assert_equal
|
27
|
+
assert_equal type, exp.type
|
28
|
+
assert_equal token, exp.token
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
data/test/scanner/test_all.rb
CHANGED
@@ -16,21 +16,23 @@ end
|
|
16
16
|
class TestRegexpScanner < Test::Unit::TestCase
|
17
17
|
|
18
18
|
def test_scanner_returns_an_array
|
19
|
-
assert_instance_of
|
19
|
+
assert_instance_of Array, RS.scan('abc')
|
20
20
|
end
|
21
21
|
|
22
22
|
def test_scanner_returns_tokens_as_arrays
|
23
23
|
tokens = RS.scan('^abc+[^one]{2,3}\b\d\\\C-C$')
|
24
24
|
|
25
|
-
|
25
|
+
all_arrays = tokens.all? do |token|
|
26
26
|
token.kind_of?(Array) and token.length == 5
|
27
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
assert all_arrays, 'Not all tokens are arrays of 5 elements'
|
28
30
|
end
|
29
31
|
|
30
32
|
def test_scanner_token_count
|
31
33
|
re = /^(one|two){2,3}([^d\]efm-qz\,\-]*)(ghi)+$/i
|
32
34
|
|
33
|
-
assert_equal
|
35
|
+
assert_equal 26, RS.scan(re).length
|
34
36
|
end
|
35
37
|
|
36
38
|
end
|