regexp_parser 1.4.0 → 1.5.0
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.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/parser/test_sets.rb
DELETED
@@ -1,179 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class TestParserSets < Test::Unit::TestCase
|
4
|
-
def test_parse_set_basic
|
5
|
-
root = RP.parse('[ab]+')
|
6
|
-
exp = root[0]
|
7
|
-
|
8
|
-
assert_equal CharacterSet, exp.class
|
9
|
-
assert_equal 2, exp.count
|
10
|
-
|
11
|
-
assert_equal Literal, exp[0].class
|
12
|
-
assert_equal 'a', exp[0].text
|
13
|
-
assert_equal Literal, exp[1].class
|
14
|
-
assert_equal 'b', exp[1].text
|
15
|
-
|
16
|
-
assert exp.quantified?
|
17
|
-
assert_equal 1, exp.quantifier.min
|
18
|
-
assert_equal(-1, exp.quantifier.max)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_parse_set_char_type
|
22
|
-
root = RP.parse('[a\dc]')
|
23
|
-
exp = root[0]
|
24
|
-
|
25
|
-
assert_equal CharacterSet, exp.class
|
26
|
-
assert_equal 3, exp.count
|
27
|
-
|
28
|
-
assert_equal CharacterType::Digit, exp[1].class
|
29
|
-
assert_equal '\d', exp[1].text
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_parse_set_escape_sequence_backspace
|
33
|
-
root = RP.parse('[a\bc]')
|
34
|
-
exp = root[0]
|
35
|
-
|
36
|
-
assert_equal CharacterSet, exp.class
|
37
|
-
assert_equal 3, exp.count
|
38
|
-
|
39
|
-
assert_equal EscapeSequence::Backspace, exp[1].class
|
40
|
-
assert_equal '\b', exp[1].text
|
41
|
-
|
42
|
-
assert exp.matches?('a')
|
43
|
-
assert exp.matches?("\b")
|
44
|
-
refute exp.matches?('b')
|
45
|
-
assert exp.matches?('c')
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_parse_set_escape_sequence_hex
|
49
|
-
root = RP.parse('[a\x20c]', :any)
|
50
|
-
exp = root[0]
|
51
|
-
|
52
|
-
assert_equal CharacterSet, exp.class
|
53
|
-
assert_equal 3, exp.count
|
54
|
-
|
55
|
-
assert_equal EscapeSequence::Hex, exp[1].class
|
56
|
-
assert_equal '\x20', exp[1].text
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_parse_set_escape_sequence_codepoint
|
60
|
-
root = RP.parse('[a\u0640]')
|
61
|
-
exp = root[0]
|
62
|
-
|
63
|
-
assert_equal CharacterSet, exp.class
|
64
|
-
assert_equal 2, exp.count
|
65
|
-
|
66
|
-
assert_equal EscapeSequence::Codepoint, exp[1].class
|
67
|
-
assert_equal '\u0640', exp[1].text
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_parse_set_escape_sequence_codepoint_list
|
71
|
-
root = RP.parse('[a\u{41 1F60D}]')
|
72
|
-
exp = root[0]
|
73
|
-
|
74
|
-
assert_equal CharacterSet, exp.class
|
75
|
-
assert_equal 2, exp.count
|
76
|
-
|
77
|
-
assert_equal EscapeSequence::CodepointList, exp[1].class
|
78
|
-
assert_equal '\u{41 1F60D}', exp[1].text
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_parse_set_posix_class
|
82
|
-
root = RP.parse('[[:digit:][:^lower:]]+')
|
83
|
-
exp = root[0]
|
84
|
-
|
85
|
-
assert_equal CharacterSet, exp.class
|
86
|
-
assert_equal 2, exp.count
|
87
|
-
|
88
|
-
assert_equal PosixClass, exp[0].class
|
89
|
-
assert_equal '[:digit:]', exp[0].text
|
90
|
-
assert_equal PosixClass, exp[1].class
|
91
|
-
assert_equal '[:^lower:]', exp[1].text
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_parse_set_nesting
|
95
|
-
root = RP.parse('[a[b[c]d]e]')
|
96
|
-
|
97
|
-
exp = root[0]
|
98
|
-
assert_equal CharacterSet, exp.class
|
99
|
-
assert_equal 3, exp.count
|
100
|
-
assert_equal Literal, exp[0].class
|
101
|
-
assert_equal Literal, exp[2].class
|
102
|
-
|
103
|
-
subset1 = exp[1]
|
104
|
-
assert_equal CharacterSet, subset1.class
|
105
|
-
assert_equal 3, subset1.count
|
106
|
-
assert_equal Literal, subset1[0].class
|
107
|
-
assert_equal Literal, subset1[2].class
|
108
|
-
|
109
|
-
subset2 = subset1[1]
|
110
|
-
assert_equal CharacterSet, subset2.class
|
111
|
-
assert_equal 1, subset2.count
|
112
|
-
assert_equal Literal, subset2[0].class
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_parse_set_nesting_negative
|
116
|
-
root = RP.parse('[a[^b[c]]]')
|
117
|
-
exp = root[0]
|
118
|
-
|
119
|
-
assert_equal CharacterSet, exp.class
|
120
|
-
assert_equal 2, exp.count
|
121
|
-
assert_equal Literal, exp[0].class
|
122
|
-
refute exp.negative?
|
123
|
-
|
124
|
-
subset1 = exp[1]
|
125
|
-
assert_equal CharacterSet, subset1.class
|
126
|
-
assert_equal 2, subset1.count
|
127
|
-
assert_equal Literal, subset1[0].class
|
128
|
-
assert subset1.negative?
|
129
|
-
|
130
|
-
subset2 = subset1[1]
|
131
|
-
assert_equal CharacterSet, subset2.class
|
132
|
-
assert_equal 1, subset2.count
|
133
|
-
assert_equal Literal, subset2[0].class
|
134
|
-
refute subset2.negative?
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_parse_set_nesting_to_s
|
138
|
-
pattern = '[a[b[^c]]]'
|
139
|
-
root = RP.parse(pattern)
|
140
|
-
|
141
|
-
assert_equal pattern, root.to_s
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_parse_set_literals_are_not_merged
|
145
|
-
root = RP.parse("[#{'a' * 10}]")
|
146
|
-
exp = root[0]
|
147
|
-
|
148
|
-
assert_equal 10, exp.count
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_parse_set_whitespace_is_not_merged
|
152
|
-
root = RP.parse("[#{' ' * 10}]")
|
153
|
-
exp = root[0]
|
154
|
-
|
155
|
-
assert_equal 10, exp.count
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_parse_set_whitespace_is_not_merged_in_x_mode
|
159
|
-
root = RP.parse("(?x)[#{' ' * 10}]")
|
160
|
-
exp = root[1]
|
161
|
-
|
162
|
-
assert_equal 10, exp.count
|
163
|
-
end
|
164
|
-
|
165
|
-
# TODO: Collations and equivalents need own exp class if they ever get enabled
|
166
|
-
def test_parse_set_collating_sequence
|
167
|
-
root = RP.parse('[a[.span-ll.]h]', :any)
|
168
|
-
exp = root[0]
|
169
|
-
|
170
|
-
assert_equal '[.span-ll.]', exp[1].to_s
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_parse_set_character_equivalents
|
174
|
-
root = RP.parse('[a[=e=]h]', :any)
|
175
|
-
exp = root[0]
|
176
|
-
|
177
|
-
assert_equal '[=e=]', exp[1].to_s
|
178
|
-
end
|
179
|
-
end
|
data/test/scanner/test_all.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
%w[
|
4
|
-
anchors errors escapes free_space groups literals meta
|
5
|
-
properties quantifiers refcalls scripts sets types unicode_blocks
|
6
|
-
].each do |tc|
|
7
|
-
require File.expand_path("../test_#{tc}", __FILE__)
|
8
|
-
end
|
9
|
-
|
10
|
-
if RUBY_VERSION >= '2.0.0'
|
11
|
-
%w{conditionals keep}.each do|tc|
|
12
|
-
require File.expand_path("../test_#{tc}", __FILE__)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class TestRegexpScanner < Test::Unit::TestCase
|
17
|
-
|
18
|
-
def test_scanner_returns_an_array
|
19
|
-
assert_instance_of Array, RS.scan('abc')
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_scanner_returns_tokens_as_arrays
|
23
|
-
tokens = RS.scan('^abc+[^one]{2,3}\b\d\\\C-C$')
|
24
|
-
|
25
|
-
all_arrays = tokens.all? do |token|
|
26
|
-
token.kind_of?(Array) and token.length == 5
|
27
|
-
end
|
28
|
-
|
29
|
-
assert all_arrays, 'Not all tokens are arrays of 5 elements'
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_scanner_token_count
|
33
|
-
re = /^(one|two){2,3}([^d\]efm-qz\,\-]*)(ghi)+$/i
|
34
|
-
|
35
|
-
assert_equal 28, RS.scan(re).length
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/test/scanner/test_errors.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ScannerErrors < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_scanner_unbalanced_set
|
6
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('[[:alpha:]') }
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_scanner_unbalanced_group
|
10
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('(abc') }
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_scanner_unbalanced_interval
|
14
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('a{1,2') }
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_scanner_eof_in_property
|
18
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\p{asci') }
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_scanner_incomplete_property
|
22
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\p{ascii abc') }
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_scanner_unknown_property
|
26
|
-
assert_raise( RS::UnknownUnicodePropertyError ) { RS.scan('\p{foobar}') }
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_scanner_incomplete_options
|
30
|
-
assert_raise( RS::ScannerError ) { RS.scan('(?mix abc)') }
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_scanner_eof_options
|
34
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('(?mix') }
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_scanner_incorrect_options
|
38
|
-
assert_raise( RS::ScannerError ) { RS.scan('(?mix^bc') }
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_scanner_eof_escape
|
42
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\\') }
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_scanner_eof_in_hex_escape
|
46
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\x') }
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_scanner_eof_in_codepoint_escape
|
50
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\u') }
|
51
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\u0') }
|
52
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\u00') }
|
53
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\u000') }
|
54
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\u{') }
|
55
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\u{00') }
|
56
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\u{0000') }
|
57
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\u{0000 ') }
|
58
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\u{0000 0000') }
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_scanner_eof_in_control_sequence
|
62
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\c') }
|
63
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\c\M') }
|
64
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\c\M-') }
|
65
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\C') }
|
66
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\C-') }
|
67
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\C-\M') }
|
68
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\C-\M-') }
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_scanner_eof_in_meta_sequence
|
72
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\M') }
|
73
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\M-') }
|
74
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\M-\\') }
|
75
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\M-\c') }
|
76
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\M-\C') }
|
77
|
-
assert_raise( RS::PrematureEndError ) { RS.scan('\M-\C-') }
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_scanner_invalid_hex_escape
|
81
|
-
assert_raise( RS::InvalidSequenceError ) { RS.scan('\xZ') }
|
82
|
-
assert_raise( RS::InvalidSequenceError ) { RS.scan('\xZ0') }
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_scanner_invalid_named_group
|
86
|
-
assert_raise( RS::InvalidGroupError ) { RS.scan("(?'')") }
|
87
|
-
assert_raise( RS::InvalidGroupError ) { RS.scan("(?''empty-name)") }
|
88
|
-
assert_raise( RS::InvalidGroupError ) { RS.scan("(?<>)") }
|
89
|
-
assert_raise( RS::InvalidGroupError ) { RS.scan("(?<>empty-name)") }
|
90
|
-
end
|
91
|
-
end
|
data/test/scanner/test_keep.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ScannerKeep < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_scan_keep_token
|
6
|
-
tokens = RS.scan(/ab\Kcd/)
|
7
|
-
result = tokens.at(1)
|
8
|
-
|
9
|
-
assert_equal :keep, result[0]
|
10
|
-
assert_equal :mark, result[1]
|
11
|
-
assert_equal '\\K', result[2]
|
12
|
-
assert_equal 2, result[3]
|
13
|
-
assert_equal 4, result[4]
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_scan_keep_nested
|
17
|
-
tokens = RS.scan(/(a\Kb)|(c\\\Kd)ef/)
|
18
|
-
|
19
|
-
first = tokens.at(2)
|
20
|
-
second = tokens.at(9)
|
21
|
-
|
22
|
-
assert_equal :keep, first[0]
|
23
|
-
assert_equal :mark, first[1]
|
24
|
-
assert_equal '\\K', first[2]
|
25
|
-
assert_equal 2, first[3]
|
26
|
-
assert_equal 4, first[4]
|
27
|
-
|
28
|
-
assert_equal :keep, second[0]
|
29
|
-
assert_equal :mark, second[1]
|
30
|
-
assert_equal '\\K', second[2]
|
31
|
-
assert_equal 11, second[3]
|
32
|
-
assert_equal 13, second[4]
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
data/test/scanner/test_types.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ScannerTypes < Test::Unit::TestCase
|
4
|
-
|
5
|
-
tests = {
|
6
|
-
'a\dc' => [1, :type, :digit, '\d', 1, 3],
|
7
|
-
'a\Dc' => [1, :type, :nondigit, '\D', 1, 3],
|
8
|
-
|
9
|
-
'a\hc' => [1, :type, :hex, '\h', 1, 3],
|
10
|
-
'a\Hc' => [1, :type, :nonhex, '\H', 1, 3],
|
11
|
-
|
12
|
-
'a\sc' => [1, :type, :space, '\s', 1, 3],
|
13
|
-
'a\Sc' => [1, :type, :nonspace, '\S', 1, 3],
|
14
|
-
|
15
|
-
'a\wc' => [1, :type, :word, '\w', 1, 3],
|
16
|
-
'a\Wc' => [1, :type, :nonword, '\W', 1, 3],
|
17
|
-
|
18
|
-
'a\Rc' => [1, :type, :linebreak, '\R', 1, 3],
|
19
|
-
'a\Xc' => [1, :type, :xgrapheme, '\X', 1, 3],
|
20
|
-
}
|
21
|
-
|
22
|
-
tests.each do |(pattern, (index, type, token, text, ts, te))|
|
23
|
-
define_method "test_scanner_#{type}_#{token}" do
|
24
|
-
tokens = RS.scan(pattern)
|
25
|
-
result = tokens.at(index)
|
26
|
-
|
27
|
-
assert_equal type, result[0]
|
28
|
-
assert_equal token, result[1]
|
29
|
-
assert_equal text, result[2]
|
30
|
-
assert_equal ts, result[3]
|
31
|
-
assert_equal te, result[4]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ScannerUnicodeBlocks < Test::Unit::TestCase
|
4
|
-
|
5
|
-
tests = {
|
6
|
-
'InArabic' => :in_arabic,
|
7
|
-
'InCJK_Unified_Ideographs_Extension_A' => :in_cjk_unified_ideographs_extension_a,
|
8
|
-
'In Letterlike Symbols' => :in_letterlike_symbols,
|
9
|
-
'InMiscellaneous_Mathematical_Symbols-A' => :in_miscellaneous_mathematical_symbols_a,
|
10
|
-
}
|
11
|
-
|
12
|
-
tests.each_with_index do |(property, token), count|
|
13
|
-
define_method "test_scanner_property_#{token}_#{count}" do
|
14
|
-
tokens = RS.scan("a\\p{#{property}}c")
|
15
|
-
result = tokens.at(1)
|
16
|
-
|
17
|
-
assert_equal :property, result[0]
|
18
|
-
assert_equal token, result[1]
|
19
|
-
end
|
20
|
-
|
21
|
-
define_method "test_scanner_nonproperty_#{token}_#{count}" do
|
22
|
-
tokens = RS.scan("a\\P{#{property}}c")
|
23
|
-
result = tokens.at(1)
|
24
|
-
|
25
|
-
assert_equal :nonproperty, result[0]
|
26
|
-
assert_equal token, result[1]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/test/syntax/test_all.rb
DELETED
data/test/syntax/test_syntax.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class TestSyntax < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def test_syntax_unknown_name
|
6
|
-
assert_raise( Regexp::Syntax::UnknownSyntaxNameError ) {
|
7
|
-
Regexp::Syntax.new('ruby/1.0')
|
8
|
-
}
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_syntax_new
|
12
|
-
assert_instance_of Regexp::Syntax::V1_9_3,
|
13
|
-
Regexp::Syntax.new('ruby/1.9.3')
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_syntax_new_any
|
17
|
-
assert_instance_of Regexp::Syntax::Any,
|
18
|
-
Regexp::Syntax.new('any')
|
19
|
-
assert_instance_of Regexp::Syntax::Any,
|
20
|
-
Regexp::Syntax.new('*')
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_syntax_not_implemented
|
24
|
-
assert_raise( Regexp::Syntax::NotImplementedError ) {
|
25
|
-
RP.parse('\p{alpha}', 'ruby/1.8')
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_syntax_supported?
|
30
|
-
assert_equal false, Regexp::Syntax.supported?('ruby/1.1.1')
|
31
|
-
assert_equal true, Regexp::Syntax.supported?('ruby/2.4.3')
|
32
|
-
assert_equal true, Regexp::Syntax.supported?('ruby/2.5')
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_syntax_invalid_version
|
36
|
-
assert_raise( Regexp::Syntax::InvalidVersionNameError ) {
|
37
|
-
Regexp::Syntax.version_class('2.0.0')
|
38
|
-
}
|
39
|
-
|
40
|
-
assert_raise( Regexp::Syntax::InvalidVersionNameError ) {
|
41
|
-
Regexp::Syntax.version_class('ruby/20')
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_syntax_version_class_tiny_version
|
46
|
-
assert_equal Regexp::Syntax::V1_9_3,
|
47
|
-
Regexp::Syntax.version_class('ruby/1.9.3')
|
48
|
-
|
49
|
-
assert_equal Regexp::Syntax::V2_3_1,
|
50
|
-
Regexp::Syntax.version_class('ruby/2.3.1')
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_syntax_version_class_minor_version
|
54
|
-
assert_equal Regexp::Syntax::V1_9,
|
55
|
-
Regexp::Syntax.version_class('ruby/1.9')
|
56
|
-
|
57
|
-
assert_equal Regexp::Syntax::V2_3,
|
58
|
-
Regexp::Syntax.version_class('ruby/2.3')
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|