@@ -8,27 +8,27 @@ class RegexpTest < Test::Unit::TestCase
8
8
##############################################################################
9
9
10
10
def test_named_captures_with_arrows
11
- assert_equal ( [ "foo" ] , YARP . named_captures ( "(?<foo>bar)" ) )
11
+ assert_equal ( [ "foo" ] , named_captures ( "(?<foo>bar)" ) )
12
12
end
13
13
14
14
def test_named_captures_with_single_quotes
15
- assert_equal ( [ "foo" ] , YARP . named_captures ( "(?'foo'bar)" ) )
15
+ assert_equal ( [ "foo" ] , named_captures ( "(?'foo'bar)" ) )
16
16
end
17
17
18
18
def test_nested_named_captures_with_arrows
19
- assert_equal ( [ "foo" , "bar" ] , YARP . named_captures ( "(?<foo>(?<bar>baz))" ) )
19
+ assert_equal ( [ "foo" , "bar" ] , named_captures ( "(?<foo>(?<bar>baz))" ) )
20
20
end
21
21
22
22
def test_nested_named_captures_with_single_quotes
23
- assert_equal ( [ "foo" , "bar" ] , YARP . named_captures ( "(?'foo'(?'bar'baz))" ) )
23
+ assert_equal ( [ "foo" , "bar" ] , named_captures ( "(?'foo'(?'bar'baz))" ) )
24
24
end
25
25
26
26
def test_allows_duplicate_named_captures
27
- assert_equal ( [ "foo" , "foo" ] , YARP . named_captures ( "(?<foo>bar)(?<foo>baz)" ) )
27
+ assert_equal ( [ "foo" , "foo" ] , named_captures ( "(?<foo>bar)(?<foo>baz)" ) )
28
28
end
29
29
30
30
def test_named_capture_inside_fake_range_quantifier
31
- assert_equal ( [ "foo" ] , YARP . named_captures ( "foo{1, (?<foo>2)}" ) )
31
+ assert_equal ( [ "foo" ] , named_captures ( "foo{1, (?<foo>2)}" ) )
32
32
end
33
33
34
34
##############################################################################
@@ -38,154 +38,160 @@ def test_named_capture_inside_fake_range_quantifier
38
38
##############################################################################
39
39
40
40
def test_alternation
41
- refute_nil ( YARP . named_captures ( "foo|bar" ) )
41
+ refute_nil ( named_captures ( "foo|bar" ) )
42
42
end
43
43
44
44
def test_anchors
45
- refute_nil ( YARP . named_captures ( "^foo$" ) )
45
+ refute_nil ( named_captures ( "^foo$" ) )
46
46
end
47
47
48
48
def test_any
49
- refute_nil ( YARP . named_captures ( "." ) )
49
+ refute_nil ( named_captures ( "." ) )
50
50
end
51
51
52
52
def test_posix_character_classes
53
- refute_nil ( YARP . named_captures ( "[[:digit:]]" ) )
53
+ refute_nil ( named_captures ( "[[:digit:]]" ) )
54
54
end
55
55
56
56
def test_negated_posix_character_classes
57
- refute_nil ( YARP . named_captures ( "[[:^digit:]]" ) )
57
+ refute_nil ( named_captures ( "[[:^digit:]]" ) )
58
58
end
59
59
60
60
def test_invalid_posix_character_classes_should_fall_back_to_regular_classes
61
- refute_nil ( YARP . named_captures ( "[[:foo]]" ) )
61
+ refute_nil ( named_captures ( "[[:foo]]" ) )
62
62
end
63
63
64
64
def test_character_sets
65
- refute_nil ( YARP . named_captures ( "[abc]" ) )
65
+ refute_nil ( named_captures ( "[abc]" ) )
66
66
end
67
67
68
68
def test_nested_character_sets
69
- refute_nil ( YARP . named_captures ( "[[abc]]" ) )
69
+ refute_nil ( named_captures ( "[[abc]]" ) )
70
70
end
71
71
72
72
def test_nested_character_sets_with_operators
73
- refute_nil ( YARP . named_captures ( "[[abc] && [def]]" ) )
73
+ refute_nil ( named_captures ( "[[abc] && [def]]" ) )
74
74
end
75
75
76
76
def test_named_capture_inside_nested_character_set
77
- assert_equal ( [ ] , YARP . named_captures ( "[foo (?<foo>bar)]" ) )
77
+ assert_equal ( [ ] , named_captures ( "[foo (?<foo>bar)]" ) )
78
78
end
79
79
80
80
def test_negated_character_sets
81
- refute_nil ( YARP . named_captures ( "[^abc]" ) )
81
+ refute_nil ( named_captures ( "[^abc]" ) )
82
82
end
83
83
84
84
def test_character_ranges
85
- refute_nil ( YARP . named_captures ( "[a-z]" ) )
85
+ refute_nil ( named_captures ( "[a-z]" ) )
86
86
end
87
87
88
88
def test_negated_character_ranges
89
- refute_nil ( YARP . named_captures ( "[^a-z]" ) )
89
+ refute_nil ( named_captures ( "[^a-z]" ) )
90
90
end
91
91
92
92
def test_fake_named_captures_inside_character_sets
93
- assert_equal ( [ ] , YARP . named_captures ( "[a-z(?<foo>)]" ) )
93
+ assert_equal ( [ ] , named_captures ( "[a-z(?<foo>)]" ) )
94
94
end
95
95
96
96
def test_fake_named_capture_inside_character_set_with_escaped_ending
97
- assert_equal ( [ ] , YARP . named_captures ( "[a-z\\ ](?<foo>)]" ) )
97
+ assert_equal ( [ ] , named_captures ( "[a-z\\ ](?<foo>)]" ) )
98
98
end
99
99
100
100
def test_comments
101
- refute_nil ( YARP . named_captures ( "(?#foo)" ) )
101
+ refute_nil ( named_captures ( "(?#foo)" ) )
102
102
end
103
103
104
104
def test_comments_with_escaped_parentheses
105
- refute_nil ( YARP . named_captures ( "(?#foo\\ )\\ ))" ) )
105
+ refute_nil ( named_captures ( "(?#foo\\ )\\ ))" ) )
106
106
end
107
107
108
108
def test_non_capturing_groups
109
- refute_nil ( YARP . named_captures ( "(?:foo)" ) )
109
+ refute_nil ( named_captures ( "(?:foo)" ) )
110
110
end
111
111
112
112
def test_positive_lookaheads
113
- refute_nil ( YARP . named_captures ( "(?=foo)" ) )
113
+ refute_nil ( named_captures ( "(?=foo)" ) )
114
114
end
115
115
116
116
def test_negative_lookaheads
117
- refute_nil ( YARP . named_captures ( "(?!foo)" ) )
117
+ refute_nil ( named_captures ( "(?!foo)" ) )
118
118
end
119
119
120
120
def test_positive_lookbehinds
121
- refute_nil ( YARP . named_captures ( "(?<=foo)" ) )
121
+ refute_nil ( named_captures ( "(?<=foo)" ) )
122
122
end
123
123
124
124
def test_negative_lookbehinds
125
- refute_nil ( YARP . named_captures ( "(?<!foo)" ) )
125
+ refute_nil ( named_captures ( "(?<!foo)" ) )
126
126
end
127
127
128
128
def test_atomic_groups
129
- refute_nil ( YARP . named_captures ( "(?>foo)" ) )
129
+ refute_nil ( named_captures ( "(?>foo)" ) )
130
130
end
131
131
132
132
def test_absence_operator
133
- refute_nil ( YARP . named_captures ( "(?~foo)" ) )
133
+ refute_nil ( named_captures ( "(?~foo)" ) )
134
134
end
135
135
136
136
def test_conditional_expression_with_index
137
- refute_nil ( YARP . named_captures ( "(?(1)foo)" ) )
137
+ refute_nil ( named_captures ( "(?(1)foo)" ) )
138
138
end
139
139
140
140
def test_conditional_expression_with_name
141
- refute_nil ( YARP . named_captures ( "(?(foo)bar)" ) )
141
+ refute_nil ( named_captures ( "(?(foo)bar)" ) )
142
142
end
143
143
144
144
def test_conditional_expression_with_group
145
- refute_nil ( YARP . named_captures ( "(?(<foo>)bar)" ) )
145
+ refute_nil ( named_captures ( "(?(<foo>)bar)" ) )
146
146
end
147
147
148
148
def test_options_on_groups
149
- refute_nil ( YARP . named_captures ( "(?imxdau:foo)" ) )
149
+ refute_nil ( named_captures ( "(?imxdau:foo)" ) )
150
150
end
151
151
152
152
def test_options_on_groups_with_invalid_options
153
- assert_nil ( YARP . named_captures ( "(?z:bar)" ) )
153
+ assert_nil ( named_captures ( "(?z:bar)" ) )
154
154
end
155
155
156
156
def test_options_on_groups_getting_turned_off
157
- refute_nil ( YARP . named_captures ( "(?-imx:foo)" ) )
157
+ refute_nil ( named_captures ( "(?-imx:foo)" ) )
158
158
end
159
159
160
160
def test_options_on_groups_some_getting_turned_on_some_getting_turned_off
161
- refute_nil ( YARP . named_captures ( "(?im-x:foo)" ) )
161
+ refute_nil ( named_captures ( "(?im-x:foo)" ) )
162
162
end
163
163
164
164
def test_star_quantifier
165
- refute_nil ( YARP . named_captures ( "foo*" ) )
165
+ refute_nil ( named_captures ( "foo*" ) )
166
166
end
167
167
168
168
def test_plus_quantifier
169
- refute_nil ( YARP . named_captures ( "foo+" ) )
169
+ refute_nil ( named_captures ( "foo+" ) )
170
170
end
171
171
172
172
def test_question_mark_quantifier
173
- refute_nil ( YARP . named_captures ( "foo?" ) )
173
+ refute_nil ( named_captures ( "foo?" ) )
174
174
end
175
175
176
176
def test_endless_range_quantifier
177
- refute_nil ( YARP . named_captures ( "foo{1,}" ) )
177
+ refute_nil ( named_captures ( "foo{1,}" ) )
178
178
end
179
179
180
180
def test_beginless_range_quantifier
181
- refute_nil ( YARP . named_captures ( "foo{,1}" ) )
181
+ refute_nil ( named_captures ( "foo{,1}" ) )
182
182
end
183
183
184
184
def test_range_quantifier
185
- refute_nil ( YARP . named_captures ( "foo{1,2}" ) )
185
+ refute_nil ( named_captures ( "foo{1,2}" ) )
186
186
end
187
187
188
188
def test_fake_range_quantifier_because_of_spaces
189
- refute_nil ( YARP . named_captures ( "foo{1, 2}" ) )
189
+ refute_nil ( named_captures ( "foo{1, 2}" ) )
190
+ end
191
+
192
+ private
193
+
194
+ def named_captures ( source )
195
+ YARP . const_get ( :Debug ) . named_captures ( source )
190
196
end
191
197
end
0 commit comments