Skip to content

Commit 986429f

Browse files
committed
Fix macro expansions in the hand-written tests ...
1 parent 4e5b9fb commit 986429f

File tree

3 files changed

+107
-107
lines changed

3 files changed

+107
-107
lines changed

tests/bench.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ macro_rules! throughput(
146146
b.iter(|| if $regex.is_match(text.as_slice()) { panic!("match") });
147147
}
148148
);
149-
)
149+
);
150150

151151
fn easy0() -> Regex { regex!("ABCDEFGHIJKLMNOPQRSTUVWXYZ$") }
152152
fn easy1() -> Regex { regex!("A[AB]B[BC]C[CD]D[DE]E[EF]F[FG]G[GH]H[HI]I[IJ]J$") }
@@ -165,18 +165,18 @@ fn gen_text(n: uint) -> String {
165165
String::from_utf8(bytes).unwrap()
166166
}
167167

168-
throughput!(easy0_32, easy0(), 32)
169-
throughput!(easy0_1K, easy0(), 1<<10)
170-
throughput!(easy0_32K, easy0(), 32<<10)
168+
throughput!(easy0_32, easy0(), 32);
169+
throughput!(easy0_1K, easy0(), 1<<10);
170+
throughput!(easy0_32K, easy0(), 32<<10);
171171

172-
throughput!(easy1_32, easy1(), 32)
173-
throughput!(easy1_1K, easy1(), 1<<10)
174-
throughput!(easy1_32K, easy1(), 32<<10)
172+
throughput!(easy1_32, easy1(), 32);
173+
throughput!(easy1_1K, easy1(), 1<<10);
174+
throughput!(easy1_32K, easy1(), 32<<10);
175175

176-
throughput!(medium_32, medium(), 32)
177-
throughput!(medium_1K, medium(), 1<<10)
178-
throughput!(medium_32K,medium(), 32<<10)
176+
throughput!(medium_32, medium(), 32);
177+
throughput!(medium_1K, medium(), 1<<10);
178+
throughput!(medium_32K,medium(), 32<<10);
179179

180-
throughput!(hard_32, hard(), 32)
181-
throughput!(hard_1K, hard(), 1<<10)
182-
throughput!(hard_32K,hard(), 32<<10)
180+
throughput!(hard_32, hard(), 32);
181+
throughput!(hard_1K, hard(), 1<<10);
182+
throughput!(hard_32K,hard(), 32<<10);

tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ macro_rules! regex(
3232
Err(err) => panic!("{}", err),
3333
}
3434
);
35-
)
35+
);
3636

3737
#[path = "bench.rs"]
3838
mod dynamic_bench;

tests/tests.rs

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ macro_rules! replace(
7676
assert_eq!(re.$which($search, $replace), String::from_str($result));
7777
}
7878
);
79-
)
79+
);
8080

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");
8585
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");
8787
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");
8989
replace!(rep_named, replace_all,
9090
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");
9292
replace!(rep_trim, replace_all, "^[ \t]+|[ \t]+$", " \t trim me\t \t",
93-
"", "trim me")
93+
"", "trim me");
9494

9595
macro_rules! noparse(
9696
($name:ident, $re:expr) => (
@@ -103,45 +103,45 @@ macro_rules! noparse(
103103
}
104104
}
105105
);
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]");
145145

146146
macro_rules! mat(
147147
($name:ident, $re:expr, $text:expr, $($loc:tt)+) => (
@@ -166,78 +166,78 @@ macro_rules! mat(
166166
}
167167
}
168168
);
169-
)
169+
);
170170

171171
// Some crazy expressions from regular-expressions.info.
172172
mat!(match_ranges,
173173
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)));
175175
mat!(match_ranges_not,
176176
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);
182182
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)));
184184
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);
186186
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)));
188188
mat!(match_date1,
189189
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)));
191191
mat!(match_date2,
192192
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);
194194
mat!(match_date3,
195195
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);
197197

198198
// 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\nab", Some((0, 4)))
204-
mat!(match_flag_case_dotnl_toggle_not, "(?is)a.(?-is)a.", "A\na\n", None)
205-
mat!(match_flag_case_dotnl_toggle_ok, "(?is)a.(?-is:a.)?", "A\na\n", Some((0, 2)))
206-
mat!(match_flag_multi, "(?m)(?:^\\d+$\n?)+", "123\n456\n789", 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\nab", Some((0, 4)));
204+
mat!(match_flag_case_dotnl_toggle_not, "(?is)a.(?-is)a.", "A\na\n", None);
205+
mat!(match_flag_case_dotnl_toggle_ok, "(?is)a.(?-is:a.)?", "A\na\n", Some((0, 2)));
206+
mat!(match_flag_multi, "(?m)(?:^\\d+$\n?)+", "123\n456\n789", 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)));
210210

211211
// Some Unicode tests.
212212
// A couple of these are commented out because something in the guts of macro expansion is creating
213213
// invalid byte strings.
214214
//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)));
221221
//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)));
226226

227227
// 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)));
237237

238238
// 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)));
241241

242242
// A whole mess of tests from Glenn Fowler's regex test suite.
243243
// Generated by the 'src/etc/regex-match-tests' program.

0 commit comments

Comments
 (0)