]> git.proxmox.com Git - rustc.git/blob - vendor/regex-0.2.11/tests/regression.rs
New upstream version 1.33.0+dfsg1
[rustc.git] / vendor / regex-0.2.11 / tests / regression.rs
1 // See: https://github.com/rust-lang/regex/issues/48
2 #[test]
3 fn invalid_regexes_no_crash() {
4 assert!(regex_new!("(*)").is_err());
5 assert!(regex_new!("(?:?)").is_err());
6 assert!(regex_new!("(?)").is_err());
7 assert!(regex_new!("*").is_err());
8 }
9
10 // See: https://github.com/rust-lang/regex/issues/98
11 #[test]
12 fn regression_many_repeat_stack_overflow() {
13 let re = regex!("^.{1,2500}");
14 assert_eq!(vec![(0, 1)], findall!(re, "a"));
15 }
16
17 // See: https://github.com/rust-lang/regex/issues/75
18 mat!(regression_unsorted_binary_search_1, r"(?i)[a_]+", "A_", Some((0, 2)));
19 mat!(regression_unsorted_binary_search_2, r"(?i)[A_]+", "a_", Some((0, 2)));
20
21 // See: https://github.com/rust-lang/regex/issues/99
22 mat!(regression_negated_char_class_1, r"(?i)[^x]", "x", None);
23 mat!(regression_negated_char_class_2, r"(?i)[^x]", "X", None);
24
25 // See: https://github.com/rust-lang/regex/issues/101
26 mat!(regression_ascii_word_underscore, r"[[:word:]]", "_", Some((0, 1)));
27
28 // See: https://github.com/rust-lang/regex/issues/129
29 #[test]
30 fn regression_captures_rep() {
31 let re = regex!(r"([a-f]){2}(?P<foo>[x-z])");
32 let caps = re.captures(text!("abx")).unwrap();
33 assert_eq!(match_text!(caps.name("foo").unwrap()), text!("x"));
34 }
35
36 // See: https://github.com/rust-lang/regex/issues/153
37 mat!(regression_alt_in_alt1, r"ab?|$", "az", Some((0, 1)));
38 mat!(regression_alt_in_alt2, r"^(.*?)(\n|\r\n?|$)", "ab\rcd", Some((0, 3)));
39
40 // See: https://github.com/rust-lang/regex/issues/169
41 mat!(regression_leftmost_first_prefix, r"z*azb", "azb", Some((0, 3)));
42
43 // See: https://github.com/rust-lang/regex/issues/76
44 mat!(uni_case_lower_nocase_flag, r"(?i)\p{Ll}+", "ΛΘΓΔα", Some((0, 10)));
45
46 // See: https://github.com/rust-lang/regex/issues/191
47 mat!(many_alternates, r"1|2|3|4|5|6|7|8|9|10|int", "int", Some((0, 3)));
48
49 // burntsushi was bad and didn't create an issue for this bug.
50 mat!(anchored_prefix1, r"^a\S", "a ", None);
51 mat!(anchored_prefix2, r"^a\S", "foo boo a ", None);
52 mat!(anchored_prefix3, r"^-[a-z]", "r-f", None);
53
54 // See: https://github.com/rust-lang/regex/issues/204
55 split!(split_on_word_boundary, r"\b", r"Should this (work?)",
56 &[t!(""), t!("Should"), t!(" "), t!("this"),
57 t!(" ("), t!("work"), t!("?)")]);
58 matiter!(word_boundary_dfa, r"\b", "a b c",
59 (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5));
60
61 // See: https://github.com/rust-lang/regex/issues/268
62 matiter!(partial_anchor, r"^a|b", "ba", (0, 1));
63
64 // See: https://github.com/rust-lang/regex/issues/264
65 mat!(ascii_boundary_no_capture, r"(?-u)\B", "\u{28f3e}", Some((0, 0)));
66 mat!(ascii_boundary_capture, r"(?-u)(\B)", "\u{28f3e}", Some((0, 0)));
67
68 // See: https://github.com/rust-lang/regex/issues/280
69 ismatch!(partial_anchor_alternate_begin, r"^a|z", "yyyyya", false);
70 ismatch!(partial_anchor_alternate_end, r"a$|z", "ayyyyy", false);
71
72 // See: https://github.com/rust-lang/regex/issues/289
73 mat!(lits_unambiguous1, r"(ABC|CDA|BC)X", "CDAX", Some((0, 4)));
74
75 // See: https://github.com/rust-lang/regex/issues/291
76 mat!(lits_unambiguous2, r"((IMG|CAM|MG|MB2)_|(DSCN|CIMG))(?P<n>[0-9]+)$",
77 "CIMG2341", Some((0, 8)), Some((0, 4)), None, Some((0, 4)), Some((4, 8)));
78
79 // See: https://github.com/rust-lang/regex/issues/271
80 mat!(end_not_wb, r"$(?-u:\B)", "\u{5c124}\u{b576c}", Some((8, 8)));
81 mat!(endl_or_wb, r"(?m:$)|(?-u:\b)", "\u{6084e}", Some((4, 4)));
82 mat!(zero_or_end, r"(?i-u:\x00)|$", "\u{e682f}", Some((4, 4)));
83 mat!(y_or_endl, r"(?i-u:y)|(?m:$)", "\u{b4331}", Some((4, 4)));
84 mat!(wb_start_x, r"(?u:\b)^(?-u:X)", "X", Some((0, 1)));
85
86 // See: https://github.com/rust-lang/regex/issues/321
87 ismatch!(strange_anchor_non_complete_prefix, r"a^{2}", "", false);
88 ismatch!(strange_anchor_non_complete_suffix, r"${2}a", "", false);
89
90 // See: https://github.com/rust-lang/regex/issues/334
91 mat!(captures_after_dfa_premature_end, r"a(b*(X|$))?", "abcbX",
92 Some((0, 1)), None, None);
93
94 // See: https://github.com/rust-lang/regex/issues/437
95 ismatch!(
96 literal_panic,
97 r"typename type\-parameter\-\d+\-\d+::.+",
98 "test",
99 false);