regexp_parser 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -1
- data/Gemfile +1 -1
- data/README.md +9 -13
- data/lib/regexp_parser/expression.rb +33 -21
- data/lib/regexp_parser/expression/classes/backref.rb +18 -10
- data/lib/regexp_parser/expression/classes/conditional.rb +4 -0
- data/lib/regexp_parser/expression/classes/group.rb +4 -2
- data/lib/regexp_parser/expression/classes/keep.rb +1 -3
- data/lib/regexp_parser/expression/methods/match_length.rb +172 -0
- data/lib/regexp_parser/expression/quantifier.rb +2 -2
- data/lib/regexp_parser/expression/sequence.rb +0 -4
- data/lib/regexp_parser/expression/subexpression.rb +3 -5
- data/lib/regexp_parser/lexer.rb +31 -24
- data/lib/regexp_parser/parser.rb +25 -3
- data/lib/regexp_parser/syntax/tokens.rb +2 -10
- data/lib/regexp_parser/version.rb +1 -1
- data/regexp_parser.gemspec +2 -2
- data/spec/expression/base_spec.rb +80 -0
- data/spec/expression/clone_spec.rb +120 -0
- data/spec/expression/conditional_spec.rb +89 -0
- data/spec/expression/free_space_spec.rb +27 -0
- data/spec/expression/methods/match_length_spec.rb +141 -0
- data/spec/expression/methods/strfregexp_spec.rb +224 -0
- data/spec/expression/methods/tests_spec.rb +97 -0
- data/spec/expression/methods/traverse_spec.rb +140 -0
- data/spec/expression/subexpression_spec.rb +50 -0
- data/spec/expression/to_h_spec.rb +26 -0
- data/spec/expression/to_s_spec.rb +100 -0
- data/spec/lexer/all_spec.rb +22 -0
- data/{test/lexer/test_conditionals.rb → spec/lexer/conditionals_spec.rb} +31 -35
- data/spec/lexer/escapes_spec.rb +38 -0
- data/spec/lexer/keep_spec.rb +22 -0
- data/{test/lexer/test_literals.rb → spec/lexer/literals_spec.rb} +20 -24
- data/{test/lexer/test_nesting.rb → spec/lexer/nesting_spec.rb} +11 -13
- data/spec/lexer/refcalls_spec.rb +54 -0
- data/spec/parser/all_spec.rb +31 -0
- data/spec/parser/alternation_spec.rb +88 -0
- data/{test/parser/test_anchors.rb → spec/parser/anchors_spec.rb} +7 -10
- data/spec/parser/conditionals_spec.rb +179 -0
- data/spec/parser/errors_spec.rb +51 -0
- data/spec/parser/escapes_spec.rb +132 -0
- data/spec/parser/free_space_spec.rb +130 -0
- data/spec/parser/groups_spec.rb +267 -0
- data/spec/parser/keep_spec.rb +19 -0
- data/spec/parser/posix_classes_spec.rb +27 -0
- data/spec/parser/properties_spec.rb +127 -0
- data/spec/parser/quantifiers_spec.rb +293 -0
- data/spec/parser/refcalls_spec.rb +237 -0
- data/spec/parser/set/intersections_spec.rb +127 -0
- data/spec/parser/set/ranges_spec.rb +111 -0
- data/spec/parser/sets_spec.rb +178 -0
- data/{test/parser/test_types.rb → spec/parser/types_spec.rb} +13 -20
- data/spec/scanner/all_spec.rb +18 -0
- data/{test/scanner/test_anchors.rb → spec/scanner/anchors_spec.rb} +8 -10
- data/{test/scanner/test_conditionals.rb → spec/scanner/conditionals_spec.rb} +49 -53
- data/spec/scanner/errors_spec.rb +90 -0
- data/{test/scanner/test_escapes.rb → spec/scanner/escapes_spec.rb} +8 -10
- data/{test/scanner/test_free_space.rb → spec/scanner/free_space_spec.rb} +48 -52
- data/{test/scanner/test_groups.rb → spec/scanner/groups_spec.rb} +33 -41
- data/spec/scanner/keep_spec.rb +33 -0
- data/{test/scanner/test_literals.rb → spec/scanner/literals_spec.rb} +8 -12
- data/{test/scanner/test_meta.rb → spec/scanner/meta_spec.rb} +8 -10
- data/{test/scanner/test_properties.rb → spec/scanner/properties_spec.rb} +14 -19
- data/{test/scanner/test_quantifiers.rb → spec/scanner/quantifiers_spec.rb} +7 -9
- data/{test/scanner/test_refcalls.rb → spec/scanner/refcalls_spec.rb} +9 -9
- data/{test/scanner/test_scripts.rb → spec/scanner/scripts_spec.rb} +8 -12
- data/{test/scanner/test_sets.rb → spec/scanner/sets_spec.rb} +14 -17
- data/spec/scanner/types_spec.rb +29 -0
- data/spec/scanner/unicode_blocks_spec.rb +28 -0
- data/spec/spec_helper.rb +14 -0
- data/{test → spec}/support/runner.rb +9 -8
- data/{test → spec}/support/warning_extractor.rb +5 -7
- data/spec/syntax/syntax_spec.rb +44 -0
- data/spec/syntax/syntax_token_map_spec.rb +23 -0
- data/spec/syntax/versions/1.8.6_spec.rb +38 -0
- data/spec/syntax/versions/1.9.1_spec.rb +23 -0
- data/spec/syntax/versions/1.9.3_spec.rb +22 -0
- data/spec/syntax/versions/2.0.0_spec.rb +28 -0
- data/spec/syntax/versions/2.2.0_spec.rb +22 -0
- data/spec/syntax/versions/aliases_spec.rb +119 -0
- data/spec/token/token_spec.rb +85 -0
- metadata +131 -140
- data/test/expression/test_all.rb +0 -12
- data/test/expression/test_base.rb +0 -90
- data/test/expression/test_clone.rb +0 -89
- data/test/expression/test_conditionals.rb +0 -113
- data/test/expression/test_free_space.rb +0 -35
- data/test/expression/test_set.rb +0 -84
- data/test/expression/test_strfregexp.rb +0 -230
- data/test/expression/test_subexpression.rb +0 -58
- data/test/expression/test_tests.rb +0 -99
- data/test/expression/test_to_h.rb +0 -59
- data/test/expression/test_to_s.rb +0 -104
- data/test/expression/test_traverse.rb +0 -161
- data/test/helpers.rb +0 -10
- data/test/lexer/test_all.rb +0 -41
- data/test/lexer/test_keep.rb +0 -24
- data/test/lexer/test_refcalls.rb +0 -56
- data/test/parser/set/test_intersections.rb +0 -127
- data/test/parser/set/test_ranges.rb +0 -111
- data/test/parser/test_all.rb +0 -64
- data/test/parser/test_alternation.rb +0 -92
- data/test/parser/test_conditionals.rb +0 -187
- data/test/parser/test_errors.rb +0 -63
- data/test/parser/test_escapes.rb +0 -134
- data/test/parser/test_free_space.rb +0 -139
- data/test/parser/test_groups.rb +0 -289
- data/test/parser/test_keep.rb +0 -21
- data/test/parser/test_posix_classes.rb +0 -27
- data/test/parser/test_properties.rb +0 -134
- data/test/parser/test_quantifiers.rb +0 -301
- data/test/parser/test_refcalls.rb +0 -186
- data/test/parser/test_sets.rb +0 -179
- data/test/scanner/test_all.rb +0 -38
- data/test/scanner/test_errors.rb +0 -91
- data/test/scanner/test_keep.rb +0 -35
- data/test/scanner/test_types.rb +0 -35
- data/test/scanner/test_unicode_blocks.rb +0 -30
- data/test/support/disable_autotest.rb +0 -8
- data/test/syntax/test_all.rb +0 -6
- data/test/syntax/test_syntax.rb +0 -61
- data/test/syntax/test_syntax_token_map.rb +0 -25
- data/test/syntax/versions/test_1.8.rb +0 -55
- data/test/syntax/versions/test_1.9.1.rb +0 -36
- data/test/syntax/versions/test_1.9.3.rb +0 -32
- data/test/syntax/versions/test_2.0.0.rb +0 -37
- data/test/syntax/versions/test_2.2.0.rb +0 -32
- data/test/syntax/versions/test_aliases.rb +0 -129
- data/test/syntax/versions/test_all.rb +0 -5
- data/test/test_all.rb +0 -5
- data/test/token/test_all.rb +0 -2
- data/test/token/test_token.rb +0 -107
data/test/helpers.rb
DELETED
data/test/lexer/test_all.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
%w{
|
4
|
-
literals nesting refcalls
|
5
|
-
}.each do|tc|
|
6
|
-
require File.expand_path("../test_#{tc}", __FILE__)
|
7
|
-
end
|
8
|
-
|
9
|
-
if RUBY_VERSION >= '2.0.0'
|
10
|
-
%w{conditionals keep}.each do|tc|
|
11
|
-
require File.expand_path("../test_#{tc}", __FILE__)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class TestRegexpLexer < Test::Unit::TestCase
|
16
|
-
|
17
|
-
def test_lexer_returns_an_array
|
18
|
-
assert_instance_of Array, RL.lex('abc')
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_lexer_returns_tokens
|
22
|
-
tokens = RL.lex('^abc+[^one]{2,3}\b\d\\\C-C$')
|
23
|
-
|
24
|
-
assert tokens.all?{ |token| token.kind_of?(Regexp::Token) },
|
25
|
-
"Not all array members are tokens"
|
26
|
-
|
27
|
-
assert tokens.all?{ |token| token.to_a.length == 8 },
|
28
|
-
"Not all tokens have a length of 8"
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_lexer_token_count
|
32
|
-
tokens = RL.lex(/^(one|two){2,3}([^d\]efm-qz\,\-]*)(ghi)+$/i)
|
33
|
-
|
34
|
-
assert_equal 28, tokens.length
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_lexer_scan_alias
|
38
|
-
assert_equal RL.lex(/a|b|c/), RL.scan(/a|b|c/)
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
data/test/lexer/test_keep.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class LexerKeep < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_lex_keep_token
|
6
|
-
regexp = /ab\Kcd/
|
7
|
-
tokens = RL.lex(regexp)
|
8
|
-
|
9
|
-
assert_equal :keep, tokens[1].type
|
10
|
-
assert_equal :mark, tokens[1].token
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_lex_keep_nested
|
14
|
-
regexp = /(a\Kb)|(c\\\Kd)ef/
|
15
|
-
tokens = RL.lex(regexp)
|
16
|
-
|
17
|
-
assert_equal :keep, tokens[2].type
|
18
|
-
assert_equal :mark, tokens[2].token
|
19
|
-
|
20
|
-
assert_equal :keep, tokens[9].type
|
21
|
-
assert_equal :mark, tokens[9].token
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
data/test/lexer/test_refcalls.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class LexerRefCalls < Test::Unit::TestCase
|
4
|
-
|
5
|
-
tests = {
|
6
|
-
# Traditional numerical group back-reference
|
7
|
-
'(abc)\1' => [3, :backref, :number, '\1', 5, 7, 0, 0, 0],
|
8
|
-
|
9
|
-
# Group back-references, named, numbered, and relative
|
10
|
-
'(?<X>abc)\k<X>' => [3, :backref, :name_ref, '\k<X>', 9, 14, 0, 0, 0],
|
11
|
-
"(?<X>abc)\\k'X'" => [3, :backref, :name_ref, "\\k'X'", 9, 14, 0, 0, 0],
|
12
|
-
|
13
|
-
'(abc)\k<1>' => [3, :backref, :number_ref, '\k<1>', 5, 10, 0, 0, 0],
|
14
|
-
"(abc)\\k'1'" => [3, :backref, :number_ref, "\\k'1'", 5, 10, 0, 0, 0],
|
15
|
-
|
16
|
-
'(abc)\k<-1>' => [3, :backref, :number_rel_ref, '\k<-1>', 5, 11, 0, 0, 0],
|
17
|
-
"(abc)\\k'-1'" => [3, :backref, :number_rel_ref, "\\k'-1'", 5, 11, 0, 0, 0],
|
18
|
-
|
19
|
-
# Sub-expression invocation, named, numbered, and relative
|
20
|
-
'(?<X>abc)\g<X>' => [3, :backref, :name_call, '\g<X>', 9, 14, 0, 0, 0],
|
21
|
-
"(?<X>abc)\\g'X'" => [3, :backref, :name_call, "\\g'X'", 9, 14, 0, 0, 0],
|
22
|
-
|
23
|
-
'(abc)\g<1>' => [3, :backref, :number_call, '\g<1>', 5, 10, 0, 0, 0],
|
24
|
-
"(abc)\\g'1'" => [3, :backref, :number_call, "\\g'1'", 5, 10, 0, 0, 0],
|
25
|
-
|
26
|
-
'(abc)\g<-1>' => [3, :backref, :number_rel_call, '\g<-1>', 5, 11, 0, 0, 0],
|
27
|
-
"(abc)\\g'-1'" => [3, :backref, :number_rel_call, "\\g'-1'", 5, 11, 0, 0, 0],
|
28
|
-
|
29
|
-
'(abc)\g<+1>' => [3, :backref, :number_rel_call, '\g<+1>', 5, 11, 0, 0, 0],
|
30
|
-
"(abc)\\g'+1'" => [3, :backref, :number_rel_call, "\\g'+1'", 5, 11, 0, 0, 0],
|
31
|
-
|
32
|
-
# Group back-references, with nesting level
|
33
|
-
'(?<X>abc)\k<X-0>' => [3, :backref, :name_recursion_ref, '\k<X-0>', 9, 16, 0, 0, 0],
|
34
|
-
"(?<X>abc)\\k'X-0'" => [3, :backref, :name_recursion_ref, "\\k'X-0'", 9, 16, 0, 0, 0],
|
35
|
-
|
36
|
-
'(abc)\k<1-0>' => [3, :backref, :number_recursion_ref, '\k<1-0>', 5, 12, 0, 0, 0],
|
37
|
-
"(abc)\\k'1-0'" => [3, :backref, :number_recursion_ref, "\\k'1-0'", 5, 12, 0, 0, 0],
|
38
|
-
}
|
39
|
-
|
40
|
-
tests.each_with_index do |(pattern, (index, type, token, text, ts, te, level, set_level, conditional_level)), count|
|
41
|
-
define_method "test_lexer_#{type}_#{token}_#{count}" do
|
42
|
-
tokens = RL.lex(pattern, 'ruby/1.9')
|
43
|
-
struct = tokens.at(index)
|
44
|
-
|
45
|
-
assert_equal type, struct.type
|
46
|
-
assert_equal token, struct.token
|
47
|
-
assert_equal text, struct.text
|
48
|
-
assert_equal ts, struct.ts
|
49
|
-
assert_equal te, struct.te
|
50
|
-
assert_equal level, struct.level
|
51
|
-
assert_equal set_level, struct.set_level
|
52
|
-
assert_equal conditional_level, struct.conditional_level
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../helpers', __FILE__)
|
2
|
-
|
3
|
-
# edge cases with `...-&&...` and `...&&-...` are checked in test_ranges.rb
|
4
|
-
|
5
|
-
class ParserSetIntersections < Test::Unit::TestCase
|
6
|
-
def test_parse_set_intersection
|
7
|
-
root = RP.parse('[a&&z]')
|
8
|
-
set = root[0]
|
9
|
-
ints = set[0]
|
10
|
-
|
11
|
-
assert_equal 1, set.count
|
12
|
-
assert_equal CharacterSet::Intersection, ints.class
|
13
|
-
assert_equal 2, ints.count
|
14
|
-
|
15
|
-
seq1, seq2 = ints.expressions
|
16
|
-
assert_equal CharacterSet::IntersectedSequence, seq1.class
|
17
|
-
assert_equal 1, seq1.count
|
18
|
-
assert_equal 'a', seq1.first.to_s
|
19
|
-
assert_equal Literal, seq1.first.class
|
20
|
-
assert_equal CharacterSet::IntersectedSequence, seq2.class
|
21
|
-
assert_equal 1, seq2.count
|
22
|
-
assert_equal 'z', seq2.first.to_s
|
23
|
-
assert_equal Literal, seq2.first.class
|
24
|
-
|
25
|
-
refute set.matches?('a')
|
26
|
-
refute set.matches?('&')
|
27
|
-
refute set.matches?('z')
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_parse_set_intersection_range_and_subset
|
31
|
-
root = RP.parse('[a-z&&[^a]]')
|
32
|
-
set = root[0]
|
33
|
-
ints = set[0]
|
34
|
-
|
35
|
-
assert_equal 1, set.count
|
36
|
-
assert_equal CharacterSet::Intersection, ints.class
|
37
|
-
assert_equal 2, ints.count
|
38
|
-
|
39
|
-
seq1, seq2 = ints.expressions
|
40
|
-
assert_equal CharacterSet::IntersectedSequence, seq1.class
|
41
|
-
assert_equal 1, seq1.count
|
42
|
-
assert_equal 'a-z', seq1.first.to_s
|
43
|
-
assert_equal CharacterSet::Range, seq1.first.class
|
44
|
-
assert_equal CharacterSet::IntersectedSequence, seq2.class
|
45
|
-
assert_equal 1, seq2.count
|
46
|
-
assert_equal '[^a]', seq2.first.to_s
|
47
|
-
assert_equal CharacterSet, seq2.first.class
|
48
|
-
|
49
|
-
refute set.matches?('a')
|
50
|
-
refute set.matches?('&')
|
51
|
-
assert set.matches?('b')
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_parse_set_intersection_trailing_range
|
55
|
-
root = RP.parse('[a&&a-z]')
|
56
|
-
set = root[0]
|
57
|
-
ints = set[0]
|
58
|
-
|
59
|
-
assert_equal 1, set.count
|
60
|
-
assert_equal CharacterSet::Intersection, ints.class
|
61
|
-
assert_equal 2, ints.count
|
62
|
-
|
63
|
-
seq1, seq2 = ints.expressions
|
64
|
-
assert_equal CharacterSet::IntersectedSequence, seq1.class
|
65
|
-
assert_equal 1, seq1.count
|
66
|
-
assert_equal 'a', seq1.first.to_s
|
67
|
-
assert_equal Literal, seq1.first.class
|
68
|
-
assert_equal CharacterSet::IntersectedSequence, seq2.class
|
69
|
-
assert_equal 1, seq2.count
|
70
|
-
assert_equal 'a-z', seq2.first.to_s
|
71
|
-
assert_equal CharacterSet::Range, seq2.first.class
|
72
|
-
|
73
|
-
assert set.matches?('a')
|
74
|
-
refute set.matches?('&')
|
75
|
-
refute set.matches?('b')
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_parse_set_intersection_type
|
79
|
-
root = RP.parse('[a&&\w]')
|
80
|
-
set = root[0]
|
81
|
-
ints = set[0]
|
82
|
-
|
83
|
-
assert_equal 1, set.count
|
84
|
-
assert_equal CharacterSet::Intersection, ints.class
|
85
|
-
assert_equal 2, ints.count
|
86
|
-
|
87
|
-
seq1, seq2 = ints.expressions
|
88
|
-
assert_equal CharacterSet::IntersectedSequence, seq1.class
|
89
|
-
assert_equal 1, seq1.count
|
90
|
-
assert_equal 'a', seq1.first.to_s
|
91
|
-
assert_equal Literal, seq1.first.class
|
92
|
-
assert_equal CharacterSet::IntersectedSequence, seq2.class
|
93
|
-
assert_equal 1, seq2.count
|
94
|
-
assert_equal '\w', seq2.first.to_s
|
95
|
-
assert_equal CharacterType::Word, seq2.first.class
|
96
|
-
|
97
|
-
assert set.matches?('a')
|
98
|
-
refute set.matches?('&')
|
99
|
-
refute set.matches?('b')
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_parse_set_intersection_multipart
|
103
|
-
root = RP.parse('[\h&&\w&&efg]')
|
104
|
-
set = root[0]
|
105
|
-
ints = set[0]
|
106
|
-
|
107
|
-
assert_equal 1, set.count
|
108
|
-
assert_equal CharacterSet::Intersection, ints.class
|
109
|
-
assert_equal 3, ints.count
|
110
|
-
|
111
|
-
seq1, seq2, seq3 = ints.expressions
|
112
|
-
assert_equal CharacterSet::IntersectedSequence, seq1.class
|
113
|
-
assert_equal 1, seq1.count
|
114
|
-
assert_equal '\h', seq1.first.to_s
|
115
|
-
assert_equal CharacterSet::IntersectedSequence, seq2.class
|
116
|
-
assert_equal 1, seq2.count
|
117
|
-
assert_equal '\w', seq2.first.to_s
|
118
|
-
assert_equal CharacterSet::IntersectedSequence, seq3.class
|
119
|
-
assert_equal 3, seq3.count
|
120
|
-
assert_equal 'efg', seq3.to_s
|
121
|
-
|
122
|
-
assert set.matches?('e')
|
123
|
-
assert set.matches?('f')
|
124
|
-
refute set.matches?('a')
|
125
|
-
refute set.matches?('g')
|
126
|
-
end
|
127
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../helpers', __FILE__)
|
2
|
-
|
3
|
-
class ParserSetRangs < Test::Unit::TestCase
|
4
|
-
def test_parse_set_range
|
5
|
-
root = RP.parse('[a-z]')
|
6
|
-
set = root[0]
|
7
|
-
range = set[0]
|
8
|
-
|
9
|
-
assert_equal 1, set.count
|
10
|
-
assert_equal CharacterSet::Range, range.class
|
11
|
-
assert_equal 2, range.count
|
12
|
-
assert_equal 'a', range.first.to_s
|
13
|
-
assert_equal Literal, range.first.class
|
14
|
-
assert_equal 'z', range.last.to_s
|
15
|
-
assert_equal Literal, range.last.class
|
16
|
-
assert set.matches?('m')
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_parse_set_range_hex
|
20
|
-
root = RP.parse('[\x00-\x99]')
|
21
|
-
set = root[0]
|
22
|
-
range = set[0]
|
23
|
-
|
24
|
-
assert_equal 1, set.count
|
25
|
-
assert_equal CharacterSet::Range, range.class
|
26
|
-
assert_equal 2, range.count
|
27
|
-
assert_equal '\x00', range.first.to_s
|
28
|
-
assert_equal EscapeSequence::Hex, range.first.class
|
29
|
-
assert_equal '\x99', range.last.to_s
|
30
|
-
assert_equal EscapeSequence::Hex, range.last.class
|
31
|
-
assert set.matches?('\x50')
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_parse_set_range_unicode
|
35
|
-
root = RP.parse('[\u{40 42}-\u1234]')
|
36
|
-
set = root[0]
|
37
|
-
range = set[0]
|
38
|
-
|
39
|
-
assert_equal 1, set.count
|
40
|
-
assert_equal CharacterSet::Range, range.class
|
41
|
-
assert_equal 2, range.count
|
42
|
-
assert_equal '\u{40 42}', range.first.to_s
|
43
|
-
assert_equal EscapeSequence::CodepointList, range.first.class
|
44
|
-
assert_equal '\u1234', range.last.to_s
|
45
|
-
assert_equal EscapeSequence::Codepoint, range.last.class
|
46
|
-
assert set.matches?('\u600')
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_parse_set_range_edge_case_leading_dash
|
50
|
-
root = RP.parse('[--z]')
|
51
|
-
set = root[0]
|
52
|
-
range = set[0]
|
53
|
-
|
54
|
-
assert_equal 1, set.count
|
55
|
-
assert_equal 2, range.count
|
56
|
-
assert set.matches?('a')
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_parse_set_range_edge_case_trailing_dash
|
60
|
-
root = RP.parse('[!--]')
|
61
|
-
set = root[0]
|
62
|
-
range = set[0]
|
63
|
-
|
64
|
-
assert_equal 1, set.count
|
65
|
-
assert_equal 2, range.count
|
66
|
-
assert set.matches?('$')
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_parse_set_range_edge_case_leading_negate
|
70
|
-
root = RP.parse('[^-z]')
|
71
|
-
set = root[0]
|
72
|
-
|
73
|
-
assert_equal 2, set.count
|
74
|
-
assert set.matches?('a')
|
75
|
-
refute set.matches?('z')
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_parse_set_range_edge_case_trailing_negate
|
79
|
-
root = RP.parse('[!-^]')
|
80
|
-
set = root[0]
|
81
|
-
range = set[0]
|
82
|
-
|
83
|
-
assert_equal 1, set.count
|
84
|
-
assert_equal 2, range.count
|
85
|
-
assert set.matches?('$')
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_parse_set_range_edge_case_leading_intersection
|
89
|
-
root = RP.parse('[[\-ab]&&-bc]')
|
90
|
-
set = root[0]
|
91
|
-
|
92
|
-
assert_equal 1, set.count
|
93
|
-
assert_equal '-bc', set.first.last.to_s
|
94
|
-
assert set.matches?('-')
|
95
|
-
assert set.matches?('b')
|
96
|
-
refute set.matches?('a')
|
97
|
-
refute set.matches?('c')
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_parse_set_range_edge_case_trailing_intersection
|
101
|
-
root = RP.parse('[bc-&&[\-ab]]')
|
102
|
-
set = root[0]
|
103
|
-
|
104
|
-
assert_equal 1, set.count
|
105
|
-
assert_equal 'bc-', set.first.first.to_s
|
106
|
-
assert set.matches?('-')
|
107
|
-
assert set.matches?('b')
|
108
|
-
refute set.matches?('a')
|
109
|
-
refute set.matches?('c')
|
110
|
-
end
|
111
|
-
end
|
data/test/parser/test_all.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
%w[
|
4
|
-
alternation anchors errors escapes free_space groups
|
5
|
-
posix_classes properties quantifiers refcalls sets types
|
6
|
-
].each do |tc|
|
7
|
-
require File.expand_path("../test_#{tc}", __FILE__)
|
8
|
-
end
|
9
|
-
|
10
|
-
require File.expand_path('../set/test_ranges.rb', __FILE__)
|
11
|
-
require File.expand_path('../set/test_intersections.rb', __FILE__)
|
12
|
-
|
13
|
-
if RUBY_VERSION >= '2.0.0'
|
14
|
-
%w[conditionals keep].each do |tc|
|
15
|
-
require File.expand_path("../test_#{tc}", __FILE__)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class TestParser < Test::Unit::TestCase
|
20
|
-
|
21
|
-
def test_parse_returns_a_root_expression
|
22
|
-
assert_instance_of Regexp::Expression::Root, RP.parse('abc')
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
def test_parse_root_contains_expressions
|
27
|
-
root = RP.parse(/^a.c+[^one]{2,3}\b\d\\\C-C$/)
|
28
|
-
|
29
|
-
all_base = root.expressions.all? do |exp|
|
30
|
-
exp.kind_of?(Regexp::Expression::Base)
|
31
|
-
end
|
32
|
-
|
33
|
-
assert all_base, "Not all nodes are instances of Regexp::Expression"
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
def test_parse_node_types
|
38
|
-
root = RP.parse('^(one){2,3}([^d\]efm-qz\,\-]*)(ghi)+$')
|
39
|
-
|
40
|
-
assert root.expressions[1].expressions[0].is_a?(Literal),
|
41
|
-
"Not a literal node, but should be"
|
42
|
-
|
43
|
-
assert root.expressions[1].quantified?, "Not quanfified, but should be"
|
44
|
-
|
45
|
-
assert root.expressions[2].expressions[0].is_a?(CharacterSet),
|
46
|
-
"Not a caracter set, but it should be"
|
47
|
-
|
48
|
-
assert_equal false, root.expressions[2].quantified?
|
49
|
-
|
50
|
-
assert root.expressions[3].is_a?(Group::Capture),
|
51
|
-
"Not a group, but should be"
|
52
|
-
|
53
|
-
assert_equal true, root.expressions[3].quantified?
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_parse_no_quantifier_target_raises_error
|
57
|
-
assert_raise( ArgumentError ) { RP.parse('?abc') }
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_parse_sequence_no_quantifier_target_raises_error
|
61
|
-
assert_raise( ArgumentError ) { RP.parse('abc|?def') }
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ParserAlternation < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@root = RP.parse('(ab??|cd*|ef+)*|(gh|ij|kl)?')
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_parse_alternation_root
|
10
|
-
e = @root.expressions[0]
|
11
|
-
assert_equal true, e.is_a?(Alternation)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_parse_alternation_alts
|
15
|
-
alts = @root.expressions[0].alternatives
|
16
|
-
|
17
|
-
assert_equal true, alts[0].is_a?(Alternative)
|
18
|
-
assert_equal true, alts[1].is_a?(Alternative)
|
19
|
-
|
20
|
-
assert_equal true, alts[0][0].is_a?(Group::Capture)
|
21
|
-
assert_equal true, alts[1][0].is_a?(Group::Capture)
|
22
|
-
|
23
|
-
assert_equal 2, alts.length
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_parse_alternation_nested
|
27
|
-
e = @root[0].alternatives[0][0][0]
|
28
|
-
|
29
|
-
assert_equal true, e.is_a?(Alternation)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_parse_alternation_nested_sequence
|
33
|
-
alts = @root.expressions[0][0]
|
34
|
-
nested = alts.expressions[0][0][0]
|
35
|
-
|
36
|
-
assert_equal true, nested.is_a?(Alternative)
|
37
|
-
|
38
|
-
assert_equal true, nested.expressions[0].is_a?(Literal)
|
39
|
-
assert_equal true, nested.expressions[1].is_a?(Literal)
|
40
|
-
assert_equal 2, nested.expressions.length
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_parse_alternation_nested_groups
|
44
|
-
root = RP.parse('(i|ey|([ougfd]+)|(ney))')
|
45
|
-
|
46
|
-
alts = root.expressions[0][0].alternatives
|
47
|
-
assert_equal 4, alts.length
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_parse_alternation_grouped_alts
|
51
|
-
root = RP.parse('ca((n)|(t)|(ll)|(b))')
|
52
|
-
|
53
|
-
alts = root.expressions[1][0].alternatives
|
54
|
-
|
55
|
-
assert_equal 4, alts.length
|
56
|
-
|
57
|
-
assert_equal true, alts[0].is_a?(Alternative)
|
58
|
-
assert_equal true, alts[1].is_a?(Alternative)
|
59
|
-
assert_equal true, alts[2].is_a?(Alternative)
|
60
|
-
assert_equal true, alts[3].is_a?(Alternative)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_parse_alternation_nested_grouped_alts
|
64
|
-
root = RP.parse('ca((n|t)|(ll|b))')
|
65
|
-
|
66
|
-
alts = root.expressions[1][0].alternatives
|
67
|
-
|
68
|
-
assert_equal 2, alts.length
|
69
|
-
|
70
|
-
assert_equal true, alts[0].is_a?(Alternative)
|
71
|
-
assert_equal true, alts[1].is_a?(Alternative)
|
72
|
-
|
73
|
-
subalts = root.expressions[1][0][0][0][0].alternatives
|
74
|
-
|
75
|
-
assert_equal 2, alts.length
|
76
|
-
|
77
|
-
assert_equal true, subalts[0].is_a?(Alternative)
|
78
|
-
assert_equal true, subalts[1].is_a?(Alternative)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_parse_alternation_continues_after_nesting
|
82
|
-
root = RP.parse(/a|(b)c/)
|
83
|
-
|
84
|
-
seq = root.expressions[0][1].expressions
|
85
|
-
|
86
|
-
assert_equal 2, seq.length
|
87
|
-
|
88
|
-
assert_equal true, seq[0].is_a?(Group::Capture)
|
89
|
-
assert_equal true, seq[1].is_a?(Literal)
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|