regexp_parser 1.3.0 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +72 -1
- data/Gemfile +3 -3
- data/README.md +12 -19
- data/Rakefile +3 -4
- data/lib/regexp_parser/expression.rb +28 -53
- data/lib/regexp_parser/expression/classes/backref.rb +18 -10
- data/lib/regexp_parser/expression/classes/conditional.rb +7 -2
- data/lib/regexp_parser/expression/classes/escape.rb +0 -4
- 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.rb +13 -0
- data/lib/regexp_parser/expression/methods/match_length.rb +172 -0
- data/lib/regexp_parser/expression/methods/options.rb +35 -0
- data/lib/regexp_parser/expression/methods/strfregexp.rb +0 -1
- data/lib/regexp_parser/expression/methods/tests.rb +6 -15
- data/lib/regexp_parser/expression/methods/traverse.rb +3 -1
- data/lib/regexp_parser/expression/quantifier.rb +2 -2
- data/lib/regexp_parser/expression/sequence.rb +3 -6
- data/lib/regexp_parser/expression/sequence_operation.rb +2 -6
- data/lib/regexp_parser/expression/subexpression.rb +3 -5
- data/lib/regexp_parser/lexer.rb +30 -44
- data/lib/regexp_parser/parser.rb +47 -24
- data/lib/regexp_parser/scanner.rb +1228 -1367
- data/lib/regexp_parser/scanner/char_type.rl +0 -3
- data/lib/regexp_parser/scanner/properties/long.yml +34 -1
- data/lib/regexp_parser/scanner/properties/short.yml +12 -0
- data/lib/regexp_parser/scanner/scanner.rl +101 -194
- data/lib/regexp_parser/syntax/tokens.rb +2 -10
- data/lib/regexp_parser/syntax/tokens/unicode_property.rb +72 -21
- data/lib/regexp_parser/syntax/versions/2.6.0.rb +10 -0
- data/lib/regexp_parser/syntax/versions/2.6.2.rb +10 -0
- data/lib/regexp_parser/syntax/versions/2.6.3.rb +10 -0
- data/lib/regexp_parser/version.rb +1 -1
- data/regexp_parser.gemspec +3 -3
- data/spec/expression/base_spec.rb +94 -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 +161 -0
- data/spec/expression/methods/match_spec.rb +25 -0
- data/spec/expression/methods/strfregexp_spec.rb +224 -0
- data/spec/expression/methods/tests_spec.rb +99 -0
- data/spec/expression/methods/traverse_spec.rb +161 -0
- data/spec/expression/options_spec.rb +128 -0
- data/spec/expression/root_spec.rb +9 -0
- data/spec/expression/sequence_spec.rb +9 -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/spec/lexer/conditionals_spec.rb +53 -0
- data/spec/lexer/delimiters_spec.rb +68 -0
- data/spec/lexer/escapes_spec.rb +14 -0
- data/spec/lexer/keep_spec.rb +10 -0
- data/spec/lexer/literals_spec.rb +89 -0
- data/spec/lexer/nesting_spec.rb +99 -0
- data/spec/lexer/refcalls_spec.rb +55 -0
- data/spec/parser/all_spec.rb +43 -0
- data/spec/parser/alternation_spec.rb +88 -0
- data/spec/parser/anchors_spec.rb +17 -0
- data/spec/parser/conditionals_spec.rb +179 -0
- data/spec/parser/errors_spec.rb +30 -0
- data/spec/parser/escapes_spec.rb +121 -0
- data/spec/parser/free_space_spec.rb +130 -0
- data/spec/parser/groups_spec.rb +108 -0
- data/spec/parser/keep_spec.rb +6 -0
- data/spec/parser/posix_classes_spec.rb +8 -0
- data/spec/parser/properties_spec.rb +115 -0
- data/spec/parser/quantifiers_spec.rb +52 -0
- data/spec/parser/refcalls_spec.rb +112 -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/spec/parser/types_spec.rb +18 -0
- data/spec/scanner/all_spec.rb +18 -0
- data/spec/scanner/anchors_spec.rb +21 -0
- data/spec/scanner/conditionals_spec.rb +128 -0
- data/spec/scanner/delimiters_spec.rb +52 -0
- data/spec/scanner/errors_spec.rb +67 -0
- data/spec/scanner/escapes_spec.rb +53 -0
- data/spec/scanner/free_space_spec.rb +133 -0
- data/spec/scanner/groups_spec.rb +52 -0
- data/spec/scanner/keep_spec.rb +10 -0
- data/spec/scanner/literals_spec.rb +49 -0
- data/spec/scanner/meta_spec.rb +18 -0
- data/spec/scanner/properties_spec.rb +64 -0
- data/spec/scanner/quantifiers_spec.rb +20 -0
- data/spec/scanner/refcalls_spec.rb +36 -0
- data/spec/scanner/sets_spec.rb +102 -0
- data/spec/scanner/types_spec.rb +14 -0
- data/spec/spec_helper.rb +15 -0
- data/{test → spec}/support/runner.rb +9 -8
- data/spec/support/shared_examples.rb +77 -0
- data/{test → spec}/support/warning_extractor.rb +5 -7
- data/spec/syntax/syntax_spec.rb +48 -0
- data/spec/syntax/syntax_token_map_spec.rb +23 -0
- data/spec/syntax/versions/1.8.6_spec.rb +17 -0
- data/spec/syntax/versions/1.9.1_spec.rb +10 -0
- data/spec/syntax/versions/1.9.3_spec.rb +9 -0
- data/spec/syntax/versions/2.0.0_spec.rb +13 -0
- data/spec/syntax/versions/2.2.0_spec.rb +9 -0
- data/spec/syntax/versions/aliases_spec.rb +37 -0
- data/spec/token/token_spec.rb +85 -0
- metadata +151 -146
- 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_conditionals.rb +0 -127
- data/test/lexer/test_keep.rb +0 -24
- data/test/lexer/test_literals.rb +0 -130
- data/test/lexer/test_nesting.rb +0 -132
- 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_anchors.rb +0 -34
- 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 -133
- 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/parser/test_types.rb +0 -50
- data/test/scanner/test_all.rb +0 -38
- data/test/scanner/test_anchors.rb +0 -38
- data/test/scanner/test_conditionals.rb +0 -184
- data/test/scanner/test_errors.rb +0 -91
- data/test/scanner/test_escapes.rb +0 -56
- data/test/scanner/test_free_space.rb +0 -200
- data/test/scanner/test_groups.rb +0 -79
- data/test/scanner/test_keep.rb +0 -35
- data/test/scanner/test_literals.rb +0 -89
- data/test/scanner/test_meta.rb +0 -40
- data/test/scanner/test_properties.rb +0 -312
- data/test/scanner/test_quantifiers.rb +0 -37
- data/test/scanner/test_refcalls.rb +0 -52
- data/test/scanner/test_scripts.rb +0 -53
- data/test/scanner/test_sets.rb +0 -119
- 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
@@ -1,52 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ScannerRefCalls < Test::Unit::TestCase
|
4
|
-
tests = {
|
5
|
-
# Traditional numerical group back-reference
|
6
|
-
'(abc)\1' => [3, :backref, :number, '\1', 5, 7],
|
7
|
-
|
8
|
-
# Group back-references, named, numbered, and relative
|
9
|
-
'(?<X>abc)\k<X>' => [3, :backref, :name_ref_ab, '\k<X>', 9, 14],
|
10
|
-
"(?<X>abc)\\k'X'" => [3, :backref, :name_ref_sq, "\\k'X'", 9, 14],
|
11
|
-
|
12
|
-
'(abc)\k<1>' => [3, :backref, :number_ref_ab, '\k<1>', 5, 10],
|
13
|
-
"(abc)\\k'1'" => [3, :backref, :number_ref_sq, "\\k'1'", 5, 10],
|
14
|
-
|
15
|
-
'(abc)\k<-1>' => [3, :backref, :number_rel_ref_ab, '\k<-1>', 5, 11],
|
16
|
-
"(abc)\\k'-1'" => [3, :backref, :number_rel_ref_sq, "\\k'-1'", 5, 11],
|
17
|
-
|
18
|
-
# Sub-expression invocation, named, numbered, and relative
|
19
|
-
'(?<X>abc)\g<X>' => [3, :backref, :name_call_ab, '\g<X>', 9, 14],
|
20
|
-
"(?<X>abc)\\g'X'" => [3, :backref, :name_call_sq, "\\g'X'", 9, 14],
|
21
|
-
|
22
|
-
'(abc)\g<1>' => [3, :backref, :number_call_ab, '\g<1>', 5, 10],
|
23
|
-
"(abc)\\g'1'" => [3, :backref, :number_call_sq, "\\g'1'", 5, 10],
|
24
|
-
|
25
|
-
'(abc)\g<-1>' => [3, :backref, :number_rel_call_ab, '\g<-1>', 5, 11],
|
26
|
-
"(abc)\\g'-1'" => [3, :backref, :number_rel_call_sq, "\\g'-1'", 5, 11],
|
27
|
-
|
28
|
-
'\g<+1>(abc)' => [0, :backref, :number_rel_call_ab, '\g<+1>', 0, 6],
|
29
|
-
"\\g'+1'(abc)" => [0, :backref, :number_rel_call_sq, "\\g'+1'", 0, 6],
|
30
|
-
|
31
|
-
# Group back-references, with recursion level
|
32
|
-
'(?<X>abc)\k<X-0>' => [3, :backref, :name_recursion_ref_ab, '\k<X-0>', 9, 16],
|
33
|
-
"(?<X>abc)\\k'X-0'" => [3, :backref, :name_recursion_ref_sq, "\\k'X-0'", 9, 16],
|
34
|
-
|
35
|
-
'(abc)\k<1-0>' => [3, :backref, :number_recursion_ref_ab, '\k<1-0>', 5, 12],
|
36
|
-
"(abc)\\k'1-0'" => [3, :backref, :number_recursion_ref_sq, "\\k'1-0'", 5, 12],
|
37
|
-
}
|
38
|
-
|
39
|
-
tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
|
40
|
-
define_method "test_scanner_#{type}_#{token}_#{count}" do
|
41
|
-
tokens = RS.scan(pattern)
|
42
|
-
result = tokens[index]
|
43
|
-
|
44
|
-
assert_equal type, result[0]
|
45
|
-
assert_equal token, result[1]
|
46
|
-
assert_equal text, result[2]
|
47
|
-
assert_equal ts, result[3]
|
48
|
-
assert_equal te, result[4]
|
49
|
-
assert_equal text, pattern[ts, te]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ScannerUnicodeScripts < Test::Unit::TestCase
|
4
|
-
|
5
|
-
tests = {
|
6
|
-
'Aghb' => :caucasian_albanian,
|
7
|
-
'Caucasian Albanian' => :caucasian_albanian,
|
8
|
-
|
9
|
-
'Arab' => :arabic,
|
10
|
-
'Arabic' => :arabic,
|
11
|
-
|
12
|
-
'Armi' => :imperial_aramaic,
|
13
|
-
'Imperial Aramaic' => :imperial_aramaic,
|
14
|
-
|
15
|
-
'Egyp' => :egyptian_hieroglyphs,
|
16
|
-
'Egyptian Hieroglyphs' => :egyptian_hieroglyphs, # test whitespace
|
17
|
-
|
18
|
-
'Linb' => :linear_b,
|
19
|
-
'Linear-B' => :linear_b, # test dash
|
20
|
-
|
21
|
-
'Yiii' => :yi,
|
22
|
-
'Yi' => :yi,
|
23
|
-
|
24
|
-
'Zinh' => :inherited,
|
25
|
-
'Inherited' => :inherited,
|
26
|
-
'Qaai' => :inherited,
|
27
|
-
|
28
|
-
'Zyyy' => :common,
|
29
|
-
'Common' => :common,
|
30
|
-
|
31
|
-
'Zzzz' => :unknown,
|
32
|
-
'Unknown' => :unknown,
|
33
|
-
}
|
34
|
-
|
35
|
-
tests.each_with_index do |(property, token), count|
|
36
|
-
define_method "test_scanner_property_#{token}_#{count}" do
|
37
|
-
tokens = RS.scan("a\\p{#{property}}c")
|
38
|
-
result = tokens.at(1)
|
39
|
-
|
40
|
-
assert_equal :property, result[0]
|
41
|
-
assert_equal token, result[1]
|
42
|
-
end
|
43
|
-
|
44
|
-
define_method "test_scanner_nonproperty_#{token}_#{count}" do
|
45
|
-
tokens = RS.scan("a\\P{#{property}}c")
|
46
|
-
result = tokens.at(1)
|
47
|
-
|
48
|
-
assert_equal :nonproperty, result[0]
|
49
|
-
assert_equal token, result[1]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
data/test/scanner/test_sets.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path("../../helpers", __FILE__)
|
4
|
-
|
5
|
-
class ScannerSets < Test::Unit::TestCase
|
6
|
-
|
7
|
-
tests = {
|
8
|
-
'[a]' => [0, :set, :open, '[', 0, 1],
|
9
|
-
'[b]' => [2, :set, :close, ']', 2, 3],
|
10
|
-
'[^n]' => [1, :set, :negate, '^', 1, 2],
|
11
|
-
|
12
|
-
'[c]' => [1, :literal, :literal, 'c', 1, 2],
|
13
|
-
'[\b]' => [1, :escape, :backspace, '\b', 1, 3],
|
14
|
-
'[A\bX]' => [2, :escape, :backspace, '\b', 2, 4],
|
15
|
-
|
16
|
-
'[.]' => [1, :literal, :literal, '.', 1, 2],
|
17
|
-
'[?]' => [1, :literal, :literal, '?', 1, 2],
|
18
|
-
'[*]' => [1, :literal, :literal, '*', 1, 2],
|
19
|
-
'[+]' => [1, :literal, :literal, '+', 1, 2],
|
20
|
-
'[{]' => [1, :literal, :literal, '{', 1, 2],
|
21
|
-
'[}]' => [1, :literal, :literal, '}', 1, 2],
|
22
|
-
'[<]' => [1, :literal, :literal, '<', 1, 2],
|
23
|
-
'[>]' => [1, :literal, :literal, '>', 1, 2],
|
24
|
-
|
25
|
-
'[äöü]' => [2, :literal, :literal, 'ö', 3, 5],
|
26
|
-
|
27
|
-
'[\x20]' => [1, :escape, :hex, '\x20', 1, 5],
|
28
|
-
|
29
|
-
'[\.]' => [1, :escape, :dot, '\.', 1, 3],
|
30
|
-
'[\!]' => [1, :escape, :literal, '\!', 1, 3],
|
31
|
-
'[\#]' => [1, :escape, :literal, '\#', 1, 3],
|
32
|
-
'[\]]' => [1, :escape, :set_close, '\]', 1, 3],
|
33
|
-
'[\\\]' => [1, :escape, :backslash, '\\\\', 1, 3],
|
34
|
-
'[\A]' => [1, :escape, :literal, '\A', 1, 3],
|
35
|
-
'[\z]' => [1, :escape, :literal, '\z', 1, 3],
|
36
|
-
'[\g]' => [1, :escape, :literal, '\g', 1, 3],
|
37
|
-
'[\K]' => [1, :escape, :literal, '\K', 1, 3],
|
38
|
-
'[\c2]' => [1, :escape, :literal, '\c', 1, 3],
|
39
|
-
'[\B]' => [1, :escape, :literal, '\B', 1, 3],
|
40
|
-
'[a\-c]' => [2, :escape, :literal, '\-', 2, 4],
|
41
|
-
|
42
|
-
'[\d]' => [1, :type, :digit, '\d', 1, 3],
|
43
|
-
'[\da-z]' => [1, :type, :digit, '\d', 1, 3],
|
44
|
-
'[\D]' => [1, :type, :nondigit, '\D', 1, 3],
|
45
|
-
|
46
|
-
'[\h]' => [1, :type, :hex, '\h', 1, 3],
|
47
|
-
'[\H]' => [1, :type, :nonhex, '\H', 1, 3],
|
48
|
-
|
49
|
-
'[\s]' => [1, :type, :space, '\s', 1, 3],
|
50
|
-
'[\S]' => [1, :type, :nonspace, '\S', 1, 3],
|
51
|
-
|
52
|
-
'[\w]' => [1, :type, :word, '\w', 1, 3],
|
53
|
-
'[\W]' => [1, :type, :nonword, '\W', 1, 3],
|
54
|
-
|
55
|
-
'[\R]' => [1, :escape, :literal, '\R', 1, 3],
|
56
|
-
'[\X]' => [1, :escape, :literal, '\X', 1, 3],
|
57
|
-
|
58
|
-
'[a-b]' => [1, :literal, :literal, 'a', 1, 2],
|
59
|
-
'[a-c]' => [2, :set, :range, '-', 2, 3],
|
60
|
-
'[a-d]' => [3, :literal, :literal, 'd', 3, 4],
|
61
|
-
'[a-b-]' => [4, :literal, :literal, '-', 4, 6],
|
62
|
-
'[-a]' => [1, :literal, :literal, '-', 1, 2],
|
63
|
-
'[a-c^]' => [4, :literal, :literal, '^', 4, 5],
|
64
|
-
'[a-bd-f]' => [2, :set, :range, '-', 2, 3],
|
65
|
-
'[a-cd-f]' => [5, :set, :range, '-', 5, 6],
|
66
|
-
|
67
|
-
'[a[:digit:]c]' => [2, :posixclass, :digit, '[:digit:]', 2, 11],
|
68
|
-
'[[:digit:][:space:]]' => [2, :posixclass, :space, '[:space:]', 10, 19],
|
69
|
-
'[[:^digit:]]' => [1, :nonposixclass, :digit, '[:^digit:]', 1, 11],
|
70
|
-
|
71
|
-
'[a[.a-b.]c]' => [2, :set, :collation, '[.a-b.]', 2, 9],
|
72
|
-
'[a[=e=]c]' => [2, :set, :equivalent, '[=e=]', 2, 7],
|
73
|
-
|
74
|
-
'[a-d&&g-h]' => [4, :set, :intersection, '&&', 4, 6],
|
75
|
-
'[a&&]' => [2, :set, :intersection, '&&', 2, 4],
|
76
|
-
'[&&z]' => [1, :set, :intersection, '&&', 1, 3],
|
77
|
-
|
78
|
-
'[\\x20-\\x27]' => [1, :escape, :hex, '\x20', 1, 5],
|
79
|
-
'[\\x20-\\x28]' => [2, :set, :range, '-', 5, 6],
|
80
|
-
'[\\x20-\\x29]' => [3, :escape, :hex, '\x29', 6, 10],
|
81
|
-
|
82
|
-
'[a\p{digit}c]' => [2, :property, :digit, '\p{digit}', 2, 11],
|
83
|
-
'[a\P{digit}c]' => [2, :nonproperty, :digit, '\P{digit}', 2, 11],
|
84
|
-
'[a\p{^digit}c]' => [2, :nonproperty, :digit, '\p{^digit}', 2, 12],
|
85
|
-
'[a\P{^digit}c]' => [2, :property, :digit, '\P{^digit}', 2, 12],
|
86
|
-
|
87
|
-
'[a\p{ALPHA}c]' => [2, :property, :alpha, '\p{ALPHA}', 2, 11],
|
88
|
-
'[a\p{P}c]' => [2, :property, :punctuation,'\p{P}', 2, 7],
|
89
|
-
'[a\p{P}\P{P}c]' => [3, :nonproperty, :punctuation,'\P{P}', 7, 12],
|
90
|
-
|
91
|
-
'[a-w&&[^c-g]z]' => [5, :set, :open, '[', 6, 7],
|
92
|
-
'[a-w&&[^c-h]z]' => [6, :set, :negate, '^', 7, 8],
|
93
|
-
'[a-w&&[^c-i]z]' => [8, :set, :range, '-', 9, 10],
|
94
|
-
'[a-w&&[^c-j]z]' => [10,:set, :close, ']', 11, 12],
|
95
|
-
}
|
96
|
-
|
97
|
-
tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
|
98
|
-
define_method "test_scanner_#{type}_#{token}_in_'#{pattern}'_#{count}" do
|
99
|
-
tokens = RS.scan(pattern)
|
100
|
-
result = tokens.at(index)
|
101
|
-
|
102
|
-
assert_equal type, result[0]
|
103
|
-
assert_equal token, result[1]
|
104
|
-
assert_equal text, result[2]
|
105
|
-
assert_equal ts, result[3]
|
106
|
-
assert_equal te, result[4]
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_set_literal_encoding
|
111
|
-
text = RS.scan('[a]')[1][2].to_s
|
112
|
-
assert_equal 'a', text
|
113
|
-
assert_equal 'UTF-8', text.encoding.to_s
|
114
|
-
|
115
|
-
text = RS.scan('[😲]')[1][2].to_s
|
116
|
-
assert_equal '😲', text
|
117
|
-
assert_equal 'UTF-8', text.encoding.to_s
|
118
|
-
end
|
119
|
-
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
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class TestSyntaxTokenMap < Test::Unit::TestCase
|
4
|
-
def test_syntax_token_map_complete
|
5
|
-
map = Regexp::Syntax::Token::Map
|
6
|
-
latest_syntax = Regexp::Syntax.new 'ruby/2.9'
|
7
|
-
|
8
|
-
latest_syntax.features.each do |type, tokens|
|
9
|
-
tokens.each do |token|
|
10
|
-
assert map[type].include?(token),
|
11
|
-
"`#{type} #{token}` implemented but missing from Map"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_syntax_token_map_uniq
|
17
|
-
combinations = Regexp::Syntax::Token::Map.flat_map do |type, tokens|
|
18
|
-
tokens.map { |token| "#{type} #{token}" }
|
19
|
-
end
|
20
|
-
|
21
|
-
non_uniq = combinations.group_by { |str| str }.select { |_, v| v.count > 1 }
|
22
|
-
|
23
|
-
assert_empty non_uniq.keys
|
24
|
-
end
|
25
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.expand_path("../../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class TestSyntaxV1_8 < Test::Unit::TestCase
|
4
|
-
include Regexp::Syntax::Token
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@syntax = Regexp::Syntax.new 'ruby/1.8'
|
8
|
-
end
|
9
|
-
|
10
|
-
tests = {
|
11
|
-
implements: {
|
12
|
-
assertion: [Assertion::Lookahead].flatten,
|
13
|
-
backref: [:number],
|
14
|
-
escape: [
|
15
|
-
Escape::Basic + Escape::ASCII + Escape::Meta + Escape::Control
|
16
|
-
].flatten,
|
17
|
-
group: [Group::V1_8_6].flatten,
|
18
|
-
quantifier: [
|
19
|
-
Quantifier::Greedy + Quantifier::Reluctant +
|
20
|
-
Quantifier::Interval + Quantifier::IntervalReluctant
|
21
|
-
].flatten,
|
22
|
-
},
|
23
|
-
|
24
|
-
excludes: {
|
25
|
-
assertion: [Assertion::Lookbehind].flatten,
|
26
|
-
|
27
|
-
backref: [
|
28
|
-
Backreference::All - [:number] + SubexpressionCall::All
|
29
|
-
].flatten,
|
30
|
-
|
31
|
-
quantifier: [
|
32
|
-
Quantifier::Possessive
|
33
|
-
].flatten
|
34
|
-
},
|
35
|
-
}
|
36
|
-
|
37
|
-
tests.each do |method, types|
|
38
|
-
expected = method == :excludes ? false : true
|
39
|
-
|
40
|
-
types.each do |type, tokens|
|
41
|
-
if tokens.nil? or tokens.empty?
|
42
|
-
define_method "test_syntax_V1_8_#{method}_#{type}" do
|
43
|
-
assert_equal expected, @syntax.implements?(type, nil)
|
44
|
-
end
|
45
|
-
else
|
46
|
-
tokens.each do |token|
|
47
|
-
define_method "test_syntax_V1_8_#{method}_#{type}_#{token}" do
|
48
|
-
assert_equal expected, @syntax.implements?(type, token)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|