Debian Codegraph @

debian/rust-vendor/regex-automata/tests/dfa/regression.rs

raw
1 // A regression test for checking that minimization correctly translates
2 // whether a state is a match state or not. Previously, it was possible for
3 // minimization to mark a non-matching state as matching.
4 #[test]
5 #[cfg(not(miri))]
6 fn minimize_sets_correct_match_states() {
7 use regex_automata::{
8 dfa::{dense::DFA, Automaton, StartKind},
9 Anchored, Input,
10 };
11
12 let pattern =
13 // This is a subset of the grapheme matching regex. I couldn't seem
14 // to get a repro any smaller than this unfortunately.
15 r"(?x)
16 (?:
17 \p{gcb=Prepend}*
18 (?:
19 (?:
20 (?:
21 \p{gcb=L}*
22 (?:\p{gcb=V}+|\p{gcb=LV}\p{gcb=V}*|\p{gcb=LVT})
23 \p{gcb=T}*
24 )
25 |
26 \p{gcb=L}+
27 |
28 \p{gcb=T}+
29 )
30 |
31 \p{Extended_Pictographic}
32 (?:\p{gcb=Extend}*\p{gcb=ZWJ}\p{Extended_Pictographic})*
33 |
34 [^\p{gcb=Control}\p{gcb=CR}\p{gcb=LF}]
35 )
36 [\p{gcb=Extend}\p{gcb=ZWJ}\p{gcb=SpacingMark}]*
37 )
38 ";
39
40 let dfa = DFA::builder()
41 .configure(
42 DFA::config().start_kind(StartKind::Anchored).minimize(true),
43 )
44 .build(pattern)
45 .unwrap();
46 let input = Input::new(b"\xE2").anchored(Anchored::Yes);
47 assert_eq!(Ok(None), dfa.try_search_fwd(&input));
48 }
49
50 // A prefilter must not skip to a new candidate after the DFA has already
51 // recorded a match. The DFA is still resolving the priority of that match,
52 // and skipping can cause a later match to overwrite it.
53 #[test]
54 #[cfg(feature = "perf-literal-multisubstring")]
55 fn prefilter_does_not_skip_pending_match() {
56 use regex_automata::{
57 dfa::{dense::DFA, Automaton},
58 util::prefilter::Prefilter,
59 HalfMatch, Input, MatchKind,
60 };
61
62 let pre = Prefilter::new(MatchKind::LeftmostFirst, &["ab", "c"])
63 .expect("prefilter");
64 let dfa = DFA::builder()
65 .configure(
66 DFA::config().prefilter(Some(pre)).starts_for_each_pattern(true),
67 )
68 .build(r"(?:ab|c)*c")
69 .unwrap();
70 let expected = Ok(Some(HalfMatch::must(0, 1)));
71 let input = Input::new("cabac");
72
73 assert_eq!(expected, dfa.try_search_fwd(&input));
74 assert_eq!(expected, dfa.to_sparse().unwrap().try_search_fwd(&input));
75 }