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
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
class ScannerEscapes < Test::Unit::TestCase
|
1
|
+
require 'spec_helper'
|
4
2
|
|
3
|
+
RSpec.describe('Escape scanning') do
|
5
4
|
tests = {
|
6
5
|
/c\at/ => [1, :escape, :bell, '\a', 1, 3],
|
7
6
|
|
@@ -41,16 +40,15 @@ class ScannerEscapes < Test::Unit::TestCase
|
|
41
40
|
}
|
42
41
|
|
43
42
|
tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
|
44
|
-
|
43
|
+
specify("scanner_#{type}_#{token}_#{count}") do
|
45
44
|
tokens = RS.scan(pattern)
|
46
45
|
result = tokens.at(index)
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
expect(result[0]).to eq type
|
48
|
+
expect(result[1]).to eq token
|
49
|
+
expect(result[2]).to eq text
|
50
|
+
expect(result[3]).to eq ts
|
51
|
+
expect(result[4]).to eq te
|
53
52
|
end
|
54
53
|
end
|
55
|
-
|
56
54
|
end
|
@@ -1,43 +1,38 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
regexp = %r{
|
3
|
+
RSpec.describe('FreeSpace scanning') do
|
4
|
+
specify('scan free space tokens') do
|
5
|
+
regexp = /
|
7
6
|
a
|
8
7
|
b ? c *
|
9
8
|
d {2,3}
|
10
9
|
e + | f +
|
11
|
-
|
10
|
+
/x
|
12
11
|
|
13
12
|
tokens = RS.scan(regexp)
|
14
13
|
|
15
14
|
0.upto(24) do |i|
|
16
15
|
if i.even?
|
17
|
-
|
18
|
-
|
16
|
+
expect(tokens[i][0]).to eq :free_space
|
17
|
+
expect(tokens[i][1]).to eq :whitespace
|
19
18
|
else
|
20
|
-
|
21
|
-
|
19
|
+
expect(tokens[i][0]).not_to eq :free_space
|
20
|
+
expect(tokens[i][1]).not_to eq :whitespace
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
|
-
[0, 2, 10, 14].each
|
26
|
-
assert_equal "\n ", tokens[i][2]
|
27
|
-
end
|
24
|
+
[0, 2, 10, 14].each { |i| expect(tokens[i][2]).to eq "\n " }
|
28
25
|
|
29
|
-
[4, 6, 8, 12].each
|
30
|
-
assert_equal ' ', tokens[i][2]
|
31
|
-
end
|
26
|
+
[4, 6, 8, 12].each { |i| expect(tokens[i][2]).to eq ' ' }
|
32
27
|
end
|
33
28
|
|
34
|
-
|
35
|
-
regexp =
|
29
|
+
specify('scan free space comments') do
|
30
|
+
regexp = /
|
36
31
|
a + # A + comment
|
37
32
|
b ? # B ? comment
|
38
33
|
c {2,3} # C {2,3} comment
|
39
34
|
d + | e + # D|E comment
|
40
|
-
|
35
|
+
/x
|
41
36
|
|
42
37
|
tokens = RS.scan(regexp)
|
43
38
|
|
@@ -49,17 +44,17 @@ class ScannerFreeSpace < Test::Unit::TestCase
|
|
49
44
|
].each do |index, type, token, text, ts, te|
|
50
45
|
result = tokens[index]
|
51
46
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
expect(result[0]).to eq type
|
48
|
+
expect(result[1]).to eq token
|
49
|
+
expect(result[2]).to eq text
|
50
|
+
expect(result[3]).to eq ts
|
51
|
+
expect(result[4]).to eq te
|
57
52
|
end
|
58
53
|
end
|
59
54
|
|
60
|
-
|
61
|
-
# Matches 'a bcdef g'
|
55
|
+
specify('scan free space inlined') do
|
62
56
|
regexp = /a b(?x:c d e)f g/
|
57
|
+
|
63
58
|
tokens = RS.scan(regexp)
|
64
59
|
|
65
60
|
[
|
@@ -75,17 +70,17 @@ class ScannerFreeSpace < Test::Unit::TestCase
|
|
75
70
|
].each do |index, type, token, text, ts, te|
|
76
71
|
result = tokens[index]
|
77
72
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
73
|
+
expect(result[0]).to eq type
|
74
|
+
expect(result[1]).to eq token
|
75
|
+
expect(result[2]).to eq text
|
76
|
+
expect(result[3]).to eq ts
|
77
|
+
expect(result[4]).to eq te
|
83
78
|
end
|
84
79
|
end
|
85
80
|
|
86
|
-
|
87
|
-
# Matches 'a bcde fghi j'
|
81
|
+
specify('scan free space nested') do
|
88
82
|
regexp = /a b(?x:c d(?-x:e f)g h)i j/
|
83
|
+
|
89
84
|
tokens = RS.scan(regexp)
|
90
85
|
|
91
86
|
[
|
@@ -105,17 +100,17 @@ class ScannerFreeSpace < Test::Unit::TestCase
|
|
105
100
|
].each do |index, type, token, text, ts, te|
|
106
101
|
result = tokens[index]
|
107
102
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
103
|
+
expect(result[0]).to eq type
|
104
|
+
expect(result[1]).to eq token
|
105
|
+
expect(result[2]).to eq text
|
106
|
+
expect(result[3]).to eq ts
|
107
|
+
expect(result[4]).to eq te
|
113
108
|
end
|
114
109
|
end
|
115
110
|
|
116
|
-
|
117
|
-
# Matches 'a bcde f g hi j'
|
111
|
+
specify('scan free space nested groups') do
|
118
112
|
regexp = /(a (b(?x: (c d) (?-x:(e f) )g) h)i j)/
|
113
|
+
|
119
114
|
tokens = RS.scan(regexp)
|
120
115
|
|
121
116
|
[
|
@@ -146,18 +141,19 @@ class ScannerFreeSpace < Test::Unit::TestCase
|
|
146
141
|
].each do |index, type, token, text, ts, te|
|
147
142
|
result = tokens[index]
|
148
143
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
144
|
+
expect(result[0]).to eq type
|
145
|
+
expect(result[1]).to eq token
|
146
|
+
expect(result[2]).to eq text
|
147
|
+
expect(result[3]).to eq ts
|
148
|
+
expect(result[4]).to eq te
|
154
149
|
end
|
155
150
|
end
|
156
151
|
|
157
|
-
|
158
|
-
# Matches 'a bcde f g hi j'
|
152
|
+
specify('scan free space switch groups') do
|
159
153
|
regexp = /(a (b((?x) (c d) ((?-x)(e f) )g) h)i j)/
|
154
|
+
|
160
155
|
tokens = RS.scan(regexp)
|
156
|
+
|
161
157
|
[
|
162
158
|
[ 0, :group, :capture, '(', 0, 1],
|
163
159
|
[ 1, :literal, :literal, 'a ', 1, 3],
|
@@ -190,11 +186,11 @@ class ScannerFreeSpace < Test::Unit::TestCase
|
|
190
186
|
].each do |index, type, token, text, ts, te|
|
191
187
|
result = tokens[index]
|
192
188
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
189
|
+
expect(result[0]).to eq type
|
190
|
+
expect(result[1]).to eq token
|
191
|
+
expect(result[2]).to eq text
|
192
|
+
expect(result[3]).to eq ts
|
193
|
+
expect(result[4]).to eq te
|
198
194
|
end
|
199
195
|
end
|
200
196
|
end
|
@@ -1,18 +1,7 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
class ScannerGroups < Test::Unit::TestCase
|
1
|
+
require 'spec_helper'
|
4
2
|
|
3
|
+
RSpec.describe('Group scanning') do
|
5
4
|
tests = {
|
6
|
-
# Options
|
7
|
-
'(?-mix:abc)' => [0, :group, :options, '(?-mix:', 0, 7],
|
8
|
-
'(?m-ix:abc)' => [0, :group, :options, '(?m-ix:', 0, 7],
|
9
|
-
'(?mi-x:abc)' => [0, :group, :options, '(?mi-x:', 0, 7],
|
10
|
-
'(?mix:abc)' => [0, :group, :options, '(?mix:', 0, 6],
|
11
|
-
'(?m:)' => [0, :group, :options, '(?m:', 0, 4],
|
12
|
-
'(?i:)' => [0, :group, :options, '(?i:', 0, 4],
|
13
|
-
'(?x:)' => [0, :group, :options, '(?x:', 0, 4],
|
14
|
-
'(?mix)' => [0, :group, :options_switch, '(?mix', 0, 5],
|
15
|
-
|
16
5
|
# Group types
|
17
6
|
'(?>abc)' => [0, :group, :atomic, '(?>', 0, 3],
|
18
7
|
'(abc)' => [0, :group, :capture, '(', 0, 1],
|
@@ -36,44 +25,47 @@ class ScannerGroups < Test::Unit::TestCase
|
|
36
25
|
'(?!abc)' => [0, :assertion, :nlookahead, '(?!', 0, 3],
|
37
26
|
'(?<=abc)' => [0, :assertion, :lookbehind, '(?<=', 0, 4],
|
38
27
|
'(?<!abc)' => [0, :assertion, :nlookbehind, '(?<!', 0, 4],
|
39
|
-
}
|
40
28
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
29
|
+
# Options
|
30
|
+
'(?-mix:abc)' => [0, :group, :options, '(?-mix:', 0, 7],
|
31
|
+
'(?m-ix:abc)' => [0, :group, :options, '(?m-ix:', 0, 7],
|
32
|
+
'(?mi-x:abc)' => [0, :group, :options, '(?mi-x:', 0, 7],
|
33
|
+
'(?mix:abc)' => [0, :group, :options, '(?mix:', 0, 6],
|
34
|
+
'(?m:)' => [0, :group, :options, '(?m:', 0, 4],
|
35
|
+
'(?i:)' => [0, :group, :options, '(?i:', 0, 4],
|
36
|
+
'(?x:)' => [0, :group, :options, '(?x:', 0, 4],
|
37
|
+
'(?mix)' => [0, :group, :options_switch, '(?mix', 0, 5],
|
38
|
+
'(?d-mix:abc)' => [0, :group, :options, '(?d-mix:', 0, 8],
|
39
|
+
'(?a-mix:abc)' => [0, :group, :options, '(?a-mix:', 0, 8],
|
40
|
+
'(?u-mix:abc)' => [0, :group, :options, '(?u-mix:', 0, 8],
|
41
|
+
'(?da-m:abc)' => [0, :group, :options, '(?da-m:', 0, 7],
|
42
|
+
'(?du-x:abc)' => [0, :group, :options, '(?du-x:', 0, 7],
|
43
|
+
'(?dau-i:abc)' => [0, :group, :options, '(?dau-i:', 0, 8],
|
44
|
+
'(?dau:abc)' => [0, :group, :options, '(?dau:', 0, 6],
|
45
|
+
'(?d:)' => [0, :group, :options, '(?d:', 0, 4],
|
46
|
+
'(?a:)' => [0, :group, :options, '(?a:', 0, 4],
|
47
|
+
'(?u:)' => [0, :group, :options, '(?u:', 0, 4],
|
48
|
+
'(?dau)' => [0, :group, :options_switch, '(?dau', 0, 5],
|
49
|
+
}
|
57
50
|
|
58
|
-
if
|
59
|
-
tests.merge!(
|
51
|
+
if ruby_version_at_least('2.4.1')
|
52
|
+
tests.merge!(
|
60
53
|
# New absence operator
|
61
54
|
'(?~abc)' => [0, :group, :absence, '(?~', 0, 3],
|
62
|
-
|
55
|
+
)
|
63
56
|
end
|
64
57
|
|
65
58
|
tests.each_with_index do |(pattern, (index, type, token, text, ts, te)), count|
|
66
|
-
|
59
|
+
specify("scanner_#{type}_#{token}_#{count}") do
|
67
60
|
tokens = RS.scan(pattern)
|
68
61
|
result = tokens[index]
|
69
62
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
63
|
+
expect(result[0]).to eq type
|
64
|
+
expect(result[1]).to eq token
|
65
|
+
expect(result[2]).to eq text
|
66
|
+
expect(result[3]).to eq ts
|
67
|
+
expect(result[4]).to eq te
|
68
|
+
expect(pattern[ts, te]).to eq text
|
76
69
|
end
|
77
70
|
end
|
78
|
-
|
79
71
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe('Keep scanning') do
|
4
|
+
specify('scan keep token') do
|
5
|
+
tokens = RS.scan(/ab\Kcd/)
|
6
|
+
result = tokens.at(1)
|
7
|
+
|
8
|
+
expect(result[0]).to eq :keep
|
9
|
+
expect(result[1]).to eq :mark
|
10
|
+
expect(result[2]).to eq '\\K'
|
11
|
+
expect(result[3]).to eq 2
|
12
|
+
expect(result[4]).to eq 4
|
13
|
+
end
|
14
|
+
|
15
|
+
specify('scan keep nested') do
|
16
|
+
tokens = RS.scan(/(a\Kb)|(c\\\Kd)ef/)
|
17
|
+
|
18
|
+
first = tokens.at(2)
|
19
|
+
second = tokens.at(9)
|
20
|
+
|
21
|
+
expect(first[0]).to eq :keep
|
22
|
+
expect(first[1]).to eq :mark
|
23
|
+
expect(first[2]).to eq '\\K'
|
24
|
+
expect(first[3]).to eq 2
|
25
|
+
expect(first[4]).to eq 4
|
26
|
+
|
27
|
+
expect(second[0]).to eq :keep
|
28
|
+
expect(second[1]).to eq :mark
|
29
|
+
expect(second[2]).to eq '\\K'
|
30
|
+
expect(second[3]).to eq 11
|
31
|
+
expect(second[4]).to eq 13
|
32
|
+
end
|
33
|
+
end
|
@@ -1,9 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require File.expand_path("../../helpers", __FILE__)
|
4
|
-
|
5
|
-
class ScannerUTF8 < Test::Unit::TestCase
|
1
|
+
require 'spec_helper'
|
6
2
|
|
3
|
+
RSpec.describe('UTF8 scanning') do
|
7
4
|
tests = {
|
8
5
|
# ascii, single byte characters
|
9
6
|
'a' => {
|
@@ -71,19 +68,18 @@ class ScannerUTF8 < Test::Unit::TestCase
|
|
71
68
|
}
|
72
69
|
|
73
70
|
tests.each_with_index do |(pattern, checks), count|
|
74
|
-
|
71
|
+
specify("scanner_utf8_runs_#{count}") do
|
75
72
|
tokens = RS.scan(pattern)
|
76
73
|
|
77
74
|
checks.each do |index, (type, token, text, ts, te)|
|
78
75
|
result = tokens[index]
|
79
76
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
expect(result[0]).to eq type
|
78
|
+
expect(result[1]).to eq token
|
79
|
+
expect(result[2]).to eq text
|
80
|
+
expect(result[3]).to eq ts
|
81
|
+
expect(result[4]).to eq te
|
85
82
|
end
|
86
83
|
end
|
87
84
|
end
|
88
|
-
|
89
85
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
class ScannerMeta < Test::Unit::TestCase
|
1
|
+
require 'spec_helper'
|
4
2
|
|
3
|
+
RSpec.describe('Meta scanning') do
|
5
4
|
tests = {
|
6
5
|
'abc??|def*+|ghi+' => {
|
7
6
|
0 => [:literal, :literal, 'abc', 0, 3],
|
@@ -22,19 +21,18 @@ class ScannerMeta < Test::Unit::TestCase
|
|
22
21
|
}
|
23
22
|
|
24
23
|
tests.each_with_index do |(pattern, checks), count|
|
25
|
-
|
24
|
+
specify("scanner_meta_alternation_#{count}") do
|
26
25
|
tokens = RS.scan(pattern)
|
27
26
|
|
28
27
|
checks.each do |index, (type, token, text, ts, te)|
|
29
28
|
result = tokens.at(index)
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
expect(result[0]).to eq type
|
31
|
+
expect(result[1]).to eq token
|
32
|
+
expect(result[2]).to eq text
|
33
|
+
expect(result[3]).to eq ts
|
34
|
+
expect(result[4]).to eq te
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
39
|
-
|
40
38
|
end
|
@@ -1,7 +1,6 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
class ScannerProperties < Test::Unit::TestCase
|
1
|
+
require 'spec_helper'
|
4
2
|
|
3
|
+
RSpec.describe('Property scanning') do
|
5
4
|
tests = {
|
6
5
|
'Alnum' => :alnum,
|
7
6
|
|
@@ -277,36 +276,32 @@ class ScannerProperties < Test::Unit::TestCase
|
|
277
276
|
}
|
278
277
|
|
279
278
|
tests.each_with_index do |(property, token), count|
|
280
|
-
|
279
|
+
specify("scan_property_#{token}_#{count}") do
|
281
280
|
tokens = RS.scan("a\\p{#{property}}c")
|
282
281
|
result = tokens.at(1)
|
283
|
-
|
284
|
-
|
285
|
-
assert_equal token, result[1]
|
282
|
+
expect(result[0]).to eq :property
|
283
|
+
expect(result[1]).to eq token
|
286
284
|
end
|
287
285
|
|
288
|
-
|
286
|
+
specify("scan_nonproperty_#{token}_#{count}") do
|
289
287
|
tokens = RS.scan("a\\P{#{property}}c")
|
290
288
|
result = tokens.at(1)
|
291
|
-
|
292
|
-
|
293
|
-
assert_equal token, result[1]
|
289
|
+
expect(result[0]).to eq :nonproperty
|
290
|
+
expect(result[1]).to eq token
|
294
291
|
end
|
295
292
|
|
296
|
-
|
293
|
+
specify("scan_caret_nonproperty_#{token}_#{count}") do
|
297
294
|
tokens = RS.scan("a\\p{^#{property}}c")
|
298
295
|
result = tokens.at(1)
|
299
|
-
|
300
|
-
|
301
|
-
assert_equal token, result[1]
|
296
|
+
expect(result[0]).to eq :nonproperty
|
297
|
+
expect(result[1]).to eq token
|
302
298
|
end
|
303
299
|
|
304
|
-
|
300
|
+
specify("scan_double_negated_property_#{token}_#{count}") do
|
305
301
|
tokens = RS.scan("a\\P{^#{property}}c")
|
306
302
|
result = tokens.at(1)
|
307
|
-
|
308
|
-
|
309
|
-
assert_equal token, result[1]
|
303
|
+
expect(result[0]).to eq :property
|
304
|
+
expect(result[1]).to eq token
|
310
305
|
end
|
311
306
|
end
|
312
307
|
end
|