@@ -76,21 +76,21 @@ macro_rules! replace(
76
76
assert_eq!( re. $which( $search, $replace) , String :: from_str( $result) ) ;
77
77
}
78
78
) ;
79
- )
79
+ ) ;
80
80
81
- replace ! ( rep_first, replace, r"\d" , "age: 26" , "Z" , "age: Z6" )
82
- replace ! ( rep_plus, replace, r"\d+" , "age: 26" , "Z" , "age: Z" )
83
- replace ! ( rep_all, replace_all, r"\d" , "age: 26" , "Z" , "age: ZZ" )
84
- replace ! ( rep_groups, replace, r"(\S+)\s+(\S+)" , "w1 w2" , "$2 $1" , "w2 w1" )
81
+ replace ! ( rep_first, replace, r"\d" , "age: 26" , "Z" , "age: Z6" ) ;
82
+ replace ! ( rep_plus, replace, r"\d+" , "age: 26" , "Z" , "age: Z" ) ;
83
+ replace ! ( rep_all, replace_all, r"\d" , "age: 26" , "Z" , "age: ZZ" ) ;
84
+ replace ! ( rep_groups, replace, r"(\S+)\s+(\S+)" , "w1 w2" , "$2 $1" , "w2 w1" ) ;
85
85
replace ! ( rep_double_dollar, replace,
86
- r"(\S+)\s+(\S+)" , "w1 w2" , "$2 $$1" , "w2 $1" )
86
+ r"(\S+)\s+(\S+)" , "w1 w2" , "$2 $$1" , "w2 $1" ) ;
87
87
replace ! ( rep_no_expand, replace,
88
- r"(\S+)\s+(\S+)" , "w1 w2" , NoExpand ( "$2 $1" ) , "$2 $1" )
88
+ r"(\S+)\s+(\S+)" , "w1 w2" , NoExpand ( "$2 $1" ) , "$2 $1" ) ;
89
89
replace ! ( rep_named, replace_all,
90
90
r"(?P<first>\S+)\s+(?P<last>\S+)(?P<space>\s*)" ,
91
- "w1 w2 w3 w4" , "$last $first$space" , "w2 w1 w4 w3" )
91
+ "w1 w2 w3 w4" , "$last $first$space" , "w2 w1 w4 w3" ) ;
92
92
replace ! ( rep_trim, replace_all, "^[ \t ]+|[ \t ]+$" , " \t trim me\t \t " ,
93
- "" , "trim me" )
93
+ "" , "trim me" ) ;
94
94
95
95
macro_rules! noparse(
96
96
( $name: ident, $re: expr) => (
@@ -103,45 +103,45 @@ macro_rules! noparse(
103
103
}
104
104
}
105
105
) ;
106
- )
107
-
108
- noparse ! ( fail_double_repeat, "a**" )
109
- noparse ! ( fail_no_repeat_arg, "*" )
110
- noparse ! ( fail_no_repeat_arg_begin, "^*" )
111
- noparse ! ( fail_incomplete_escape, "\\ " )
112
- noparse ! ( fail_class_incomplete, "[A-" )
113
- noparse ! ( fail_class_not_closed, "[A" )
114
- noparse ! ( fail_class_no_begin, r"[\A]" )
115
- noparse ! ( fail_class_no_end, r"[\z]" )
116
- noparse ! ( fail_class_no_boundary, r"[\b]" )
117
- noparse ! ( fail_open_paren, "(" )
118
- noparse ! ( fail_close_paren, ")" )
119
- noparse ! ( fail_invalid_range, "[a-Z]" )
120
- noparse ! ( fail_empty_capture_name, "(?P<>a)" )
121
- noparse ! ( fail_empty_capture_exp, "(?P<name>)" )
122
- noparse ! ( fail_bad_capture_name, "(?P<na-me>)" )
123
- noparse ! ( fail_bad_flag, "(?a)a" )
124
- noparse ! ( fail_empty_alt_before, "|a" )
125
- noparse ! ( fail_empty_alt_after, "a|" )
126
- noparse ! ( fail_counted_big_exact, "a{1001}" )
127
- noparse ! ( fail_counted_big_min, "a{1001,}" )
128
- noparse ! ( fail_counted_no_close, "a{1001" )
129
- noparse ! ( fail_unfinished_cap, "(?" )
130
- noparse ! ( fail_unfinished_escape, "\\ " )
131
- noparse ! ( fail_octal_digit, r"\8" )
132
- noparse ! ( fail_hex_digit, r"\xG0" )
133
- noparse ! ( fail_hex_short, r"\xF" )
134
- noparse ! ( fail_hex_long_digits, r"\x{fffg}" )
135
- noparse ! ( fail_flag_bad, "(?a)" )
136
- noparse ! ( fail_flag_empty, "(?)" )
137
- noparse ! ( fail_double_neg, "(?-i-i)" )
138
- noparse ! ( fail_neg_empty, "(?i-)" )
139
- noparse ! ( fail_empty_group, "()" )
140
- noparse ! ( fail_dupe_named, "(?P<a>.)(?P<a>.)" )
141
- noparse ! ( fail_range_end_no_class, "[a-[:lower:]]" )
142
- noparse ! ( fail_range_end_no_begin, r"[a-\A]" )
143
- noparse ! ( fail_range_end_no_end, r"[a-\z]" )
144
- noparse ! ( fail_range_end_no_boundary, r"[a-\b]" )
106
+ ) ;
107
+
108
+ noparse ! ( fail_double_repeat, "a**" ) ;
109
+ noparse ! ( fail_no_repeat_arg, "*" ) ;
110
+ noparse ! ( fail_no_repeat_arg_begin, "^*" ) ;
111
+ noparse ! ( fail_incomplete_escape, "\\ " ) ;
112
+ noparse ! ( fail_class_incomplete, "[A-" ) ;
113
+ noparse ! ( fail_class_not_closed, "[A" ) ;
114
+ noparse ! ( fail_class_no_begin, r"[\A]" ) ;
115
+ noparse ! ( fail_class_no_end, r"[\z]" ) ;
116
+ noparse ! ( fail_class_no_boundary, r"[\b]" ) ;
117
+ noparse ! ( fail_open_paren, "(" ) ;
118
+ noparse ! ( fail_close_paren, ")" ) ;
119
+ noparse ! ( fail_invalid_range, "[a-Z]" ) ;
120
+ noparse ! ( fail_empty_capture_name, "(?P<>a)" ) ;
121
+ noparse ! ( fail_empty_capture_exp, "(?P<name>)" ) ;
122
+ noparse ! ( fail_bad_capture_name, "(?P<na-me>)" ) ;
123
+ noparse ! ( fail_bad_flag, "(?a)a" ) ;
124
+ noparse ! ( fail_empty_alt_before, "|a" ) ;
125
+ noparse ! ( fail_empty_alt_after, "a|" ) ;
126
+ noparse ! ( fail_counted_big_exact, "a{1001}" ) ;
127
+ noparse ! ( fail_counted_big_min, "a{1001,}" ) ;
128
+ noparse ! ( fail_counted_no_close, "a{1001" ) ;
129
+ noparse ! ( fail_unfinished_cap, "(?" ) ;
130
+ noparse ! ( fail_unfinished_escape, "\\ " ) ;
131
+ noparse ! ( fail_octal_digit, r"\8" ) ;
132
+ noparse ! ( fail_hex_digit, r"\xG0" ) ;
133
+ noparse ! ( fail_hex_short, r"\xF" ) ;
134
+ noparse ! ( fail_hex_long_digits, r"\x{fffg}" ) ;
135
+ noparse ! ( fail_flag_bad, "(?a)" ) ;
136
+ noparse ! ( fail_flag_empty, "(?)" ) ;
137
+ noparse ! ( fail_double_neg, "(?-i-i)" ) ;
138
+ noparse ! ( fail_neg_empty, "(?i-)" ) ;
139
+ noparse ! ( fail_empty_group, "()" ) ;
140
+ noparse ! ( fail_dupe_named, "(?P<a>.)(?P<a>.)" ) ;
141
+ noparse ! ( fail_range_end_no_class, "[a-[:lower:]]" ) ;
142
+ noparse ! ( fail_range_end_no_begin, r"[a-\A]" ) ;
143
+ noparse ! ( fail_range_end_no_end, r"[a-\z]" ) ;
144
+ noparse ! ( fail_range_end_no_boundary, r"[a-\b]" ) ;
145
145
146
146
macro_rules! mat(
147
147
( $name: ident, $re: expr, $text: expr, $( $loc: tt) +) => (
@@ -166,78 +166,78 @@ macro_rules! mat(
166
166
}
167
167
}
168
168
) ;
169
- )
169
+ ) ;
170
170
171
171
// Some crazy expressions from regular-expressions.info.
172
172
mat ! ( match_ranges,
173
173
r"\b(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b" ,
174
- "num: 255" , Some ( ( 5 , 8 ) ) )
174
+ "num: 255" , Some ( ( 5 , 8 ) ) ) ;
175
175
mat ! ( match_ranges_not,
176
176
r"\b(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b" ,
177
- "num: 256" , None )
178
- mat ! ( match_float1, r"[-+]?[0-9]*\.?[0-9]+" , "0.1" , Some ( ( 0 , 3 ) ) )
179
- mat ! ( match_float2, r"[-+]?[0-9]*\.?[0-9]+" , "0.1.2" , Some ( ( 0 , 3 ) ) )
180
- mat ! ( match_float3, r"[-+]?[0-9]*\.?[0-9]+" , "a1.2" , Some ( ( 1 , 4 ) ) )
181
- mat ! ( match_float4, r"^[-+]?[0-9]*\.?[0-9]+$" , "1.a" , None )
177
+ "num: 256" , None ) ;
178
+ mat ! ( match_float1, r"[-+]?[0-9]*\.?[0-9]+" , "0.1" , Some ( ( 0 , 3 ) ) ) ;
179
+ mat ! ( match_float2, r"[-+]?[0-9]*\.?[0-9]+" , "0.1.2" , Some ( ( 0 , 3 ) ) ) ;
180
+ mat ! ( match_float3, r"[-+]?[0-9]*\.?[0-9]+" , "a1.2" , Some ( ( 1 , 4 ) ) ) ;
181
+ mat ! ( match_float4, r"^[-+]?[0-9]*\.?[0-9]+$" , "1.a" , None ) ;
182
182
mat ! ( match_email, r"(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b" ,
183
- "mine is jam.slam@gmail.com " , Some ( ( 8 , 26 ) ) )
183
+ "mine is jam.slam@gmail.com " , Some ( ( 8 , 26 ) ) ) ;
184
184
mat ! ( match_email_not, r"(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b" ,
185
- "mine is jam.slam@gmail " , None )
185
+ "mine is jam.slam@gmail " , None ) ;
186
186
mat ! ( match_email_big, r"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" ,
187
- "mine is jam.slam@gmail.com " , Some ( ( 8 , 26 ) ) )
187
+ "mine is jam.slam@gmail.com " , Some ( ( 8 , 26 ) ) ) ;
188
188
mat ! ( match_date1,
189
189
r"^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$" ,
190
- "1900-01-01" , Some ( ( 0 , 10 ) ) )
190
+ "1900-01-01" , Some ( ( 0 , 10 ) ) ) ;
191
191
mat ! ( match_date2,
192
192
r"^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$" ,
193
- "1900-00-01" , None )
193
+ "1900-00-01" , None ) ;
194
194
mat ! ( match_date3,
195
195
r"^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$" ,
196
- "1900-13-01" , None )
196
+ "1900-13-01" , None ) ;
197
197
198
198
// Exercise the flags.
199
- mat ! ( match_flag_case, "(?i)abc" , "ABC" , Some ( ( 0 , 3 ) ) )
200
- mat ! ( match_flag_weird_case, "(?i)a(?-i)bc" , "Abc" , Some ( ( 0 , 3 ) ) )
201
- mat ! ( match_flag_weird_case_not, "(?i)a(?-i)bc" , "ABC" , None )
202
- mat ! ( match_flag_case_dotnl, "(?is)a." , "A\n " , Some ( ( 0 , 2 ) ) )
203
- mat ! ( match_flag_case_dotnl_toggle, "(?is)a.(?-is)a." , "A\n ab" , Some ( ( 0 , 4 ) ) )
204
- mat ! ( match_flag_case_dotnl_toggle_not, "(?is)a.(?-is)a." , "A\n a\n " , None )
205
- mat ! ( match_flag_case_dotnl_toggle_ok, "(?is)a.(?-is:a.)?" , "A\n a\n " , Some ( ( 0 , 2 ) ) )
206
- mat ! ( match_flag_multi, "(?m)(?:^\\ d+$\n ?)+" , "123\n 456\n 789" , Some ( ( 0 , 11 ) ) )
207
- mat ! ( match_flag_ungreedy, "(?U)a+" , "aa" , Some ( ( 0 , 1 ) ) )
208
- mat ! ( match_flag_ungreedy_greedy, "(?U)a+?" , "aa" , Some ( ( 0 , 2 ) ) )
209
- mat ! ( match_flag_ungreedy_noop, "(?U)(?-U)a+" , "aa" , Some ( ( 0 , 2 ) ) )
199
+ mat ! ( match_flag_case, "(?i)abc" , "ABC" , Some ( ( 0 , 3 ) ) ) ;
200
+ mat ! ( match_flag_weird_case, "(?i)a(?-i)bc" , "Abc" , Some ( ( 0 , 3 ) ) ) ;
201
+ mat ! ( match_flag_weird_case_not, "(?i)a(?-i)bc" , "ABC" , None ) ;
202
+ mat ! ( match_flag_case_dotnl, "(?is)a." , "A\n " , Some ( ( 0 , 2 ) ) ) ;
203
+ mat ! ( match_flag_case_dotnl_toggle, "(?is)a.(?-is)a." , "A\n ab" , Some ( ( 0 , 4 ) ) ) ;
204
+ mat ! ( match_flag_case_dotnl_toggle_not, "(?is)a.(?-is)a." , "A\n a\n " , None ) ;
205
+ mat ! ( match_flag_case_dotnl_toggle_ok, "(?is)a.(?-is:a.)?" , "A\n a\n " , Some ( ( 0 , 2 ) ) ) ;
206
+ mat ! ( match_flag_multi, "(?m)(?:^\\ d+$\n ?)+" , "123\n 456\n 789" , Some ( ( 0 , 11 ) ) ) ;
207
+ mat ! ( match_flag_ungreedy, "(?U)a+" , "aa" , Some ( ( 0 , 1 ) ) ) ;
208
+ mat ! ( match_flag_ungreedy_greedy, "(?U)a+?" , "aa" , Some ( ( 0 , 2 ) ) ) ;
209
+ mat ! ( match_flag_ungreedy_noop, "(?U)(?-U)a+" , "aa" , Some ( ( 0 , 2 ) ) ) ;
210
210
211
211
// Some Unicode tests.
212
212
// A couple of these are commented out because something in the guts of macro expansion is creating
213
213
// invalid byte strings.
214
214
//mat!(uni_literal, r"Ⅰ", "Ⅰ", Some((0, 3)))
215
- mat ! ( uni_one, r"\pN" , "Ⅰ" , Some ( ( 0 , 3 ) ) )
216
- mat ! ( uni_mixed, r"\pN+" , "Ⅰ1Ⅱ2" , Some ( ( 0 , 8 ) ) )
217
- mat ! ( uni_not, r"\PN+" , "abⅠ" , Some ( ( 0 , 2 ) ) )
218
- mat ! ( uni_not_class, r"[\PN]+" , "abⅠ" , Some ( ( 0 , 2 ) ) )
219
- mat ! ( uni_not_class_neg, r"[^\PN]+" , "abⅠ" , Some ( ( 2 , 5 ) ) )
220
- mat ! ( uni_case, r"(?i)Δ" , "δ" , Some ( ( 0 , 2 ) ) )
215
+ mat ! ( uni_one, r"\pN" , "Ⅰ" , Some ( ( 0 , 3 ) ) ) ;
216
+ mat ! ( uni_mixed, r"\pN+" , "Ⅰ1Ⅱ2" , Some ( ( 0 , 8 ) ) ) ;
217
+ mat ! ( uni_not, r"\PN+" , "abⅠ" , Some ( ( 0 , 2 ) ) ) ;
218
+ mat ! ( uni_not_class, r"[\PN]+" , "abⅠ" , Some ( ( 0 , 2 ) ) ) ;
219
+ mat ! ( uni_not_class_neg, r"[^\PN]+" , "abⅠ" , Some ( ( 2 , 5 ) ) ) ;
220
+ mat ! ( uni_case, r"(?i)Δ" , "δ" , Some ( ( 0 , 2 ) ) ) ;
221
221
//mat!(uni_case_not, r"Δ", "δ", None)
222
- mat ! ( uni_case_upper, r"\p{Lu}+" , "ΛΘΓΔα" , Some ( ( 0 , 8 ) ) )
223
- mat ! ( uni_case_upper_nocase_flag, r"(?i)\p{Lu}+" , "ΛΘΓΔα" , Some ( ( 0 , 10 ) ) )
224
- mat ! ( uni_case_upper_nocase, r"\p{L}+" , "ΛΘΓΔα" , Some ( ( 0 , 10 ) ) )
225
- mat ! ( uni_case_lower, r"\p{Ll}+" , "ΛΘΓΔα" , Some ( ( 8 , 10 ) ) )
222
+ mat ! ( uni_case_upper, r"\p{Lu}+" , "ΛΘΓΔα" , Some ( ( 0 , 8 ) ) ) ;
223
+ mat ! ( uni_case_upper_nocase_flag, r"(?i)\p{Lu}+" , "ΛΘΓΔα" , Some ( ( 0 , 10 ) ) ) ;
224
+ mat ! ( uni_case_upper_nocase, r"\p{L}+" , "ΛΘΓΔα" , Some ( ( 0 , 10 ) ) ) ;
225
+ mat ! ( uni_case_lower, r"\p{Ll}+" , "ΛΘΓΔα" , Some ( ( 8 , 10 ) ) ) ;
226
226
227
227
// Test the Unicode friendliness of Perl character classes.
228
- mat ! ( uni_perl_w, r"\w+" , "dδd" , Some ( ( 0 , 4 ) ) )
229
- mat ! ( uni_perl_w_not, r"\w+" , "⥡" , None )
230
- mat ! ( uni_perl_w_neg, r"\W+" , "⥡" , Some ( ( 0 , 3 ) ) )
231
- mat ! ( uni_perl_d, r"\d+" , "1२३9" , Some ( ( 0 , 8 ) ) )
232
- mat ! ( uni_perl_d_not, r"\d+" , "Ⅱ" , None )
233
- mat ! ( uni_perl_d_neg, r"\D+" , "Ⅱ" , Some ( ( 0 , 3 ) ) )
234
- mat ! ( uni_perl_s, r"\s+" , " " , Some ( ( 0 , 3 ) ) )
235
- mat ! ( uni_perl_s_not, r"\s+" , "☃" , None )
236
- mat ! ( uni_perl_s_neg, r"\S+" , "☃" , Some ( ( 0 , 3 ) ) )
228
+ mat ! ( uni_perl_w, r"\w+" , "dδd" , Some ( ( 0 , 4 ) ) ) ;
229
+ mat ! ( uni_perl_w_not, r"\w+" , "⥡" , None ) ;
230
+ mat ! ( uni_perl_w_neg, r"\W+" , "⥡" , Some ( ( 0 , 3 ) ) ) ;
231
+ mat ! ( uni_perl_d, r"\d+" , "1२३9" , Some ( ( 0 , 8 ) ) ) ;
232
+ mat ! ( uni_perl_d_not, r"\d+" , "Ⅱ" , None ) ;
233
+ mat ! ( uni_perl_d_neg, r"\D+" , "Ⅱ" , Some ( ( 0 , 3 ) ) ) ;
234
+ mat ! ( uni_perl_s, r"\s+" , " " , Some ( ( 0 , 3 ) ) ) ;
235
+ mat ! ( uni_perl_s_not, r"\s+" , "☃" , None ) ;
236
+ mat ! ( uni_perl_s_neg, r"\S+" , "☃" , Some ( ( 0 , 3 ) ) ) ;
237
237
238
238
// And do the same for word boundaries.
239
- mat ! ( uni_boundary_none, r"\d\b" , "6δ" , None )
240
- mat ! ( uni_boundary_ogham, r"\d\b" , "6 " , Some ( ( 0 , 1 ) ) )
239
+ mat ! ( uni_boundary_none, r"\d\b" , "6δ" , None ) ;
240
+ mat ! ( uni_boundary_ogham, r"\d\b" , "6 " , Some ( ( 0 , 1 ) ) ) ;
241
241
242
242
// A whole mess of tests from Glenn Fowler's regex test suite.
243
243
// Generated by the 'src/etc/regex-match-tests' program.
0 commit comments