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/expression/test_all.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
%w{
|
4
|
-
base to_s to_h clone subexpression free_space tests
|
5
|
-
traverse strfregexp
|
6
|
-
}.each do|tc|
|
7
|
-
require File.expand_path("../test_#{tc}", __FILE__)
|
8
|
-
end
|
9
|
-
|
10
|
-
if RUBY_VERSION >= '2.0.0'
|
11
|
-
require File.expand_path("../test_conditionals", __FILE__)
|
12
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ExpressionBase < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_expression_to_re
|
6
|
-
re_text = '^a*(b([cde]+))+f?$'
|
7
|
-
|
8
|
-
re = RP.parse(re_text).to_re
|
9
|
-
|
10
|
-
assert re.is_a?(::Regexp),
|
11
|
-
'Not a Regexp, but should be'
|
12
|
-
|
13
|
-
assert_equal re.source, re_text
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_expression_level
|
17
|
-
regexp = /^a(b(c(d)))e$/
|
18
|
-
root = RP.parse(regexp)
|
19
|
-
|
20
|
-
%w{^ a (b(c(d))) e $}.each_with_index do |t, i|
|
21
|
-
assert_equal t, root[i].to_s
|
22
|
-
assert_equal 0, root[i].level
|
23
|
-
end
|
24
|
-
|
25
|
-
assert_equal 'b', root[2][0].to_s
|
26
|
-
assert_equal 1, root[2][0].level
|
27
|
-
|
28
|
-
assert_equal 'c', root[2][1][0].to_s
|
29
|
-
assert_equal 2, root[2][1][0].level
|
30
|
-
|
31
|
-
assert_equal 'd', root[2][1][1][0].to_s
|
32
|
-
assert_equal 3, root[2][1][1][0].level
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_expression_terminal?
|
36
|
-
root = RP.parse('^a([b]+)c$')
|
37
|
-
|
38
|
-
assert_equal false, root.terminal?
|
39
|
-
|
40
|
-
assert_equal true, root[0].terminal?
|
41
|
-
assert_equal true, root[1].terminal?
|
42
|
-
assert_equal false, root[2].terminal?
|
43
|
-
assert_equal false, root[2][0].terminal?
|
44
|
-
assert_equal true, root[2][0][0].terminal?
|
45
|
-
assert_equal true, root[3].terminal?
|
46
|
-
assert_equal true, root[4].terminal?
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_expression_alt_terminal?
|
50
|
-
root = RP.parse('^(ab|cd)$')
|
51
|
-
|
52
|
-
assert_equal false, root.terminal?
|
53
|
-
|
54
|
-
assert_equal true, root[0].terminal?
|
55
|
-
assert_equal false, root[1].terminal?
|
56
|
-
assert_equal false, root[1][0].terminal?
|
57
|
-
assert_equal false, root[1][0][0].terminal?
|
58
|
-
assert_equal true, root[1][0][0][0].terminal?
|
59
|
-
assert_equal false, root[1][0][1].terminal?
|
60
|
-
assert_equal true, root[1][0][1][0].terminal?
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_expression_coded_offset
|
64
|
-
root = RP.parse('^a*(b+(c?))$')
|
65
|
-
|
66
|
-
assert_equal '@0+12', root.coded_offset
|
67
|
-
|
68
|
-
# All top level offsets
|
69
|
-
[
|
70
|
-
[ '@0+1', '^' ],
|
71
|
-
[ '@1+2', 'a*' ],
|
72
|
-
[ '@3+8', '(b+(c?))' ],
|
73
|
-
['@11+1', '$' ],
|
74
|
-
].each_with_index do |check, i|
|
75
|
-
against = [ root[i].coded_offset, root[i].to_s ]
|
76
|
-
|
77
|
-
assert_equal check, against
|
78
|
-
end
|
79
|
-
|
80
|
-
# Nested expression
|
81
|
-
assert_equal ['@4+2', 'b+'], [root[2][0].coded_offset, root[2][0].to_s]
|
82
|
-
|
83
|
-
# Nested subexpression
|
84
|
-
assert_equal ['@6+4', '(c?)'], [root[2][1].coded_offset, root[2][1].to_s]
|
85
|
-
|
86
|
-
# Nested subexpression expression
|
87
|
-
assert_equal ['@7+2', 'c?'], [root[2][1][0].coded_offset, root[2][1][0].to_s]
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ExpressionClone < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_expression_clone_base
|
6
|
-
root = RP.parse(/^(?i:a)b+$/i)
|
7
|
-
copy = root.clone
|
8
|
-
|
9
|
-
refute_equal copy.object_id, root.object_id
|
10
|
-
|
11
|
-
# The text content is equal but the objects are not.
|
12
|
-
assert_equal copy.text, root.text
|
13
|
-
refute_equal copy.text.object_id, root.text.object_id
|
14
|
-
|
15
|
-
root_1 = root.expressions[1]
|
16
|
-
copy_1 = copy.expressions[1]
|
17
|
-
|
18
|
-
# The options hash contents are equal but the objects are not.
|
19
|
-
assert_equal copy_1.options, root_1.options
|
20
|
-
refute_equal copy_1.options.object_id, root_1.options.object_id
|
21
|
-
|
22
|
-
root_2 = root.expressions[2]
|
23
|
-
copy_2 = copy.expressions[2]
|
24
|
-
|
25
|
-
assert root_2.quantified?
|
26
|
-
assert copy_2.quantified?
|
27
|
-
|
28
|
-
# The quantifier contents are equal but the objects are not.
|
29
|
-
assert_equal copy_2.quantifier.text,
|
30
|
-
root_2.quantifier.text
|
31
|
-
|
32
|
-
refute_equal copy_2.quantifier.text.object_id,
|
33
|
-
root_2.quantifier.text.object_id
|
34
|
-
|
35
|
-
refute_equal copy_2.quantifier.object_id,
|
36
|
-
root_2.quantifier.object_id
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_expression_clone_subexpression
|
40
|
-
root = RP.parse(/^a(b([cde])f)g$/)
|
41
|
-
copy = root.clone
|
42
|
-
|
43
|
-
assert root.respond_to?(:expressions)
|
44
|
-
assert copy.respond_to?(:expressions)
|
45
|
-
|
46
|
-
# The expressions arrays are not equal.
|
47
|
-
refute_equal copy.expressions.object_id,
|
48
|
-
root.expressions.object_id
|
49
|
-
|
50
|
-
# The expressions in the arrays are not equal.
|
51
|
-
copy.expressions.each_with_index do |exp, index|
|
52
|
-
refute_equal exp.object_id,
|
53
|
-
root.expressions[index].object_id
|
54
|
-
end
|
55
|
-
|
56
|
-
# The expressions in nested expressions are not equal.
|
57
|
-
copy.expressions[2].each_with_index do |exp, index|
|
58
|
-
refute_equal exp.object_id,
|
59
|
-
root.expressions[2][index].object_id
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# ruby 1.8 does not implement named groups
|
64
|
-
def test_expression_clone_named_group
|
65
|
-
root = RP.parse('^(?<somename>a)+bc$')
|
66
|
-
copy = root.clone
|
67
|
-
|
68
|
-
root_1 = root.expressions[1]
|
69
|
-
copy_1 = copy.expressions[1]
|
70
|
-
|
71
|
-
# The names are equal but their objects are not.
|
72
|
-
assert_equal copy_1.name, root_1.name
|
73
|
-
refute_equal copy_1.name.object_id, root_1.name.object_id
|
74
|
-
|
75
|
-
# Verify super: text objects should be different.
|
76
|
-
assert_equal copy_1.text, root_1.text
|
77
|
-
|
78
|
-
# Verify super: expressions arrays are not equal.
|
79
|
-
refute_equal copy_1.expressions.object_id,
|
80
|
-
root_1.expressions.object_id
|
81
|
-
|
82
|
-
# Verify super: expressions in the arrays are not equal.
|
83
|
-
copy_1.expressions.each_with_index do |exp, index|
|
84
|
-
refute_equal exp.object_id,
|
85
|
-
root_1.expressions[index].object_id
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ExpressionConditionals < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@root = RP.parse(/^(a(b))(b(?(1)c|(?(2)d|(?(3)e|f)))g)$/)
|
7
|
-
|
8
|
-
@cond_1 = @root[2][1]
|
9
|
-
@cond_2 = @root[2][1][2][0]
|
10
|
-
@cond_3 = @root[2][1][2][0][2][0]
|
11
|
-
end
|
12
|
-
|
13
|
-
def is_conditional_condition?(exp)
|
14
|
-
exp.is_a?(Conditional::Condition)
|
15
|
-
end
|
16
|
-
|
17
|
-
def is_conditional_branch?(exp)
|
18
|
-
exp.is_a?(Conditional::Branch)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_expression_conditional_root_level
|
22
|
-
%w{^ (a(b)) (b(?(1)c|(?(2)d|(?(3)e|f)))g) $}.each_with_index do |t, i|
|
23
|
-
assert_equal 0, @root[i].conditional_level
|
24
|
-
assert_equal t, @root[i].to_s
|
25
|
-
end
|
26
|
-
|
27
|
-
# First capture group
|
28
|
-
assert_equal 'b', @root[2][0].text
|
29
|
-
assert_equal 0, @root[2][0].conditional_level
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_expression_conditional_level_one
|
33
|
-
condition = @cond_1.condition
|
34
|
-
branch_1 = @cond_1.branches.first
|
35
|
-
|
36
|
-
# Condition
|
37
|
-
assert_equal true, is_conditional_condition?(condition)
|
38
|
-
assert_equal '(1)', condition.text
|
39
|
-
assert_equal 1, condition.conditional_level
|
40
|
-
|
41
|
-
# Branch 1
|
42
|
-
assert_equal true, is_conditional_branch?(branch_1)
|
43
|
-
assert_equal 'c', branch_1.text
|
44
|
-
assert_equal 1, branch_1.conditional_level
|
45
|
-
|
46
|
-
# Literal
|
47
|
-
assert_equal 'c', branch_1.first.text
|
48
|
-
assert_equal 1, branch_1.first.conditional_level
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_expression_conditional_level_two
|
53
|
-
condition = @cond_2.condition
|
54
|
-
branch_1 = @cond_2.branches.first
|
55
|
-
branch_2 = @cond_2.branches.last
|
56
|
-
|
57
|
-
assert_equal '(?', @cond_2.text
|
58
|
-
assert_equal 1, @cond_2.conditional_level
|
59
|
-
|
60
|
-
# Condition
|
61
|
-
assert_equal true, is_conditional_condition?(condition)
|
62
|
-
assert_equal '(2)', condition.text
|
63
|
-
assert_equal 2, condition.conditional_level
|
64
|
-
|
65
|
-
# Branch 1
|
66
|
-
assert_equal true, is_conditional_branch?(branch_1)
|
67
|
-
assert_equal 'd', branch_1.text
|
68
|
-
assert_equal 2, branch_1.conditional_level
|
69
|
-
|
70
|
-
# Literal
|
71
|
-
assert_equal 'd', branch_1.first.text
|
72
|
-
assert_equal 2, branch_1.first.conditional_level
|
73
|
-
|
74
|
-
# Branch 2
|
75
|
-
assert_equal '(?', branch_2.first.text
|
76
|
-
assert_equal 2, branch_2.first.conditional_level
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_expression_conditional_level_three
|
80
|
-
condition = @cond_3.condition
|
81
|
-
branch_1 = @cond_3.branches.first
|
82
|
-
branch_2 = @cond_3.branches.last
|
83
|
-
|
84
|
-
# Condition
|
85
|
-
assert_equal true, is_conditional_condition?(condition)
|
86
|
-
assert_equal '(3)', condition.text
|
87
|
-
assert_equal 3, condition.conditional_level
|
88
|
-
|
89
|
-
# Same as branch 2 in level two
|
90
|
-
assert_equal '(?', @cond_3.text
|
91
|
-
assert_equal '(?(3)e|f)', @cond_3.to_s
|
92
|
-
assert_equal 2, @cond_3.conditional_level
|
93
|
-
|
94
|
-
# Branch 1
|
95
|
-
assert_equal true, is_conditional_branch?(branch_1)
|
96
|
-
assert_equal 'e', branch_1.text
|
97
|
-
assert_equal 3, branch_1.conditional_level
|
98
|
-
|
99
|
-
# Literal
|
100
|
-
assert_equal 'e', branch_1.first.text
|
101
|
-
assert_equal 3, branch_1.first.conditional_level
|
102
|
-
|
103
|
-
# Branch 2
|
104
|
-
assert_equal true, is_conditional_branch?(branch_2)
|
105
|
-
assert_equal 'f', branch_2.text
|
106
|
-
assert_equal 3, branch_2.conditional_level
|
107
|
-
|
108
|
-
# Literal
|
109
|
-
assert_equal 'f', branch_2.first.text
|
110
|
-
assert_equal 3, branch_2.first.conditional_level
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ExpressionFreeSpace < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_expression_white_space_quantify_raises_error
|
6
|
-
regexp = %r{
|
7
|
-
a # Comment
|
8
|
-
}x
|
9
|
-
|
10
|
-
root = RP.parse(regexp)
|
11
|
-
|
12
|
-
space = root[0]
|
13
|
-
assert_equal FreeSpace::WhiteSpace, space.class
|
14
|
-
|
15
|
-
assert_raise( RuntimeError ) {
|
16
|
-
space.quantify(:dummy, '#')
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_expression_comment_quantify_raises_error
|
21
|
-
regexp = %r{
|
22
|
-
a # Comment
|
23
|
-
}x
|
24
|
-
|
25
|
-
root = RP.parse(regexp)
|
26
|
-
|
27
|
-
comment = root[3]
|
28
|
-
assert_equal FreeSpace::Comment, comment.class
|
29
|
-
|
30
|
-
assert_raise( RuntimeError ) {
|
31
|
-
comment.quantify(:dummy, '#')
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
data/test/expression/test_set.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ExpressionSet < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_expression_set_expand_members_digit
|
6
|
-
set = RP.parse('[\d]').first
|
7
|
-
|
8
|
-
assert_equal ['0-9'], set.expand_members
|
9
|
-
assert_equal ['\p{Digit}'], set.expand_members(true)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_expression_set_expand_members_nondigit
|
13
|
-
set = RP.parse('[\D]').first
|
14
|
-
|
15
|
-
assert_equal ['^0-9'], set.expand_members
|
16
|
-
assert_equal ['\P{Digit}'], set.expand_members(true)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_expression_set_expand_members_word
|
20
|
-
set = RP.parse('[\w]').first
|
21
|
-
|
22
|
-
assert_equal ['A-Za-z0-9_'], set.expand_members
|
23
|
-
assert_equal ['\p{Word}'], set.expand_members(true)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_expression_set_expand_members_nonword
|
27
|
-
set = RP.parse('[\W]').first
|
28
|
-
|
29
|
-
assert_equal ['^A-Za-z0-9_'], set.expand_members
|
30
|
-
assert_equal ['\P{Word}'], set.expand_members(true)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_expression_set_expand_members_space
|
34
|
-
set = RP.parse('[\s]').first
|
35
|
-
|
36
|
-
assert_equal [' \t\f\v\n\r'], set.expand_members
|
37
|
-
assert_equal ['\p{Space}'], set.expand_members(true)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_expression_set_expand_members_nonspace
|
41
|
-
set = RP.parse('[\S]').first
|
42
|
-
|
43
|
-
assert_equal ['^ \t\f\v\n\r'], set.expand_members
|
44
|
-
assert_equal ['\P{Space}'], set.expand_members(true)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_expression_set_expand_members_xdigit
|
48
|
-
set = RP.parse('[\h]').first
|
49
|
-
|
50
|
-
assert_equal ['0-9A-Fa-f'], set.expand_members
|
51
|
-
assert_equal ['\p{Xdigit}'], set.expand_members(true)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_expression_set_expand_members_nonxdigit
|
55
|
-
set = RP.parse('[\H]').first
|
56
|
-
|
57
|
-
assert_equal ['^0-9A-Fa-f'], set.expand_members
|
58
|
-
assert_equal ['\P{Xdigit}'], set.expand_members(true)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_expression_set_include
|
62
|
-
set = RP.parse('[ac-eh\s[:digit:]\x20[b]]').first
|
63
|
-
|
64
|
-
assert set.include?('a')
|
65
|
-
assert set.include?('a', true)
|
66
|
-
assert set.include?('c-e')
|
67
|
-
assert set.include?('h')
|
68
|
-
assert set.include?('\s')
|
69
|
-
assert set.include?('[:digit:]')
|
70
|
-
assert set.include?('\x20')
|
71
|
-
|
72
|
-
assert set.include?('b')
|
73
|
-
refute set.include?('b', true) # should not include b directly
|
74
|
-
|
75
|
-
refute set.include?(']')
|
76
|
-
refute set.include?('[')
|
77
|
-
refute set.include?('x')
|
78
|
-
refute set.include?('\S')
|
79
|
-
|
80
|
-
subset = set.last
|
81
|
-
assert subset.include?('b')
|
82
|
-
refute subset.include?('a')
|
83
|
-
end
|
84
|
-
end
|
@@ -1,230 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class Expressionstrfregexp < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_expression_strfre_alias
|
6
|
-
assert_equal true, RP.parse(/a/).respond_to?(:strfre)
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_expression_strfregexp_level
|
10
|
-
root = RP.parse(/a(b(c))/)
|
11
|
-
|
12
|
-
assert_equal 'root', root.strfregexp('%l')
|
13
|
-
|
14
|
-
a = root.first
|
15
|
-
assert_equal '%0', a.strfregexp('%%l')
|
16
|
-
|
17
|
-
b = root[1].first
|
18
|
-
assert_equal '<1>', b.strfregexp('<%l>')
|
19
|
-
|
20
|
-
c = root[1][1].first
|
21
|
-
assert_equal '[at: 2]', c.strfregexp('[at: %l]')
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_expression_strfregexp_start_end
|
25
|
-
root = RP.parse(/a(b(c))/)
|
26
|
-
|
27
|
-
assert_equal '0', root.strfregexp('%s')
|
28
|
-
assert_equal '7', root.strfregexp('%e')
|
29
|
-
|
30
|
-
a = root.first
|
31
|
-
assert_equal '%0', a.strfregexp('%%s')
|
32
|
-
assert_equal '1', a.strfregexp('%e')
|
33
|
-
|
34
|
-
group_1 = root[1]
|
35
|
-
assert_equal 'GRP:1', group_1.strfregexp('GRP:%s')
|
36
|
-
assert_equal '7', group_1.strfregexp('%e')
|
37
|
-
|
38
|
-
b = group_1.first
|
39
|
-
assert_equal '<@2>', b.strfregexp('<@%s>')
|
40
|
-
assert_equal '3', b.strfregexp('%e')
|
41
|
-
|
42
|
-
c = group_1.last.first
|
43
|
-
assert_equal '[at: 4]', c.strfregexp('[at: %s]')
|
44
|
-
assert_equal '5', c.strfregexp('%e')
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_expression_strfregexp_length
|
48
|
-
root = RP.parse(/a[b]c/)
|
49
|
-
|
50
|
-
assert_equal '5', root.strfregexp('%S')
|
51
|
-
|
52
|
-
a = root.first
|
53
|
-
assert_equal '1', a.strfregexp('%S')
|
54
|
-
|
55
|
-
set = root[1]
|
56
|
-
assert_equal '3', set.strfregexp('%S')
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_expression_strfregexp_coded_offset
|
60
|
-
root = RP.parse(/a[b]c/)
|
61
|
-
|
62
|
-
assert_equal '@0+5', root.strfregexp('%o')
|
63
|
-
|
64
|
-
a = root.first
|
65
|
-
assert_equal '@0+1', a.strfregexp('%o')
|
66
|
-
|
67
|
-
set = root[1]
|
68
|
-
assert_equal '@1+3', set.strfregexp('%o')
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_expression_strfregexp_type_token
|
72
|
-
root = RP.parse(/a[b](c)/)
|
73
|
-
|
74
|
-
assert_equal 'expression', root.strfregexp('%y')
|
75
|
-
assert_equal 'root', root.strfregexp('%k')
|
76
|
-
assert_equal 'expression:root', root.strfregexp('%i')
|
77
|
-
assert_equal 'Regexp::Expression::Root', root.strfregexp('%c')
|
78
|
-
|
79
|
-
a = root.first
|
80
|
-
assert_equal 'literal', a.strfregexp('%y')
|
81
|
-
assert_equal 'literal', a.strfregexp('%k')
|
82
|
-
assert_equal 'literal:literal', a.strfregexp('%i')
|
83
|
-
assert_equal 'Regexp::Expression::Literal', a.strfregexp('%c')
|
84
|
-
|
85
|
-
set = root[1]
|
86
|
-
assert_equal 'set', set.strfregexp('%y')
|
87
|
-
assert_equal 'character', set.strfregexp('%k')
|
88
|
-
assert_equal 'set:character', set.strfregexp('%i')
|
89
|
-
assert_equal 'Regexp::Expression::CharacterSet', set.strfregexp('%c')
|
90
|
-
|
91
|
-
group = root.last
|
92
|
-
assert_equal 'group', group.strfregexp('%y')
|
93
|
-
assert_equal 'capture', group.strfregexp('%k')
|
94
|
-
assert_equal 'group:capture', group.strfregexp('%i')
|
95
|
-
assert_equal 'Regexp::Expression::Group::Capture', group.strfregexp('%c')
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_expression_strfregexp_quantifier
|
99
|
-
root = RP.parse(/a+[b](c)?d{3,4}/)
|
100
|
-
|
101
|
-
assert_equal '{1}', root.strfregexp('%q')
|
102
|
-
assert_equal '', root.strfregexp('%Q')
|
103
|
-
assert_equal '1, 1', root.strfregexp('%z, %Z')
|
104
|
-
|
105
|
-
a = root.first
|
106
|
-
assert_equal '{1, or-more}', a.strfregexp('%q')
|
107
|
-
assert_equal '+', a.strfregexp('%Q')
|
108
|
-
assert_equal '1, -1', a.strfregexp('%z, %Z')
|
109
|
-
|
110
|
-
set = root[1]
|
111
|
-
assert_equal '{1}', set.strfregexp('%q')
|
112
|
-
assert_equal '', set.strfregexp('%Q')
|
113
|
-
assert_equal '1, 1', set.strfregexp('%z, %Z')
|
114
|
-
|
115
|
-
group = root[2]
|
116
|
-
assert_equal '{0, 1}', group.strfregexp('%q')
|
117
|
-
assert_equal '?', group.strfregexp('%Q')
|
118
|
-
assert_equal '0, 1', group.strfregexp('%z, %Z')
|
119
|
-
|
120
|
-
d = root.last
|
121
|
-
assert_equal '{3, 4}', d.strfregexp('%q')
|
122
|
-
assert_equal '{3,4}', d.strfregexp('%Q')
|
123
|
-
assert_equal '3, 4', d.strfregexp('%z, %Z')
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_expression_strfregexp_text
|
127
|
-
root = RP.parse(/a(b(c))|[d-gk-p]+/)
|
128
|
-
|
129
|
-
assert_equal 'a(b(c))|[d-gk-p]+', root.strfregexp('%t')
|
130
|
-
assert_equal 'expression:root', root.strfregexp('%~t')
|
131
|
-
|
132
|
-
alt = root.first
|
133
|
-
assert_equal 'a(b(c))|[d-gk-p]+', alt.strfregexp('%t')
|
134
|
-
assert_equal 'a(b(c))|[d-gk-p]+', alt.strfregexp('%T')
|
135
|
-
assert_equal 'meta:alternation', alt.strfregexp('%~t')
|
136
|
-
|
137
|
-
seq_1 = alt.first
|
138
|
-
assert_equal 'a(b(c))', seq_1.strfregexp('%t')
|
139
|
-
assert_equal 'a(b(c))', seq_1.strfregexp('%T')
|
140
|
-
assert_equal 'expression:sequence', seq_1.strfregexp('%~t')
|
141
|
-
|
142
|
-
group = seq_1[1]
|
143
|
-
assert_equal '(b(c))', group.strfregexp('%t')
|
144
|
-
assert_equal '(b(c))', group.strfregexp('%T')
|
145
|
-
assert_equal 'group:capture', group.strfregexp('%~t')
|
146
|
-
|
147
|
-
seq_2 = alt.last
|
148
|
-
assert_equal '[d-gk-p]+', seq_2.strfregexp('%t')
|
149
|
-
assert_equal '[d-gk-p]+', seq_2.strfregexp('%T')
|
150
|
-
|
151
|
-
set = seq_2.first
|
152
|
-
assert_equal '[d-gk-p]', set.strfregexp('%t')
|
153
|
-
assert_equal '[d-gk-p]+', set.strfregexp('%T')
|
154
|
-
assert_equal 'set:character', set.strfregexp('%~t')
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_expression_strfregexp_combined
|
158
|
-
root = RP.parse(/a{5}|[b-d]+/)
|
159
|
-
|
160
|
-
assert_equal '@0+11 expression:root', root.strfregexp('%b')
|
161
|
-
assert_equal root.strfregexp('%o %i'), root.strfregexp('%b')
|
162
|
-
|
163
|
-
assert_equal '@0+11 expression:root {1}', root.strfregexp('%m')
|
164
|
-
assert_equal root.strfregexp('%b %q'), root.strfregexp('%m')
|
165
|
-
|
166
|
-
assert_equal '@0+11 expression:root {1} a{5}|[b-d]+', root.strfregexp('%a')
|
167
|
-
assert_equal root.strfregexp('%m %t'), root.strfregexp('%a')
|
168
|
-
end
|
169
|
-
|
170
|
-
# regression test
|
171
|
-
def test_expression_strfregexp_conditional
|
172
|
-
root = RP.parse('(?<A>a)(?(<A>)b|c)', 'ruby/2.0')
|
173
|
-
|
174
|
-
assert_nothing_raised { root.strfregexp }
|
175
|
-
end
|
176
|
-
|
177
|
-
def test_expression_strfregexp_tree
|
178
|
-
root = RP.parse(/a[b-d]*(e(f+))?/)
|
179
|
-
|
180
|
-
assert_equal(
|
181
|
-
"@0+15 expression:root\n" +
|
182
|
-
" @0+1 a\n" +
|
183
|
-
" @1+6 set:character\n" +
|
184
|
-
" @2+3 set:range\n" +
|
185
|
-
" @2+1 b\n" +
|
186
|
-
" @4+1 d\n" +
|
187
|
-
" @7+8 group:capture\n" +
|
188
|
-
" @8+1 e\n" +
|
189
|
-
" @9+4 group:capture\n" +
|
190
|
-
" @10+2 f+",
|
191
|
-
root.strfregexp_tree('%>%o %~t')
|
192
|
-
)
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_expression_strfregexp_tree_separator
|
196
|
-
root = RP.parse(/a[b-d]*(e(f+))?/)
|
197
|
-
|
198
|
-
assert_equal(
|
199
|
-
"@0+15 expression:root-SEP-" +
|
200
|
-
" @0+1 a-SEP-" +
|
201
|
-
" @1+6 set:character-SEP-" +
|
202
|
-
" @2+3 set:range-SEP-" +
|
203
|
-
" @2+1 b-SEP-" +
|
204
|
-
" @4+1 d-SEP-" +
|
205
|
-
" @7+8 group:capture-SEP-" +
|
206
|
-
" @8+1 e-SEP-" +
|
207
|
-
" @9+4 group:capture-SEP-" +
|
208
|
-
" @10+2 f+",
|
209
|
-
root.strfregexp_tree('%>%o %~t', true, '-SEP-')
|
210
|
-
)
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_expression_strfregexp_tree_exclude_self
|
214
|
-
root = RP.parse(/a[b-d]*(e(f+))?/)
|
215
|
-
|
216
|
-
assert_equal(
|
217
|
-
"@0+1 a\n" +
|
218
|
-
"@1+6 set:character\n" +
|
219
|
-
" @2+3 set:range\n" +
|
220
|
-
" @2+1 b\n" +
|
221
|
-
" @4+1 d\n" +
|
222
|
-
"@7+8 group:capture\n" +
|
223
|
-
" @8+1 e\n" +
|
224
|
-
" @9+4 group:capture\n" +
|
225
|
-
" @10+2 f+",
|
226
|
-
root.strfregexp_tree('%>%o %~t', false)
|
227
|
-
)
|
228
|
-
end
|
229
|
-
|
230
|
-
end
|