|
| 1 | +use debugger_test::debugger_test; |
| 2 | + |
| 3 | +#[inline(never)] |
| 4 | +fn __break() {} |
| 5 | + |
| 6 | +#[debugger_test( |
| 7 | + debugger = "cdb", |
| 8 | + commands = r#" |
| 9 | +.nvlist |
| 10 | +dv |
| 11 | +dx re |
| 12 | +dx captures |
| 13 | +g |
| 14 | +dx m1 |
| 15 | +dx m2 |
| 16 | +dx m3 |
| 17 | +dx m4 |
| 18 | +"#, |
| 19 | + expected_statements = r#" |
| 20 | +re : { text="^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$" } [Type: regex::re_unicode::Regex] |
| 21 | +[<Raw View>] [Type: regex::re_unicode::Regex] |
| 22 | +[Reference count] : 0x2 [Type: core::sync::atomic::AtomicUsize] |
| 23 | +[Weak reference count] : 0x1 [Type: core::sync::atomic::AtomicUsize] |
| 24 | +[+0xc00] res : { len=0x1 } [Type: alloc::vec::Vec<alloc::string::String,alloc::alloc::Global>] |
| 25 | +[+0x000] nfa [Type: regex::prog::Program] |
| 26 | +[+0x320] dfa [Type: regex::prog::Program] |
| 27 | +[+0x640] dfa_reverse [Type: regex::prog::Program] |
| 28 | +[+0x960] suffixes [Type: regex::literal::imp::LiteralSearcher] |
| 29 | +[+0xc18] ac : None [Type: enum$<core::option::Option<aho_corasick::ahocorasick::AhoCorasick<u32> >, 0, 1, Some>] |
| 30 | +[+0xda0] match_type : Dfa [Type: enum$<regex::exec::MatchType>] |
| 31 | +
|
| 32 | +captures : { named_groups=0x3 } [Type: regex::re_unicode::Captures] |
| 33 | +[<Raw View>] [Type: regex::re_unicode::Captures] |
| 34 | +[text] : "2020-10-15" [Type: str] |
| 35 | +pattern:\[named_groups\] : \{ len=0x3 \} \[Type: .*\] |
| 36 | +pattern:\[0\] : .* : "2020-10-15" \[Type: char \*\] |
| 37 | +pattern:\[1\] : .* : "2020" \[Type: char \*\] |
| 38 | +pattern:\[2\] : .* : "10" \[Type: char \*\] |
| 39 | +pattern:\[3\] : .* : "15" \[Type: char \*\] |
| 40 | +
|
| 41 | +m1 : "2020-10-15" [Type: regex::re_unicode::Match] |
| 42 | +[<Raw View>] [Type: regex::re_unicode::Match] |
| 43 | +[text] : "2020-10-15" [Type: str] |
| 44 | +[match_text] : "2020-10-15" |
| 45 | +[start] : 0 [Type: unsigned __int64] |
| 46 | +[end] : 10 [Type: unsigned __int64] |
| 47 | +
|
| 48 | +m2 : "2020" [Type: regex::re_unicode::Match] |
| 49 | +[<Raw View>] [Type: regex::re_unicode::Match] |
| 50 | +[text] : "2020-10-15" [Type: str] |
| 51 | +[match_text] : "2020" |
| 52 | +[start] : 0 [Type: unsigned __int64] |
| 53 | +[end] : 4 [Type: unsigned __int64] |
| 54 | +
|
| 55 | +m3 : "10" [Type: regex::re_unicode::Match] |
| 56 | +[<Raw View>] [Type: regex::re_unicode::Match] |
| 57 | +[text] : "2020-10-15" [Type: str] |
| 58 | +[match_text] : "10" |
| 59 | +[start] : 5 [Type: unsigned __int64] |
| 60 | +[end] : 7 [Type: unsigned __int64] |
| 61 | +
|
| 62 | +m4 : "15" [Type: regex::re_unicode::Match] |
| 63 | +[<Raw View>] [Type: regex::re_unicode::Match] |
| 64 | +[text] : "2020-10-15" [Type: str] |
| 65 | +[match_text] : "15" |
| 66 | +[start] : 8 [Type: unsigned __int64] |
| 67 | +[end] : 10 [Type: unsigned __int64] |
| 68 | +"# |
| 69 | +)] |
| 70 | +fn test_debugger_visualizer() { |
| 71 | + let re = regex::Regex::new( |
| 72 | + r"^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$", |
| 73 | + ) |
| 74 | + .unwrap(); |
| 75 | + let text = "2020-10-15"; |
| 76 | + |
| 77 | + let captures = re.captures(text).unwrap(); |
| 78 | + let matches = captures |
| 79 | + .iter() |
| 80 | + .filter_map(|capture| capture) |
| 81 | + .collect::<Vec<regex::Match>>(); |
| 82 | + assert_eq!(4, matches.len()); |
| 83 | + __break(); // #break |
| 84 | + |
| 85 | + let m1 = matches[0]; |
| 86 | + assert_eq!("2020-10-15", m1.as_str()); |
| 87 | + |
| 88 | + let m2 = matches[1]; |
| 89 | + assert_eq!("2020", m2.as_str()); |
| 90 | + |
| 91 | + let m3 = matches[2]; |
| 92 | + assert_eq!("10", m3.as_str()); |
| 93 | + |
| 94 | + let m4 = matches[3]; |
| 95 | + assert_eq!("15", m4.as_str()); |
| 96 | + __break(); // #break |
| 97 | +} |
| 98 | + |
| 99 | +#[debugger_test( |
| 100 | + debugger = "cdb", |
| 101 | + commands = r#" |
| 102 | +.nvlist |
| 103 | +dv |
| 104 | +dx re |
| 105 | +dx captures |
| 106 | +g |
| 107 | +dx m1 |
| 108 | +dx m2 |
| 109 | +dx m3 |
| 110 | +dx m4 |
| 111 | +"#, |
| 112 | + expected_statements = r#" |
| 113 | +re : { text="^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$" } [Type: regex::re_bytes::Regex] |
| 114 | +[<Raw View>] [Type: regex::re_bytes::Regex] |
| 115 | +[Reference count] : 0x2 [Type: core::sync::atomic::AtomicUsize] |
| 116 | +[Weak reference count] : 0x1 [Type: core::sync::atomic::AtomicUsize] |
| 117 | +[+0xc00] res : { len=0x1 } [Type: alloc::vec::Vec<alloc::string::String,alloc::alloc::Global>] |
| 118 | +[+0x000] nfa [Type: regex::prog::Program] |
| 119 | +[+0x320] dfa [Type: regex::prog::Program] |
| 120 | +[+0x640] dfa_reverse [Type: regex::prog::Program] |
| 121 | +[+0x960] suffixes [Type: regex::literal::imp::LiteralSearcher] |
| 122 | +[+0xc18] ac : None [Type: enum$<core::option::Option<aho_corasick::ahocorasick::AhoCorasick<u32> >, 0, 1, Some>] |
| 123 | +[+0xda0] match_type : Dfa [Type: enum$<regex::exec::MatchType>] |
| 124 | +
|
| 125 | +captures : { named_groups=0x3 } [Type: regex::re_bytes::Captures] |
| 126 | +[<Raw View>] [Type: regex::re_bytes::Captures] |
| 127 | +[text] : { len=0xa } [Type: slice$<u8>] |
| 128 | +pattern:\[named_groups\] : \{ len=0x3 \} \[Type: .*\] |
| 129 | +pattern:\[0\] : .* : "2020-10-15" \[Type: char \*\] |
| 130 | +pattern:\[1\] : .* : "2020" \[Type: char \*\] |
| 131 | +pattern:\[2\] : .* : "10" \[Type: char \*\] |
| 132 | +pattern:\[3\] : .* : "15" \[Type: char \*\] |
| 133 | +
|
| 134 | +m1 : "2020-10-15" [Type: regex::re_bytes::Match] |
| 135 | +[<Raw View>] [Type: regex::re_bytes::Match] |
| 136 | +[text] : { len=0xa } [Type: slice$<u8>] |
| 137 | +[match_text] : "2020-10-15" |
| 138 | +[start] : 0 [Type: unsigned __int64] |
| 139 | +[end] : 10 [Type: unsigned __int64] |
| 140 | +
|
| 141 | +m2 : "2020" [Type: regex::re_bytes::Match] |
| 142 | +[<Raw View>] [Type: regex::re_bytes::Match] |
| 143 | +[text] : { len=0xa } [Type: slice$<u8>] |
| 144 | +[match_text] : "2020" |
| 145 | +[start] : 0 [Type: unsigned __int64] |
| 146 | +[end] : 4 [Type: unsigned __int64] |
| 147 | +
|
| 148 | +m3 : "10" [Type: regex::re_bytes::Match] |
| 149 | +[<Raw View>] [Type: regex::re_bytes::Match] |
| 150 | +[text] : { len=0xa } [Type: slice$<u8>] |
| 151 | +[match_text] : "10" |
| 152 | +[start] : 5 [Type: unsigned __int64] |
| 153 | +[end] : 7 [Type: unsigned __int64] |
| 154 | +
|
| 155 | +m4 : "15" [Type: regex::re_bytes::Match] |
| 156 | +[<Raw View>] [Type: regex::re_bytes::Match] |
| 157 | +[text] : { len=0xa } [Type: slice$<u8>] |
| 158 | +[match_text] : "15" |
| 159 | +[start] : 8 [Type: unsigned __int64] |
| 160 | +[end] : 10 [Type: unsigned __int64] |
| 161 | +"# |
| 162 | +)] |
| 163 | +fn test_bytes_debugger_visualizer() { |
| 164 | + let re = regex::bytes::Regex::new( |
| 165 | + r"^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})$", |
| 166 | + ) |
| 167 | + .unwrap(); |
| 168 | + let text = b"2020-10-15"; |
| 169 | + |
| 170 | + let captures = re.captures(text).unwrap(); |
| 171 | + let matches = captures |
| 172 | + .iter() |
| 173 | + .filter_map(|capture| capture) |
| 174 | + .collect::<Vec<regex::bytes::Match>>(); |
| 175 | + assert_eq!(4, matches.len()); |
| 176 | + __break(); // #break |
| 177 | + |
| 178 | + let m1 = matches[0]; |
| 179 | + assert_eq!(b"2020-10-15", m1.as_bytes()); |
| 180 | + |
| 181 | + let m2 = matches[1]; |
| 182 | + assert_eq!(b"2020", m2.as_bytes()); |
| 183 | + |
| 184 | + let m3 = matches[2]; |
| 185 | + assert_eq!(b"10", m3.as_bytes()); |
| 186 | + |
| 187 | + let m4 = matches[3]; |
| 188 | + assert_eq!(b"15", m4.as_bytes()); |
| 189 | + |
| 190 | + __break(); // #break |
| 191 | +} |
0 commit comments