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,89 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require File.expand_path("../../helpers", __FILE__)
|
4
|
-
|
5
|
-
class ScannerUTF8 < Test::Unit::TestCase
|
6
|
-
|
7
|
-
tests = {
|
8
|
-
# ascii, single byte characters
|
9
|
-
'a' => {
|
10
|
-
0 => [:literal, :literal, 'a', 0, 1],
|
11
|
-
},
|
12
|
-
|
13
|
-
'ab+' => {
|
14
|
-
0 => [:literal, :literal, 'ab', 0, 2],
|
15
|
-
1 => [:quantifier, :one_or_more, '+', 2, 3],
|
16
|
-
},
|
17
|
-
|
18
|
-
# 2 byte wide characters, Arabic
|
19
|
-
'aاbبcت' => {
|
20
|
-
0 => [:literal, :literal, 'aاbبcت', 0, 9],
|
21
|
-
},
|
22
|
-
|
23
|
-
'aاbبت?' => {
|
24
|
-
0 => [:literal, :literal, 'aاbبت', 0, 8],
|
25
|
-
1 => [:quantifier, :zero_or_one, '?', 8, 9],
|
26
|
-
},
|
27
|
-
|
28
|
-
'aا?bبcت+' => {
|
29
|
-
0 => [:literal, :literal, 'aا', 0, 3],
|
30
|
-
1 => [:quantifier, :zero_or_one, '?', 3, 4],
|
31
|
-
2 => [:literal, :literal, 'bبcت', 4, 10],
|
32
|
-
3 => [:quantifier, :one_or_more, '+', 10, 11],
|
33
|
-
},
|
34
|
-
|
35
|
-
'a(اbب+)cت?' => {
|
36
|
-
0 => [:literal, :literal, 'a', 0, 1],
|
37
|
-
1 => [:group, :capture, '(', 1, 2],
|
38
|
-
2 => [:literal, :literal, 'اbب', 2, 7],
|
39
|
-
3 => [:quantifier, :one_or_more, '+', 7, 8],
|
40
|
-
4 => [:group, :close, ')', 8, 9],
|
41
|
-
5 => [:literal, :literal, 'cت', 9, 12],
|
42
|
-
6 => [:quantifier, :zero_or_one, '?', 12, 13],
|
43
|
-
},
|
44
|
-
|
45
|
-
# 3 byte wide characters, Japanese
|
46
|
-
'ab?れます+cd' => {
|
47
|
-
0 => [:literal, :literal, 'ab', 0, 2],
|
48
|
-
1 => [:quantifier, :zero_or_one, '?', 2, 3],
|
49
|
-
2 => [:literal, :literal, 'れます', 3, 12],
|
50
|
-
3 => [:quantifier, :one_or_more, '+', 12, 13],
|
51
|
-
4 => [:literal, :literal, 'cd', 13, 15],
|
52
|
-
},
|
53
|
-
|
54
|
-
# 4 byte wide characters, Osmanya
|
55
|
-
'𐒀𐒁?𐒂ab+𐒃' => {
|
56
|
-
0 => [:literal, :literal, '𐒀𐒁', 0, 8],
|
57
|
-
1 => [:quantifier, :zero_or_one, '?', 8, 9],
|
58
|
-
2 => [:literal, :literal, '𐒂ab', 9, 15],
|
59
|
-
3 => [:quantifier, :one_or_more, '+', 15, 16],
|
60
|
-
4 => [:literal, :literal, '𐒃', 16, 20],
|
61
|
-
},
|
62
|
-
|
63
|
-
'mu𝄞?si*𝄫c+' => {
|
64
|
-
0 => [:literal, :literal, 'mu𝄞', 0, 6],
|
65
|
-
1 => [:quantifier, :zero_or_one, '?', 6, 7],
|
66
|
-
2 => [:literal, :literal, 'si', 7, 9],
|
67
|
-
3 => [:quantifier, :zero_or_more, '*', 9, 10],
|
68
|
-
4 => [:literal, :literal, '𝄫c', 10, 15],
|
69
|
-
5 => [:quantifier, :one_or_more, '+', 15, 16],
|
70
|
-
},
|
71
|
-
}
|
72
|
-
|
73
|
-
tests.each_with_index do |(pattern, checks), count|
|
74
|
-
define_method "test_scanner_utf8_runs_#{count}" do
|
75
|
-
tokens = RS.scan(pattern)
|
76
|
-
|
77
|
-
checks.each do |index, (type, token, text, ts, te)|
|
78
|
-
result = tokens[index]
|
79
|
-
|
80
|
-
assert_equal type, result[0]
|
81
|
-
assert_equal token, result[1]
|
82
|
-
assert_equal text, result[2]
|
83
|
-
assert_equal ts, result[3]
|
84
|
-
assert_equal te, result[4]
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
data/test/scanner/test_meta.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ScannerMeta < Test::Unit::TestCase
|
4
|
-
|
5
|
-
tests = {
|
6
|
-
'abc??|def*+|ghi+' => {
|
7
|
-
0 => [:literal, :literal, 'abc', 0, 3],
|
8
|
-
1 => [:quantifier, :zero_or_one_reluctant, '??', 3, 5],
|
9
|
-
2 => [:meta, :alternation, '|', 5, 6],
|
10
|
-
3 => [:literal, :literal, 'def', 6, 9],
|
11
|
-
4 => [:quantifier, :zero_or_more_possessive, '*+', 9, 11],
|
12
|
-
5 => [:meta, :alternation, '|', 11, 12],
|
13
|
-
},
|
14
|
-
|
15
|
-
'(a\|b)|(c|d)\|(e[|]f)' => {
|
16
|
-
2 => [:escape, :alternation, '\|', 2, 4],
|
17
|
-
5 => [:meta, :alternation, '|', 6, 7],
|
18
|
-
8 => [:meta, :alternation, '|', 9, 10],
|
19
|
-
11 => [:escape, :alternation, '\|', 12, 14],
|
20
|
-
15 => [:literal, :literal, '|', 17, 18],
|
21
|
-
},
|
22
|
-
}
|
23
|
-
|
24
|
-
tests.each_with_index do |(pattern, checks), count|
|
25
|
-
define_method "test_scanner_meta_alternation_#{count}" do
|
26
|
-
tokens = RS.scan(pattern)
|
27
|
-
|
28
|
-
checks.each do |index, (type, token, text, ts, te)|
|
29
|
-
result = tokens.at(index)
|
30
|
-
|
31
|
-
assert_equal type, result[0]
|
32
|
-
assert_equal token, result[1]
|
33
|
-
assert_equal text, result[2]
|
34
|
-
assert_equal ts, result[3]
|
35
|
-
assert_equal te, result[4]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
@@ -1,312 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ScannerProperties < Test::Unit::TestCase
|
4
|
-
|
5
|
-
tests = {
|
6
|
-
'Alnum' => :alnum,
|
7
|
-
|
8
|
-
'XPosixPunct' => :xposixpunct,
|
9
|
-
|
10
|
-
'Newline' => :newline,
|
11
|
-
|
12
|
-
'Any' => :any,
|
13
|
-
|
14
|
-
'Assigned' => :assigned,
|
15
|
-
|
16
|
-
'L' => :letter,
|
17
|
-
'Letter' => :letter,
|
18
|
-
|
19
|
-
'Lu' => :uppercase_letter,
|
20
|
-
'Uppercase_Letter' => :uppercase_letter,
|
21
|
-
|
22
|
-
'Ll' => :lowercase_letter,
|
23
|
-
'Lowercase_Letter' => :lowercase_letter,
|
24
|
-
|
25
|
-
'Lt' => :titlecase_letter,
|
26
|
-
'Titlecase_Letter' => :titlecase_letter,
|
27
|
-
|
28
|
-
'Lm' => :modifier_letter,
|
29
|
-
'Modifier_Letter' => :modifier_letter,
|
30
|
-
|
31
|
-
'Lo' => :other_letter,
|
32
|
-
'Other_Letter' => :other_letter,
|
33
|
-
|
34
|
-
'M' => :mark,
|
35
|
-
'Mark' => :mark,
|
36
|
-
|
37
|
-
'Mn' => :nonspacing_mark,
|
38
|
-
'Nonspacing_Mark' => :nonspacing_mark,
|
39
|
-
|
40
|
-
'Mc' => :spacing_mark,
|
41
|
-
'Spacing_Mark' => :spacing_mark,
|
42
|
-
|
43
|
-
'Me' => :enclosing_mark,
|
44
|
-
'Enclosing_Mark' => :enclosing_mark,
|
45
|
-
|
46
|
-
'N' => :number,
|
47
|
-
'Number' => :number,
|
48
|
-
|
49
|
-
'Nd' => :decimal_number,
|
50
|
-
'Decimal_Number' => :decimal_number,
|
51
|
-
|
52
|
-
'Nl' => :letter_number,
|
53
|
-
'Letter_Number' => :letter_number,
|
54
|
-
|
55
|
-
'No' => :other_number,
|
56
|
-
'Other_Number' => :other_number,
|
57
|
-
|
58
|
-
'P' => :punctuation,
|
59
|
-
'Punctuation' => :punctuation,
|
60
|
-
|
61
|
-
'Pc' => :connector_punctuation,
|
62
|
-
'Connector_Punctuation' => :connector_punctuation,
|
63
|
-
|
64
|
-
'Pd' => :dash_punctuation,
|
65
|
-
'Dash_Punctuation' => :dash_punctuation,
|
66
|
-
|
67
|
-
'Ps' => :open_punctuation,
|
68
|
-
'Open_Punctuation' => :open_punctuation,
|
69
|
-
|
70
|
-
'Pe' => :close_punctuation,
|
71
|
-
'Close_Punctuation' => :close_punctuation,
|
72
|
-
|
73
|
-
'Pi' => :initial_punctuation,
|
74
|
-
'Initial_Punctuation' => :initial_punctuation,
|
75
|
-
|
76
|
-
'Pf' => :final_punctuation,
|
77
|
-
'Final_Punctuation' => :final_punctuation,
|
78
|
-
|
79
|
-
'Po' => :other_punctuation,
|
80
|
-
'Other_Punctuation' => :other_punctuation,
|
81
|
-
|
82
|
-
'S' => :symbol,
|
83
|
-
'Symbol' => :symbol,
|
84
|
-
|
85
|
-
'Sm' => :math_symbol,
|
86
|
-
'Math_Symbol' => :math_symbol,
|
87
|
-
|
88
|
-
'Sc' => :currency_symbol,
|
89
|
-
'Currency_Symbol' => :currency_symbol,
|
90
|
-
|
91
|
-
'Sk' => :modifier_symbol,
|
92
|
-
'Modifier_Symbol' => :modifier_symbol,
|
93
|
-
|
94
|
-
'So' => :other_symbol,
|
95
|
-
'Other_Symbol' => :other_symbol,
|
96
|
-
|
97
|
-
'Z' => :separator,
|
98
|
-
'Separator' => :separator,
|
99
|
-
|
100
|
-
'Zs' => :space_separator,
|
101
|
-
'Space_Separator' => :space_separator,
|
102
|
-
|
103
|
-
'Zl' => :line_separator,
|
104
|
-
'Line_Separator' => :line_separator,
|
105
|
-
|
106
|
-
'Zp' => :paragraph_separator,
|
107
|
-
'Paragraph_Separator' => :paragraph_separator,
|
108
|
-
|
109
|
-
'C' => :other,
|
110
|
-
'Other' => :other,
|
111
|
-
|
112
|
-
'Cc' => :control,
|
113
|
-
'Control' => :control,
|
114
|
-
|
115
|
-
'Cf' => :format,
|
116
|
-
'Format' => :format,
|
117
|
-
|
118
|
-
'Cs' => :surrogate,
|
119
|
-
'Surrogate' => :surrogate,
|
120
|
-
|
121
|
-
'Co' => :private_use,
|
122
|
-
'Private_Use' => :private_use,
|
123
|
-
|
124
|
-
'Cn' => :unassigned,
|
125
|
-
'Unassigned' => :unassigned,
|
126
|
-
|
127
|
-
'Age=1.1' => :'age=1.1',
|
128
|
-
'Age=6.0' => :'age=6.0',
|
129
|
-
'Age=10.0' => :'age=10.0',
|
130
|
-
|
131
|
-
'ahex' => :ascii_hex_digit,
|
132
|
-
'ASCII_Hex_Digit' => :ascii_hex_digit,
|
133
|
-
|
134
|
-
'Alphabetic' => :alphabetic,
|
135
|
-
|
136
|
-
'Cased' => :cased,
|
137
|
-
|
138
|
-
'cwcf' => :changes_when_casefolded,
|
139
|
-
'Changes_When_Casefolded' => :changes_when_casefolded,
|
140
|
-
|
141
|
-
'cwcm' => :changes_when_casemapped,
|
142
|
-
'Changes_When_Casemapped' => :changes_when_casemapped,
|
143
|
-
|
144
|
-
'cwl' => :changes_when_lowercased,
|
145
|
-
'Changes_When_Lowercased' => :changes_when_lowercased,
|
146
|
-
|
147
|
-
'cwt' => :changes_when_titlecased,
|
148
|
-
'Changes_When_Titlecased' => :changes_when_titlecased,
|
149
|
-
|
150
|
-
'cwu' => :changes_when_uppercased,
|
151
|
-
'Changes_When_Uppercased' => :changes_when_uppercased,
|
152
|
-
|
153
|
-
'ci' => :case_ignorable,
|
154
|
-
'Case_Ignorable' => :case_ignorable,
|
155
|
-
|
156
|
-
'bidic' => :bidi_control,
|
157
|
-
'Bidi_Control' => :bidi_control,
|
158
|
-
|
159
|
-
'Dash' => :dash,
|
160
|
-
|
161
|
-
'dep' => :deprecated,
|
162
|
-
'Deprecated' => :deprecated,
|
163
|
-
|
164
|
-
'di' => :default_ignorable_code_point,
|
165
|
-
'Default_Ignorable_Code_Point' => :default_ignorable_code_point,
|
166
|
-
|
167
|
-
'dia' => :diacritic,
|
168
|
-
'Diacritic' => :diacritic,
|
169
|
-
|
170
|
-
'ext' => :extender,
|
171
|
-
'Extender' => :extender,
|
172
|
-
|
173
|
-
'grbase' => :grapheme_base,
|
174
|
-
'Grapheme_Base' => :grapheme_base,
|
175
|
-
|
176
|
-
'grext' => :grapheme_extend,
|
177
|
-
'Grapheme_Extend' => :grapheme_extend,
|
178
|
-
|
179
|
-
'grlink' => :grapheme_link,
|
180
|
-
'Grapheme_Link' => :grapheme_link,
|
181
|
-
|
182
|
-
'hex' => :hex_digit,
|
183
|
-
'Hex_Digit' => :hex_digit,
|
184
|
-
|
185
|
-
'Hyphen' => :hyphen,
|
186
|
-
|
187
|
-
'idc' => :id_continue,
|
188
|
-
'ID_Continue' => :id_continue,
|
189
|
-
|
190
|
-
'ideo' => :ideographic,
|
191
|
-
'Ideographic' => :ideographic,
|
192
|
-
|
193
|
-
'ids' => :id_start,
|
194
|
-
'ID_Start' => :id_start,
|
195
|
-
|
196
|
-
'idsb' => :ids_binary_operator,
|
197
|
-
'IDS_Binary_Operator' => :ids_binary_operator,
|
198
|
-
|
199
|
-
'idst' => :ids_trinary_operator,
|
200
|
-
'IDS_Trinary_Operator' => :ids_trinary_operator,
|
201
|
-
|
202
|
-
'joinc' => :join_control,
|
203
|
-
'Join_Control' => :join_control,
|
204
|
-
|
205
|
-
'loe' => :logical_order_exception,
|
206
|
-
'Logical_Order_Exception' => :logical_order_exception,
|
207
|
-
|
208
|
-
'Lowercase' => :lowercase,
|
209
|
-
|
210
|
-
'Math' => :math,
|
211
|
-
|
212
|
-
'nchar' => :noncharacter_code_point,
|
213
|
-
'Noncharacter_Code_Point' => :noncharacter_code_point,
|
214
|
-
|
215
|
-
'oalpha' => :other_alphabetic,
|
216
|
-
'Other_Alphabetic' => :other_alphabetic,
|
217
|
-
|
218
|
-
'odi' => :other_default_ignorable_code_point,
|
219
|
-
'Other_Default_Ignorable_Code_Point' => :other_default_ignorable_code_point,
|
220
|
-
|
221
|
-
'ogrext' => :other_grapheme_extend,
|
222
|
-
'Other_Grapheme_Extend' => :other_grapheme_extend,
|
223
|
-
|
224
|
-
'oidc' => :other_id_continue,
|
225
|
-
'Other_ID_Continue' => :other_id_continue,
|
226
|
-
|
227
|
-
'oids' => :other_id_start,
|
228
|
-
'Other_ID_Start' => :other_id_start,
|
229
|
-
|
230
|
-
'olower' => :other_lowercase,
|
231
|
-
'Other_Lowercase' => :other_lowercase,
|
232
|
-
|
233
|
-
'omath' => :other_math,
|
234
|
-
'Other_Math' => :other_math,
|
235
|
-
|
236
|
-
'oupper' => :other_uppercase,
|
237
|
-
'Other_Uppercase' => :other_uppercase,
|
238
|
-
|
239
|
-
'patsyn' => :pattern_syntax,
|
240
|
-
'Pattern_Syntax' => :pattern_syntax,
|
241
|
-
|
242
|
-
'patws' => :pattern_white_space,
|
243
|
-
'Pattern_Whitespace' => :pattern_white_space,
|
244
|
-
|
245
|
-
'qmark' => :quotation_mark,
|
246
|
-
'quotationmark' => :quotation_mark,
|
247
|
-
|
248
|
-
'radical' => :radical,
|
249
|
-
|
250
|
-
'ri' => :regional_indicator,
|
251
|
-
'Regional_Indicator' => :regional_indicator,
|
252
|
-
|
253
|
-
'sd' => :soft_dotted,
|
254
|
-
'Soft-Dotted' => :soft_dotted, # test dash spelling
|
255
|
-
|
256
|
-
'sterm' => :sentence_terminal,
|
257
|
-
|
258
|
-
'term' => :terminal_punctuation,
|
259
|
-
'Terminal_Punctuation' => :terminal_punctuation,
|
260
|
-
|
261
|
-
'uideo' => :unified_ideograph,
|
262
|
-
'Unified_Ideograph' => :unified_ideograph,
|
263
|
-
|
264
|
-
'Uppercase' => :uppercase,
|
265
|
-
|
266
|
-
'vs' => :variation_selector,
|
267
|
-
'Variation_Selector' => :variation_selector,
|
268
|
-
|
269
|
-
'wspace' => :white_space,
|
270
|
-
'whitespace' => :white_space,
|
271
|
-
|
272
|
-
'xids' => :xid_start,
|
273
|
-
'XID_Start' => :xid_start,
|
274
|
-
|
275
|
-
'xidc' => :xid_continue,
|
276
|
-
'XID_Continue' => :xid_continue,
|
277
|
-
}
|
278
|
-
|
279
|
-
tests.each_with_index do |(property, token), count|
|
280
|
-
define_method "test_scan_property_#{token}_#{count}" do
|
281
|
-
tokens = RS.scan("a\\p{#{property}}c")
|
282
|
-
result = tokens.at(1)
|
283
|
-
|
284
|
-
assert_equal :property, result[0]
|
285
|
-
assert_equal token, result[1]
|
286
|
-
end
|
287
|
-
|
288
|
-
define_method "test_scan_nonproperty_#{token}_#{count}" do
|
289
|
-
tokens = RS.scan("a\\P{#{property}}c")
|
290
|
-
result = tokens.at(1)
|
291
|
-
|
292
|
-
assert_equal :nonproperty, result[0]
|
293
|
-
assert_equal token, result[1]
|
294
|
-
end
|
295
|
-
|
296
|
-
define_method "test_scan_caret_nonproperty_#{token}_#{count}" do
|
297
|
-
tokens = RS.scan("a\\p{^#{property}}c")
|
298
|
-
result = tokens.at(1)
|
299
|
-
|
300
|
-
assert_equal :nonproperty, result[0]
|
301
|
-
assert_equal token, result[1]
|
302
|
-
end
|
303
|
-
|
304
|
-
define_method "test_scan_double_negated_property_#{token}_#{count}" do
|
305
|
-
tokens = RS.scan("a\\P{^#{property}}c")
|
306
|
-
result = tokens.at(1)
|
307
|
-
|
308
|
-
assert_equal :property, result[0]
|
309
|
-
assert_equal token, result[1]
|
310
|
-
end
|
311
|
-
end
|
312
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.expand_path("../../helpers", __FILE__)
|
2
|
-
|
3
|
-
class ScannerQuantifiers < Test::Unit::TestCase
|
4
|
-
|
5
|
-
tests = {
|
6
|
-
'a?' => [:quantifier, :zero_or_one, '?'],
|
7
|
-
'a??' => [:quantifier, :zero_or_one_reluctant, '??'],
|
8
|
-
'a?+' => [:quantifier, :zero_or_one_possessive, '?+'],
|
9
|
-
|
10
|
-
'a*' => [:quantifier, :zero_or_more, '*'],
|
11
|
-
'a*?' => [:quantifier, :zero_or_more_reluctant, '*?'],
|
12
|
-
'a*+' => [:quantifier, :zero_or_more_possessive, '*+'],
|
13
|
-
|
14
|
-
'a+' => [:quantifier, :one_or_more, '+'],
|
15
|
-
'a+?' => [:quantifier, :one_or_more_reluctant, '+?'],
|
16
|
-
'a++' => [:quantifier, :one_or_more_possessive, '++'],
|
17
|
-
|
18
|
-
'a{2}' => [:quantifier, :interval, '{2}'],
|
19
|
-
'a{2,}' => [:quantifier, :interval, '{2,}'],
|
20
|
-
'a{,2}' => [:quantifier, :interval, '{,2}'],
|
21
|
-
'a{2,4}' => [:quantifier, :interval, '{2,4}'],
|
22
|
-
}
|
23
|
-
|
24
|
-
tests.each_with_index do |(pattern, (type, token, text)), count|
|
25
|
-
name = (token == :interval ? "interval_#{count}" : token)
|
26
|
-
|
27
|
-
define_method "test_scan_#{type}_#{name}" do
|
28
|
-
tokens = RS.scan(pattern)
|
29
|
-
result = tokens.last
|
30
|
-
|
31
|
-
assert_equal type, result[0]
|
32
|
-
assert_equal token, result[1]
|
33
|
-
assert_equal text, result[2]
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|