Debian Codegraph @

lib.rs

raw symbols SCIP
1 /*!
2 A crate for defining tests in a TOML format and applying them to regex engine
3 implementations.
4
5 Generally speaking, if you aren't writing your own regex engine and looking to
6 test it, then this crate is probably not for you. Moreover, this crate does not
7 come with any actual tests. It merely defines the test format and provides some
8 convenient routines for executing tests within the context of Rust unit tests.
9
10 # Format
11
12 The entire test corpus is derived from zero or more TOML files. Each TOML
13 file contains zero or more tests, where each test is defined as a table via
14 `[[test]]`.
15
16 Each test has the following fields:
17
18 * `name` - A name for the test. It must be unique within its file. A test's
19 [`RegexTest::full_name`] is derived either via `{group_name}/{name}` or
20 `{group_name}/{name}/{additional_name}`, with the latter being used only when
21 [`TestRunner::expand`] is used. The `group_name` is derived from the file stem
22 (the file name without the `.toml suffix).
23 * `regex` - The regex to test. This is either a string or a (possibly empty)
24 list of regex patterns. When using a list, the underlying regex engine is
25 expected to support multiple patterns where each are identified starting from
26 `0` and incrementing by 1 for each subsequent pattern.
27 * `haystack` - The text to search.
28 * `bounds` - An optional field whose value is a table with `start` and `end`
29 fields, whose values must be valid for the given `haystack`. When set,
30 the search will only execute within these bounds. When absent, the bounds
31 correspond to `start = 0` and `end = haystack.len()`.
32 * `matches` - Zero or more match values. Each match value can be in one of four
33 formats:
34 * A simple span, i.e., `[5, 12]`, corresponding to the start and end of the
35 match, in byte offsets. The start is inclusive and the end is exclusive.
36 The pattern ID for the match is assumed to be `0`.
37 * A table corresponding to the matching pattern ID and the span of the
38 match. For example, `{ id = 5, span = [20, 21] }`.
39 * A list of capture group spans, with the first corresponding to the
40 overall match and the pattern ID assumed to be `0`. For example,
41 `[[5, 10], [6, 8], [], [9, 10]]`, where `[]` corresponds to a group
42 present in the regex but one that did not participate in a match.
43 * A table corresponding to the matching pattern ID and a list of spans
44 corresponding to the capture groups. For example,
45 `{ id = 5, spans = [[5, 10], [6, 8], [], [9, 10]] }`. This is the most
46 general, but also most verbose, syntax.
47 * `match-limit` - An optional field that specifies a limit on the number of
48 matches. When absent, no limit is enforced and all matches should be reported
49 by the regex engine. This can be useful, for example, when one only cares about
50 the first match.
51 * `compiles` - An optional field indicating whether the regex is expected to
52 compile. It defaults to `true` when absent. When `true`, if the regex does not
53 compile, then the test fails. Conversely, when `false`, if the regex _does_
54 compile, then the test fails.
55 * `anchored` - Whether to execute an anchored search or not. Note that this is
56 not the same as adding a `^` to the beginning of your regex pattern. `^` always
57 requires the regex to match at position `0`, but an anchored search simply
58 requires that the regex match at the starting position of the search. (The
59 starting position of the search can be configured via the optional `bounds`
60 field.)
61 * `case-insensitive` - Whether to match the regex case insensitively. This is
62 disabled by default. There is no real difference between using this field and
63 adding a `(?i)` to the beginning of your regex. (Some regex engines may not
64 support `(?i)`.)
65 * `unescape` - When enabled, the haystack is unescaped. Sequences like `\x00`
66 are turned into their corresponding byte values. This permits one to write
67 haystacks that contain invalid UTF-8 without embedding actual invalid UTF-8
68 into a TOML file (which is not allowed). There is generally no other reason to
69 enable `unescape`.
70 * `unicode` - When enabled, the regex pattern should be compiled with its
71 corresponding Unicode mode enabled. For example, `[^a]` matches any UTF-8
72 encoding of any codepoint other than `a`. Case insensitivty should be Unicode
73 aware. Unicode classes like `\pL` are available. The Perl classes `\w`, `\s`
74 and `\d` should be Unicode aware. And so on. This is an optional field and is
75 enabled by default.
76 * `utf8` - When this is enabled, all regex match substrings should be entirely
77 valid UTF-8. While parts of the haystack the regex searches through may not be
78 valid UTF-8, only the portions that are valid UTF-8 may be reported in match
79 spans. Importantly, this includes zero-width matches. Zero-width matches must
80 never split the UTF-8 encoding of a single codepoint when this is enabled. This
81 is an optional field and is enabled by default.
82 * `line-terminator` - This sets the line terminator used by the multi-line
83 assertions `(?m:^)` and `(?m:$)`. It defaults to `\n`. It must be exactly one
84 byte. This field is automatically unescaped in order to permit a non-ASCII
85 byte.
86 * `match-kind` - May be one of `all`, `leftmost-first` or `leftmost-longest`.
87 See [`MatchKind`] for more details. This is an optional field and defaults to
88 `leftmost-first`.
89 * `search-kind` - May be one of `earliest`, `leftmost` or `overlapping`. See
90 [`SearchKind`] for more details. This is an optional field and defaults to
91 `leftmost`.
92 */
93
94 #![deny(missing_docs)]
95
96 /// For convenience, `anyhow::Error` is used to represents errors in this
97 /// crate.
98 ///
99 /// For this reason, `anyhow` is a public dependency and is re-exported here.
100 pub extern crate anyhowrust-analyzer cargo regex-test 0.1.1 anyhow/;
101
102 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#, collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#, fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/, pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#};
103
104 use {
105 anyhowrust-analyzer cargo anyhow 1.0.104 crate/::{bailrust-analyzer cargo anyhow 1.0.104 macros/bail!, Contextrust-analyzer cargo anyhow 1.0.104 Context#, Resultrust-analyzer cargo anyhow 1.0.104 Result#},
106 bstrrust-analyzer cargo bstr 1.13.1 crate/::{BStringrust-analyzer cargo bstr 1.13.1 bstring/BString#, ByteSlicerust-analyzer cargo bstr 1.13.1 ext_slice/ByteSlice#, ByteVecrust-analyzer cargo bstr 1.13.1 ext_vec/ByteVec#},
107 serderust-analyzer cargo serde 1.0.229 crate/::Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#,
108 };
109
110 const ENV_REGEX_TESTrust-analyzer cargo regex-test 0.1.1 ENV_REGEX_TEST.: &str = "REGEX_TEST";
111 const ENV_REGEX_TEST_VERBOSErust-analyzer cargo regex-test 0.1.1 ENV_REGEX_TEST_VERBOSE.: &str = "REGEX_TEST_VERBOSE";
112
113 /// A collection of regex tests.
114 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:)]
115 pub struct RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests# {
116 /// 'default' permits an empty TOML file.
117 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default, rename = "test")]
118 testsrust-analyzer cargo regex-test 0.1.1 RegexTests#tests.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#>,
119 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(skip)]
120 seenrust-analyzer cargo regex-test 0.1.1 RegexTests#seen.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
121 }
122
123 impl RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests# {
124 /// Create a new empty collection of glob tests.
125 pub fn newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().() -> RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests# {
126 RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests# { testsrust-analyzer cargo regex-test 0.1.1 RegexTests#tests.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], seenrust-analyzer cargo regex-test 0.1.1 RegexTests#seen.: HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]new().() }
127 }
128
129 /// Loads all of the tests in the given TOML file. The group name assigned
130 /// to each test is the stem of the file name. For example, if one loads
131 /// `foo/bar.toml`, then the group name for each test will be `bar`.
132 pub fn loadrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(&mut self, path: P) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
133 let path = path.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().();
134 let data = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().(path)
135 .with_contextrust-analyzer cargo anyhow 1.0.104 context/impl#[`Result<T, E>`][`Context<T, E>`]with_context().(|| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("failed to read {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
136 let group_name = path
137 .file_stemrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_stem().()
138 .with_contextrust-analyzer cargo anyhow 1.0.104 context/impl#[`Option<T>`][`Context<T, Infallible>`]with_context().(|| {
139 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("failed to get file name of {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().())
140 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
141 .to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()
142 .with_contextrust-analyzer cargo anyhow 1.0.104 context/impl#[`Option<T>`][`Context<T, Infallible>`]with_context().(|| {
143 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("invalid UTF-8 found in {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().())
144 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
145 self.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().(&group_name, &data)
146 .with_contextrust-analyzer cargo anyhow 1.0.104 context/impl#[`Result<T, E>`][`Context<T, E>`]with_context().(|| formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("error loading {}", path.displayrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]display().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
147 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
148 }
149
150 /// Load all of the TOML encoded tests in `data` into this collection.
151 /// The given group name is assigned to all loaded tests.
152 pub fn load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().(&mut self, group_name: &str, data: &[u8]) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<()> {
153 let data = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&data).with_contextrust-analyzer cargo anyhow 1.0.104 context/impl#[`Result<T, E>`][`Context<T, E>`]with_context().(|| {
154 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("data in {} is not valid UTF-8", group_name)
155 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
156 let mut index = 1;
157 let mut tests: RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests# =
158 tomlrust-analyzer cargo toml 1.1.4+spec-1.1.0 crate/::from_strrust-analyzer cargo toml 1.1.4+spec-1.1.0 de/from_str().(&data).with_contextrust-analyzer cargo anyhow 1.0.104 context/impl#[`Result<T, E>`][`Context<T, E>`]with_context().(|| {
159 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("error decoding TOML for '{}'", group_name)
160 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
161 for t in &mut tests.testsrust-analyzer cargo regex-test 0.1.1 RegexTests#tests. {
162 t.grouprust-analyzer cargo regex-test 0.1.1 RegexTest#group. = group_name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
163 if t.namerust-analyzer cargo regex-test 0.1.1 RegexTest#name..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
164 t.namerust-analyzer cargo regex-test 0.1.1 RegexTest#name. = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", index);
165 index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1;
166 }
167 t.full_namerust-analyzer cargo regex-test 0.1.1 RegexTest#full_name. = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}/{}", t.grouprust-analyzer cargo regex-test 0.1.1 RegexTest#group., t.namerust-analyzer cargo regex-test 0.1.1 RegexTest#name.);
168 if t.unescaperust-analyzer cargo regex-test 0.1.1 RegexTest#unescape. {
169 t.haystackrust-analyzer cargo regex-test 0.1.1 RegexTest#haystack. = BStringrust-analyzer cargo bstr 1.13.1 bstring/BString#::fromrust-analyzer cargo bstr 1.13.1 impls/bstring/impl#[BString][`From<Vec<u8>>`]from().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::unescape_bytesrust-analyzer cargo bstr 1.13.1 ext_vec/ByteVec#unescape_bytes().(
170 // OK because TOML requires valid UTF-8.
171 t.haystackrust-analyzer cargo regex-test 0.1.1 RegexTest#haystack..to_strrust-analyzer cargo bstr 1.13.1 ext_slice/ByteSlice#to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
172 ));
173 }
174 if t.line_terminatorrust-analyzer cargo regex-test 0.1.1 RegexTest#line_terminator..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
175 t.line_terminatorrust-analyzer cargo regex-test 0.1.1 RegexTest#line_terminator. = BStringrust-analyzer cargo bstr 1.13.1 bstring/BString#::fromrust-analyzer cargo bstr 1.13.1 impls/bstring/impl#[BString][`From<&'a str>`]from().("\n");
176 } else {
177 t.line_terminatorrust-analyzer cargo regex-test 0.1.1 RegexTest#line_terminator. = BStringrust-analyzer cargo bstr 1.13.1 bstring/BString#::fromrust-analyzer cargo bstr 1.13.1 impls/bstring/impl#[BString][`From<Vec<u8>>`]from().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::unescape_bytesrust-analyzer cargo bstr 1.13.1 ext_vec/ByteVec#unescape_bytes().(
178 // OK because TOML requires valid UTF-8.
179 t.line_terminatorrust-analyzer cargo regex-test 0.1.1 RegexTest#line_terminator..to_strrust-analyzer cargo bstr 1.13.1 ext_slice/ByteSlice#to_str().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
180 ));
181 anyhowrust-analyzer cargo anyhow 1.0.104 crate/::ensurerust-analyzer cargo anyhow 1.0.104 macros/ensure!!(
182 t.line_terminatorrust-analyzer cargo regex-test 0.1.1 RegexTest#line_terminator..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() == 1,
183 "line terminator '{:?}' has length not equal to 1",
184 t.line_terminatorrust-analyzer cargo regex-test 0.1.1 RegexTest#line_terminator.,
185 );
186 }
187 if self.seenrust-analyzer cargo regex-test 0.1.1 RegexTests#seen..containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(t.full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]full_name().()) {
188 bailrust-analyzer cargo anyhow 1.0.104 macros/bail!!("found duplicate tests for name '{}'", t.full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]full_name().());
189 }
190 self.seenrust-analyzer cargo regex-test 0.1.1 RegexTests#seen..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(t.full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]full_name().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
191 }
192 self.testsrust-analyzer cargo regex-test 0.1.1 RegexTests#tests..extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(tests.testsrust-analyzer cargo regex-test 0.1.1 RegexTests#tests.);
193 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
194 }
195
196 /// Return an iterator over all regex tests that have been loaded. The
197 /// order of the iterator corresponds to the order in which the tests were
198 /// loaded.
199 ///
200 /// This is useful to pass to [`TestRunner::test_iter`].
201 pub fn iterrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]iter().(&self) -> RegexTestsIterrust-analyzer cargo regex-test 0.1.1 RegexTestsIter# {
202 RegexTestsIterrust-analyzer cargo regex-test 0.1.1 RegexTestsIter#(self.testsrust-analyzer cargo regex-test 0.1.1 RegexTests#tests..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().())
203 }
204 }
205
206 /// A regex test describes the inputs and expected outputs of a regex match.
207 ///
208 /// Each `RegexTest` represents a single `[[test]]` table in a TOML test file.
209 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:)]
210 #[serde(deny_unknown_fields)]
211 pub struct RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest# {
212 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(skip)]
213 grouprust-analyzer cargo regex-test 0.1.1 RegexTest#group.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
214 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default)]
215 namerust-analyzer cargo regex-test 0.1.1 RegexTest#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
216 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(skip)]
217 additional_namerust-analyzer cargo regex-test 0.1.1 RegexTest#additional_name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
218 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(skip)]
219 full_namerust-analyzer cargo regex-test 0.1.1 RegexTest#full_name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
220 regexrust-analyzer cargo regex-test 0.1.1 RegexTest#regex.: RegexesFormatrust-analyzer cargo regex-test 0.1.1 RegexesFormat#,
221 haystackrust-analyzer cargo regex-test 0.1.1 RegexTest#haystack.: BStringrust-analyzer cargo bstr 1.13.1 bstring/BString#,
222 boundsrust-analyzer cargo regex-test 0.1.1 RegexTest#bounds.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Spanrust-analyzer cargo regex-test 0.1.1 Span#>,
223 matchesrust-analyzer cargo regex-test 0.1.1 RegexTest#matches.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Capturesrust-analyzer cargo regex-test 0.1.1 Captures#>,
224 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(rename = "match-limit")]
225 match_limitrust-analyzer cargo regex-test 0.1.1 RegexTest#match_limit.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>,
226 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default = "default_true")]
227 compilesrust-analyzer cargo regex-test 0.1.1 RegexTest#compiles.: bool,
228 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default)]
229 anchoredrust-analyzer cargo regex-test 0.1.1 RegexTest#anchored.: bool,
230 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default, rename = "case-insensitive")]
231 case_insensitiverust-analyzer cargo regex-test 0.1.1 RegexTest#case_insensitive.: bool,
232 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default)]
233 unescaperust-analyzer cargo regex-test 0.1.1 RegexTest#unescape.: bool,
234 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default = "default_true")]
235 unicoderust-analyzer cargo regex-test 0.1.1 RegexTest#unicode.: bool,
236 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default = "default_true")]
237 utf8rust-analyzer cargo regex-test 0.1.1 RegexTest#utf8.: bool,
238 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default, rename = "line-terminator")]
239 line_terminatorrust-analyzer cargo regex-test 0.1.1 RegexTest#line_terminator.: BStringrust-analyzer cargo bstr 1.13.1 bstring/BString#,
240 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default, rename = "match-kind")]
241 match_kindrust-analyzer cargo regex-test 0.1.1 RegexTest#match_kind.: MatchKindrust-analyzer cargo regex-test 0.1.1 MatchKind#,
242 #[serderust-analyzer cargo serde_derive 1.0.229 serde:(default, rename = "search-kind")]
243 search_kindrust-analyzer cargo regex-test 0.1.1 RegexTest#search_kind.: SearchKindrust-analyzer cargo regex-test 0.1.1 SearchKind#,
244 }
245
246 impl RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest# {
247 /// Return the group name of this test.
248 ///
249 /// Usually the group name corresponds to a collection of related
250 /// tests. More specifically, when using [`RegexTests::load`], the
251 /// group name corresponds to the file stem (the file name without the
252 /// `.toml` suffix). Otherwise, the group name is whatever is given to
253 /// [`RegexTests::load_slice`].
254 pub fn grouprust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]group().(&self) -> &str {
255 &self.grouprust-analyzer cargo regex-test 0.1.1 RegexTest#group.
256 }
257
258 /// The name of this test.
259 ///
260 /// Note that this is only the name as given in the `[[test]]` block. The
261 /// actual full name used for filtering and reporting can be retrieved with
262 /// [`RegexTest::full_name`].
263 pub fn namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]name().(&self) -> &str {
264 &self.namerust-analyzer cargo regex-test 0.1.1 RegexTest#name.
265 }
266
267 /// The additional name for this test.
268 ///
269 /// This is only non-empty when the test runner was expanded with
270 /// [`TestRunner::expand`].
271 pub fn additional_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]additional_name().(&self) -> &str {
272 &self.additional_namerust-analyzer cargo regex-test 0.1.1 RegexTest#additional_name.
273 }
274
275 /// The full name of this test, which is formed by joining the group
276 /// name, the test name and the additional name with a `/`.
277 pub fn full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]full_name().(&self) -> &str {
278 &self.full_namerust-analyzer cargo regex-test 0.1.1 RegexTest#full_name.
279 }
280
281 /// Return all of the regexes that should be matched for this test. This
282 /// slice may be empty!
283 pub fn regexesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]regexes().(&self) -> &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#] {
284 self.regexrust-analyzer cargo regex-test 0.1.1 RegexTest#regex..patternsrust-analyzer cargo regex-test 0.1.1 impl#[RegexesFormat]patterns().()
285 }
286
287 /// Return the bytes on which the regex should be matched.
288 pub fn haystackrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]haystack().(&self) -> &[u8] {
289 &self.haystackrust-analyzer cargo regex-test 0.1.1 RegexTest#haystack.
290 }
291
292 /// Returns the bounds of a search.
293 ///
294 /// If the test didn't specify any bounds, then the bounds returned are
295 /// equivalent to the entire haystack.
296 pub fn boundsrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]bounds().(&self) -> Spanrust-analyzer cargo regex-test 0.1.1 Span# {
297 self.boundsrust-analyzer cargo regex-test 0.1.1 RegexTest#bounds..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 0, endrust-analyzer cargo regex-test 0.1.1 Span#end.: self.haystackrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]haystack().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() })
298 }
299
300 /// Returns the limit on the number of matches that should be reported,
301 /// if specified in the test.
302 ///
303 /// This is useful for tests that only want to check for the first
304 /// match. In which case, the match limit is set to 1.
305 ///
306 /// If there is no match limit, then regex engines are expected to report
307 /// all matches.
308 pub fn match_limitrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]match_limit().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> {
309 self.match_limitrust-analyzer cargo regex-test 0.1.1 RegexTest#match_limit.
310 }
311
312 /// Returns true if the regex(es) in this test are expected to compile.
313 pub fn compilesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]compiles().(&self) -> bool {
314 self.compilesrust-analyzer cargo regex-test 0.1.1 RegexTest#compiles.
315 }
316
317 /// Whether the regex should perform an anchored search.
318 ///
319 /// This is distinct from putting a `^` in the regex in that `bounds` may
320 /// be specified that permit the regex search to start at a position
321 /// `i > 0`. In which case, enabling anchored mode here requires that any
322 /// matches produced must have a start offset at `i`.
323 pub fn anchoredrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]anchored().(&self) -> bool {
324 self.anchoredrust-analyzer cargo regex-test 0.1.1 RegexTest#anchored.
325 }
326
327 /// Returns true if regex matching should be performed without regard to
328 /// case.
329 pub fn case_insensitiverust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]case_insensitive().(&self) -> bool {
330 self.case_insensitiverust-analyzer cargo regex-test 0.1.1 RegexTest#case_insensitive.
331 }
332
333 /// Returns true if regex matching should have Unicode mode enabled.
334 ///
335 /// For example, `[^a]` matches any UTF-8 encoding of any codepoint other
336 /// than `a`. Case insensitivty should be Unicode aware. Unicode classes
337 /// like `\pL` are available. The Perl classes `\w`, `\s` and `\d` should
338 /// be Unicode aware. And so on.
339 ///
340 /// This is enabled by default.
341 pub fn unicoderust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]unicode().(&self) -> bool {
342 self.unicoderust-analyzer cargo regex-test 0.1.1 RegexTest#unicode.
343 }
344
345 /// Returns true if regex matching should exclusively match valid UTF-8.
346 /// When this is disabled, matching on arbitrary bytes is permitted.
347 ///
348 /// When this is enabled, all regex match substrings should be entirely
349 /// valid UTF-8. While parts of the haystack the regex searches through
350 /// may not be valid UTF-8, only the portions that are valid UTF-8 may be
351 /// reported in match spans.
352 ///
353 /// Importantly, this includes zero-width matches. Zero-width matches must
354 /// never split the UTF-8 encoding of a single codepoint when this is
355 /// enabled.
356 ///
357 /// This is enabled by default.
358 pub fn utf8rust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]utf8().(&self) -> bool {
359 self.utf8rust-analyzer cargo regex-test 0.1.1 RegexTest#utf8.
360 }
361
362 /// Returns the line terminator that should be used for the multi-line
363 /// assertions `(?m:^)` and `(?m:$)`.
364 ///
365 /// If it isn't set, then this defaults to `\n`.
366 pub fn line_terminatorrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]line_terminator().(&self) -> u8 {
367 self.line_terminatorrust-analyzer cargo regex-test 0.1.1 RegexTest#line_terminator.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
368 }
369
370 /// Return the match semantics required by this test.
371 pub fn match_kindrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]match_kind().(&self) -> MatchKindrust-analyzer cargo regex-test 0.1.1 MatchKind# {
372 self.match_kindrust-analyzer cargo regex-test 0.1.1 RegexTest#match_kind.
373 }
374
375 /// Return the search semantics required by this test.
376 pub fn search_kindrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]search_kind().(&self) -> SearchKindrust-analyzer cargo regex-test 0.1.1 SearchKind# {
377 self.search_kindrust-analyzer cargo regex-test 0.1.1 RegexTest#search_kind.
378 }
379
380 /// Run the test and return the result produced by the given compiled
381 /// regex.
382 fn testrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]test().(&self, regex: &mut CompiledRegexrust-analyzer cargo regex-test 0.1.1 CompiledRegex#) -> TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# {
383 match regex.matcherrust-analyzer cargo regex-test 0.1.1 CompiledRegex#matcher. {
384 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => TestResultrust-analyzer cargo regex-test 0.1.1 TestResult#::skiprust-analyzer cargo regex-test 0.1.1 impl#[TestResult]skip().(),
385 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref mut match_regex) => match_regex(self),
386 }
387 }
388
389 /// Append `/name` to the `full_name` of this test.
390 ///
391 /// This is used to support [`TestRunner::expand`].
392 fn with_additional_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]with_additional_name().(&self, name: &str) -> RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest# {
393 let additional_name = name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
394 let full_name = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}/{}", self.full_namerust-analyzer cargo regex-test 0.1.1 RegexTest#full_name., additional_name);
395 RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest# { additional_namerust-analyzer cargo regex-test 0.1.1 RegexTest#additional_name., full_namerust-analyzer cargo regex-test 0.1.1 RegexTest#full_name., ..self.clonerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest][Clone]clone().() }
396 }
397
398 /// Returns true if and only if this test expects at least one of the
399 /// regexes to match the haystack.
400 fn is_matchrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]is_match().(&self) -> bool {
401 !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.matchesrust-analyzer cargo regex-test 0.1.1 RegexTest#matches..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()
402 }
403
404 /// Returns a slice of pattern IDs that are expected to match the haystack.
405 /// The slice is empty if no match is expected to occur. The IDs returned
406 /// are deduplicated and sorted in ascending order.
407 fn which_matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]which_matches().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> {
408 let mut seen = HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]new().();
409 let mut ids = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
410 for cap in self.matchesrust-analyzer cargo regex-test 0.1.1 RegexTest#matches..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
411 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().seen.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&cap.idrust-analyzer cargo regex-test 0.1.1 Captures#id.) {
412 seen.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(cap.idrust-analyzer cargo regex-test 0.1.1 Captures#id.);
413 ids.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(cap.idrust-analyzer cargo regex-test 0.1.1 Captures#id.);
414 }
415 }
416 ids.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().();
417 ids
418 }
419
420 /// Extracts the overall match from each `Captures` match in this test
421 /// and returns it.
422 fn matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]matches().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Matchrust-analyzer cargo regex-test 0.1.1 Match#> {
423 let mut matches = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
424 for cap in self.matchesrust-analyzer cargo regex-test 0.1.1 RegexTest#matches..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
425 matches.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(cap.to_matchrust-analyzer cargo regex-test 0.1.1 impl#[Captures]to_match().());
426 }
427 matches
428 }
429
430 /// Returns the matches expected by this test, including the spans of any
431 /// matching capture groups.
432 fn capturesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]captures().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Capturesrust-analyzer cargo regex-test 0.1.1 Captures#> {
433 self.matchesrust-analyzer cargo regex-test 0.1.1 RegexTest#matches..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().()
434 }
435 }
436
437 /// The result of compiling a regex.
438 ///
439 /// In many implementations, the act of matching a regex can be separated from
440 /// the act of compiling a regex. A `CompiledRegex` represents a regex that has
441 /// been compiled and is ready to be used for matching.
442 ///
443 /// The matching implementation is represented by a closure that accepts a
444 /// [`&RegexTest`](RegexTest) and returns a [`TestResult`].
445 pub struct CompiledRegexrust-analyzer cargo regex-test 0.1.1 CompiledRegex# {
446 matcherrust-analyzer cargo regex-test 0.1.1 CompiledRegex#matcher.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#) -> TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# + 'static>>,
447 }
448
449 impl CompiledRegexrust-analyzer cargo regex-test 0.1.1 CompiledRegex# {
450 /// Provide a closure that represents the compiled regex and executes a
451 /// regex match on any `RegexTest`. The `RegexTest` given to the closure
452 /// provided is the exact same `RegexTest` that is used to compile this
453 /// regex.
454 pub fn compiledrust-analyzer cargo regex-test 0.1.1 impl#[CompiledRegex]compiled().(
455 matcher: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#) -> TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# + 'static,
456 ) -> CompiledRegexrust-analyzer cargo regex-test 0.1.1 CompiledRegex# {
457 CompiledRegexrust-analyzer cargo regex-test 0.1.1 CompiledRegex# { matcherrust-analyzer cargo regex-test 0.1.1 CompiledRegex#matcher.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(matcher)) }
458 }
459
460 /// Indicate that tests on this regex should be skipped. This typically
461 /// occurs if the `RegexTest` requires something that an implementation
462 /// does not support.
463 pub fn skiprust-analyzer cargo regex-test 0.1.1 impl#[CompiledRegex]skip().() -> CompiledRegexrust-analyzer cargo regex-test 0.1.1 CompiledRegex# {
464 CompiledRegexrust-analyzer cargo regex-test 0.1.1 CompiledRegex# { matcherrust-analyzer cargo regex-test 0.1.1 CompiledRegex#matcher.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# }
465 }
466
467 /// Returns true if the test runner decided to skip the test when
468 /// attempting to compile the regex.
469 pub fn is_skiprust-analyzer cargo regex-test 0.1.1 impl#[CompiledRegex]is_skip().(&self) -> bool {
470 self.matcherrust-analyzer cargo regex-test 0.1.1 CompiledRegex#matcher..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()
471 }
472 }
473
474 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for CompiledRegexrust-analyzer cargo regex-test 0.1.1 CompiledRegex# {
475 fn fmtrust-analyzer cargo regex-test 0.1.1 impl#[CompiledRegex][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
476 let status = match self.matcherrust-analyzer cargo regex-test 0.1.1 CompiledRegex#matcher. {
477 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => "Skip",
478 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => "Run(...)",
479 };
480 f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("CompiledRegex").fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("matcher", &status).finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().()
481 }
482 }
483
484 /// The result of executing a regex search.
485 ///
486 /// When using the test runner, callers must provide a closure that takes
487 /// a `RegexTest` and returns a `TestResult`. The `TestResult` is meant to
488 /// capture the results of matching the haystack against the regex specified by
489 /// the `RegexTest`.
490 ///
491 /// Usually this consists of one or more matches, which can be constructed via
492 /// `TestResult::matches` (for just overall matches) or `TestResult::captures`
493 /// (for matches with capture group spans). But the regex engine may also
494 /// report whether a match exists, or just whether a pattern matched or not.
495 /// That can be done via `TestResult::matched` and `TestResult::which`,
496 /// respectively.
497 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
498 pub struct TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# {
499 kindrust-analyzer cargo regex-test 0.1.1 TestResult#kind.: TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#,
500 }
501
502 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
503 enum TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind# {
504 Matchrust-analyzer cargo regex-test 0.1.1 TestResultKind#Match#(bool),
505 Whichrust-analyzer cargo regex-test 0.1.1 TestResultKind#Which#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize>),
506 StartEndrust-analyzer cargo regex-test 0.1.1 TestResultKind#StartEnd#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Matchrust-analyzer cargo regex-test 0.1.1 Match#>),
507 Capturesrust-analyzer cargo regex-test 0.1.1 TestResultKind#Captures#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Capturesrust-analyzer cargo regex-test 0.1.1 Captures#>),
508 Skiprust-analyzer cargo regex-test 0.1.1 TestResultKind#Skip#,
509 Failrust-analyzer cargo regex-test 0.1.1 TestResultKind#Fail# { whyrust-analyzer cargo regex-test 0.1.1 TestResultKind#Fail#why.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# },
510 }
511
512 impl TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# {
513 /// Create a test result that indicates just whether any match was found
514 /// or not.
515 pub fn matchedrust-analyzer cargo regex-test 0.1.1 impl#[TestResult]matched().(yes: bool) -> TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# {
516 TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# { kindrust-analyzer cargo regex-test 0.1.1 TestResult#kind.: TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::Matchrust-analyzer cargo regex-test 0.1.1 TestResultKind#Match#(yes) }
517 }
518
519 /// Create a test result that indicates which out of possibly many regexes
520 /// matched the haystack. If `which` is empty, then this is equivalent to
521 /// `TestResult::matched(false)`.
522 ///
523 /// Note that the iterator should consist of pattern IDs, where each
524 /// ID corresponds to a pattern that matches anywhere in the haystack.
525 /// Multiple patterns may match the same region of the haystack. That is,
526 /// this supports overlapping matches.
527 pub fn whichrust-analyzer cargo regex-test 0.1.1 impl#[TestResult]which().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = usize>>(it: I) -> TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# {
528 let mut which: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> = it.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
529 which.sortrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort().();
530 TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# { kindrust-analyzer cargo regex-test 0.1.1 TestResult#kind.: TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::Whichrust-analyzer cargo regex-test 0.1.1 TestResultKind#Which#(which) }
531 }
532
533 /// Create a test result containing a sequence of all matches in the test's
534 /// haystack. This is useful when the regex engine only reports overall
535 /// matches and not the spans of each matching capture group.
536 ///
537 /// If the sequence is empty, then this is equivalent to
538 /// `TestResult::matched(false)`.
539 pub fn matchesrust-analyzer cargo regex-test 0.1.1 impl#[TestResult]matches().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = Matchrust-analyzer cargo regex-test 0.1.1 Match#>>(it: I) -> TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# {
540 TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# { kindrust-analyzer cargo regex-test 0.1.1 TestResult#kind.: TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::StartEndrust-analyzer cargo regex-test 0.1.1 TestResultKind#StartEnd#(it.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) }
541 }
542
543 /// Create a test result containing a sequence of all capturing matches in
544 /// the test's haystack. Each match is a `Captures`, and each `Captures`
545 /// should include the spans of all matching capturing groups.
546 ///
547 /// If the sequence is empty, then this is equivalent to
548 /// `TestResult::matched(false)`.
549 pub fn capturesrust-analyzer cargo regex-test 0.1.1 impl#[TestResult]captures().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = Capturesrust-analyzer cargo regex-test 0.1.1 Captures#>>(it: I) -> TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# {
550 TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# { kindrust-analyzer cargo regex-test 0.1.1 TestResult#kind.: TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::Capturesrust-analyzer cargo regex-test 0.1.1 TestResultKind#Captures#(it.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()) }
551 }
552
553 /// Indicate that this test should be skipped. It will not be counted as
554 /// a failure.
555 pub fn skiprust-analyzer cargo regex-test 0.1.1 impl#[TestResult]skip().() -> TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# {
556 TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# { kindrust-analyzer cargo regex-test 0.1.1 TestResult#kind.: TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::Skiprust-analyzer cargo regex-test 0.1.1 TestResultKind#Skip# }
557 }
558
559 /// Indicate that this test should be failed for the reason given.
560 ///
561 /// This is useful when a test needs to be failed for reasons that the
562 /// test runner itself cannot check. That is, the test is failed by the
563 /// implementation being tested.
564 pub fn failrust-analyzer cargo regex-test 0.1.1 impl#[TestResult]fail().(why: &str) -> TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# {
565 TestResultrust-analyzer cargo regex-test 0.1.1 TestResult# { kindrust-analyzer cargo regex-test 0.1.1 TestResult#kind.: TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::Failrust-analyzer cargo regex-test 0.1.1 TestResultKind#Fail# { whyrust-analyzer cargo regex-test 0.1.1 TestResultKind#Fail#why.: why.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() } }
566 }
567 }
568
569 /// A runner for executing regex tests.
570 ///
571 /// This runner is intended to be used within a Rust unit test, marked with the
572 /// `#[test]` attribute.
573 ///
574 /// A test runner is responsible for running tests against a regex
575 /// implementation. It contains logic for skipping tests and collects test
576 /// results. Typical usage corresponds to calling [`TestRunner::test_iter`] on
577 /// an iterator of `RegexTest`s, and then calling `assert` once done. If any
578 /// tests failed, then `assert` will panic with an error message containing all
579 /// test failures. `assert` must be called before the test completes.
580 ///
581 /// # Skipping tests
582 ///
583 /// If the `REGEX_TEST` environment variable is set, then it may contain
584 /// a comma separated list of substrings. Each substring corresponds to a
585 /// whitelisted item, unless it starts with a `-`, in which case it corresponds
586 /// to a blacklisted item.
587 ///
588 /// If there are any whitelist items, then a test's full name must contain at
589 /// least one of the whitelist substrings in order to be run, and does not
590 /// contain and blacklist substrings. If there are no whitelist substrings,
591 /// then a test is run only when it does not match any blacklist substrings.
592 ///
593 /// The last substring that a test name matches takes precedent.
594 ///
595 /// Callers may also specify explicit whitelist or blacklist substrings using
596 /// the corresponding methods on this type, which has the effect of always
597 /// having those rules in place for that specific test. For example, if you're
598 /// testing a search by building a DFA and then minimizing it, you may want to
599 /// skip tests with bigger regexes, since they could take quite some time to
600 /// run.
601 ///
602 /// Whitelist and blacklist substrings are matched on the full name of each
603 /// test, which typically looks like `group_name/test_name`.
604 ///
605 /// Currently there is no way to escape either a `-` or a `,` in `REGEX_TEST`.
606 /// This usually isn't required because test names usually don't include either
607 /// character.
608 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
609 pub struct TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner# {
610 includerust-analyzer cargo regex-test 0.1.1 TestRunner#include.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<IncludePatternrust-analyzer cargo regex-test 0.1.1 IncludePattern#>,
611 resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results.: RegexTestResultsrust-analyzer cargo regex-test 0.1.1 RegexTestResults#,
612 expandersrust-analyzer cargo regex-test 0.1.1 TestRunner#expanders.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Expanderrust-analyzer cargo regex-test 0.1.1 Expander#>,
613 }
614
615 impl TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner# {
616 /// Create a new runner for executing tests.
617 ///
618 /// The test runner maintains a full list of tests that have succeeded,
619 /// failed or been skipped. Moreover, the test runner may control which
620 /// tests get run via its whitelist and blacklist.
621 ///
622 /// This returns an error if there was a problem reading the `REGEX_TEST`
623 /// environment variable, which may be set to include or exclude tests.
624 /// See the docs on `TestRunner` for its format.
625 pub fn newrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]new().() -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner#> {
626 let mut runner = TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner# {
627 includerust-analyzer cargo regex-test 0.1.1 TestRunner#include.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![],
628 resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results.: RegexTestResultsrust-analyzer cargo regex-test 0.1.1 RegexTestResults#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]new().(),
629 expandersrust-analyzer cargo regex-test 0.1.1 TestRunner#expanders.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![],
630 };
631 for mut substring in read_envrust-analyzer cargo regex-test 0.1.1 read_env().(ENV_REGEX_TESTrust-analyzer cargo regex-test 0.1.1 ENV_REGEX_TEST.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(",") {
632 substring = substring.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().();
633 if substring.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
634 continue;
635 }
636 if substring.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("-") {
637 runner.blacklistrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]blacklist().(&substring[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
638 } else {
639 runner.whitelistrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]whitelist().(substring);
640 }
641 }
642 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(runner)
643 }
644
645 /// Assert that all tests run have either passed or have been skipped.
646 ///
647 /// If any tests have failed, then a panic occurs with a report of all
648 /// failures.
649 ///
650 /// If `REGEX_TEST_VERBOSE` is set to `1`, then a longer report of tests
651 /// that passed, failed or skipped is printed.
652 pub fn assertrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]assert().(&mut self) {
653 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..assertrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]assert().();
654 }
655
656 /// Whitelist the given substring.
657 ///
658 /// Whitelist and blacklist rules are only applied when
659 /// [`TestRunner::test_iter`] is called.
660 pub fn whitelistrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]whitelist().(&mut self, substring: &str) -> &mut TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner# {
661 self.includerust-analyzer cargo regex-test 0.1.1 TestRunner#include..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(IncludePatternrust-analyzer cargo regex-test 0.1.1 IncludePattern# {
662 blacklistrust-analyzer cargo regex-test 0.1.1 IncludePattern#blacklist.: false,
663 substringrust-analyzer cargo regex-test 0.1.1 IncludePattern#substring.: BStringrust-analyzer cargo bstr 1.13.1 bstring/BString#::fromrust-analyzer cargo bstr 1.13.1 impls/bstring/impl#[BString][`From<&'a str>`]from().(substring),
664 });
665 self
666 }
667
668 /// Whitelist the given iterator substrings.
669 ///
670 /// This is a convenience routine for calling `whitelist` on each of the
671 /// substrings in the iterator provided.
672 ///
673 /// Whitelist and blacklist rules are only applied when
674 /// [`TestRunner::test_iter`] is called.
675 pub fn whitelist_iterrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]whitelist_iter().<I, S>(&mut self, substrings: I) -> &mut TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner#
676 where
677 I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = S>,
678 S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>,
679 {
680 for substring in substrings {
681 self.whitelistrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]whitelist().(substring.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().());
682 }
683 self
684 }
685
686 /// Blacklist the given substring.
687 ///
688 /// A blacklisted test is never run, unless a whitelisted substring added
689 /// after the blacklisted substring matches it.
690 ///
691 /// Whitelist and blacklist rules are only applied when
692 /// [`TestRunner::test_iter`] is called.
693 pub fn blacklistrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]blacklist().(&mut self, substring: &str) -> &mut TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner# {
694 self.includerust-analyzer cargo regex-test 0.1.1 TestRunner#include..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(IncludePatternrust-analyzer cargo regex-test 0.1.1 IncludePattern# {
695 blacklistrust-analyzer cargo regex-test 0.1.1 IncludePattern#blacklist.: true,
696 substringrust-analyzer cargo regex-test 0.1.1 IncludePattern#substring.: BStringrust-analyzer cargo bstr 1.13.1 bstring/BString#::fromrust-analyzer cargo bstr 1.13.1 impls/bstring/impl#[BString][`From<&'a str>`]from().(substring),
697 });
698 self
699 }
700
701 /// Blacklist the given iterator substrings.
702 ///
703 /// A blacklisted test is never run, unless a whitelisted substring added
704 /// after the blacklisted substring matches it.
705 ///
706 /// This is a convenience routine for calling `blacklist` on each of the
707 /// substrings in the iterator provided.
708 ///
709 /// Whitelist and blacklist rules are only applied when
710 /// [`TestRunner::test_iter`] is called.
711 pub fn blacklist_iterrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]blacklist_iter().<I, S>(&mut self, substrings: I) -> &mut TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner#
712 where
713 I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = S>,
714 S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>,
715 {
716 for substring in substrings {
717 self.blacklistrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]blacklist().(substring.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().());
718 }
719 self
720 }
721
722 /// Set an expansion predicate that appends each entry in
723 /// `additional_names` to the end the name for every test that `predicate`
724 /// returns true. Moreover, the corresponding additional name is made
725 /// available via [`RegexTest::additional_name`].
726 ///
727 /// This permits implementors to create multiple copies of each test, and
728 /// then do specifically different tasks with each, while making it so each
729 /// test is distinct.
730 ///
731 /// For example, you might write something like this:
732 ///
733 /// ```ignore
734 /// TestRunner::new()?
735 /// .expand(&["is_match", "find"], |t| t.compiles())
736 /// .test_iter(tests, compiler)
737 /// .assert()
738 /// ```
739 ///
740 /// where each test that is expected to have a regex compile gets copied
741 /// with `/is_match` and `/find` appends to the end of its name. Then, in
742 /// your own test runner, you can inspect [`RegexTest::additional_name`] to
743 /// decide what to do. In the case of `is_match`, you might test your regex
744 /// engines "has a match" API, which might exercise different logic than
745 /// your "find where the matches are" API.
746 pub fn expandrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]expand().<S: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str>>(
747 &mut self,
748 additional_names: &[S],
749 predicate: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#) -> bool + 'static,
750 ) -> &mut TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner# {
751 self.expandersrust-analyzer cargo regex-test 0.1.1 TestRunner#expanders..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Expanderrust-analyzer cargo regex-test 0.1.1 Expander# {
752 predicaterust-analyzer cargo regex-test 0.1.1 Expander#predicate.: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(predicate),
753 additional_namesrust-analyzer cargo regex-test 0.1.1 Expander#additional_names.: additional_names
754 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
755 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
756 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(),
757 });
758 self
759 }
760
761 /// Run all of the given tests using the given regex compiler.
762 ///
763 /// The compiler given is a closure that accepts a
764 /// [`&RegexTest`](RegexTest) and a sequence of patterns, and returns (if
765 /// successful) a [`CompiledRegex`] which can execute a search.
766 ///
767 /// Note that if there are test failures, this merely _collects_ them. Use
768 /// [`TestRunner::assert`] to fail the current test by panicking if there
769 /// any failures.
770 ///
771 /// Typically, one provides [`RegexTests::iter`] as the iterator of
772 /// `RegexTest` values.
773 pub fn test_iterrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]test_iter().<I, T>(
774 &mut self,
775 it: I,
776 mut compile: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#, &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#]) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<CompiledRegexrust-analyzer cargo regex-test 0.1.1 CompiledRegex#>,
777 ) -> &mut TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner#
778 where
779 I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = T>,
780 T: Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#>,
781 {
782 for test in it {
783 let test = test.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().();
784 let mut additional = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
785 for expander in &mut self.expandersrust-analyzer cargo regex-test 0.1.1 TestRunner#expanders. {
786 if (expander.predicaterust-analyzer cargo regex-test 0.1.1 Expander#predicate.)(test) {
787 for name in expander.additional_namesrust-analyzer cargo regex-test 0.1.1 Expander#additional_names..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
788 additional.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(test.with_additional_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]with_additional_name().(name));
789 }
790 break;
791 }
792 }
793 if additional.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
794 additional.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(test.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().());
795 }
796 for test in &additional {
797 if self.should_skiprust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]should_skip().(test) {
798 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..skiprust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]skip().(test);
799 continue;
800 }
801 self.testrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]test().(test, |regexes| compile(test, regexes));
802 }
803 }
804 self
805 }
806
807 /// Run a single test.
808 ///
809 /// This records the result of running the test in this runner. This does
810 /// not fail the test immediately if the given regex test fails. Instead,
811 /// this is only done when the `assert` method is called.
812 ///
813 /// Note that using this method bypasses any whitelist or blacklist applied
814 /// to this runner. Whitelisted (and blacklisted) substrings are only
815 /// applied when using `test_iter`.
816 pub fn testrust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]test().(
817 &mut self,
818 test: &RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#,
819 mut compile: impl FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#]) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<CompiledRegexrust-analyzer cargo regex-test 0.1.1 CompiledRegex#>,
820 ) -> &mut TestRunnerrust-analyzer cargo regex-test 0.1.1 TestRunner# {
821 let mut compiled = match saferust-analyzer cargo regex-test 0.1.1 safe().(|| compile(test.regexesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]regexes().())) {
822 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(msg) => {
823 // Regex tests should never panic. It's auto-fail if they do.
824 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..failrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]fail().(
825 test,
826 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::UnexpectedPanicCompilerust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UnexpectedPanicCompile#(msg),
827 );
828 return self;
829 }
830 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(compiled)) => compiled,
831 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err)) => {
832 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().test.compilesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]compiles().() {
833 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..passrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]pass().(test);
834 } else {
835 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..failrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]fail().(
836 test,
837 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::CompileErrorrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#CompileError# { errrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#CompileError#err. },
838 );
839 }
840 return self;
841 }
842 };
843 // We fail the test if we didn't expect the regex to compile. However,
844 // it's possible the caller decided to skip the test when attempting
845 // to compile the regex, so we check for that. If the compiled regex
846 // is marked as skipped, then 'test.test(..)' below handles it
847 // correctly.
848 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().test.compilesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]compiles().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().compiled.is_skiprust-analyzer cargo regex-test 0.1.1 impl#[CompiledRegex]is_skip().() {
849 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..failrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]fail().(test, RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::NoCompileErrorrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#NoCompileError#);
850 return self;
851 }
852 let result = match saferust-analyzer cargo regex-test 0.1.1 safe().(|| test.testrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]test().(&mut compiled)) {
853 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(result) => result,
854 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(msg) => {
855 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..failrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]fail().(
856 test,
857 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::UnexpectedPanicSearchrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UnexpectedPanicSearch#(msg),
858 );
859 return self;
860 }
861 };
862 match result.kindrust-analyzer cargo regex-test 0.1.1 TestResult#kind. {
863 TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::Matchrust-analyzer cargo regex-test 0.1.1 TestResultKind#Match#(yes) => {
864 if yes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().test.is_matchrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]is_match().() {
865 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..passrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]pass().(test);
866 } else {
867 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..failrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]fail().(test, RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::IsMatchrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#IsMatch#);
868 }
869 }
870 TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::Whichrust-analyzer cargo regex-test 0.1.1 TestResultKind#Which#(which) => {
871 if which rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]ne().test.which_matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]which_matches().() {
872 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results.
873 .failrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]fail().(test, RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::Manyrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Many# { gotrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Many#got.: which });
874 } else {
875 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..passrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]pass().(test);
876 }
877 }
878 TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::StartEndrust-analyzer cargo regex-test 0.1.1 TestResultKind#StartEnd#(matches) => {
879 let expected = test.matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]matches().();
880 if expected rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]ne().matches {
881 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..failrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]fail().(
882 test,
883 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::StartEndrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#StartEnd# { gotrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#StartEnd#got.: matches },
884 );
885 } else {
886 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..passrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]pass().(test);
887 }
888 }
889 TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::Capturesrust-analyzer cargo regex-test 0.1.1 TestResultKind#Captures#(caps) => {
890 let expected = test.capturesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]captures().();
891 if expected rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]ne().!=rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]ne(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/partial_eq/impl#[`Vec<T, A1>`][`PartialEq<Vec<U, A2>>`]ne().caps {
892 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..failrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]fail().(
893 test,
894 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::Capturesrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Captures# { gotrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Captures#got.: caps },
895 );
896 } else {
897 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..passrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]pass().(test);
898 }
899 }
900 TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::Skiprust-analyzer cargo regex-test 0.1.1 TestResultKind#Skip# => {
901 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results..skiprust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]skip().(test);
902 }
903 TestResultKindrust-analyzer cargo regex-test 0.1.1 TestResultKind#::Failrust-analyzer cargo regex-test 0.1.1 TestResultKind#Fail# { whyrust-analyzer cargo regex-test 0.1.1 TestResultKind#Fail#why. } => {
904 self.resultsrust-analyzer cargo regex-test 0.1.1 TestRunner#results.
905 .failrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]fail().(test, RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::UserFailurerust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UserFailure# { whyrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UserFailure#why. });
906 }
907 }
908 self
909 }
910
911 /// Return true if and only if the given test should be skipped.
912 fn should_skiprust-analyzer cargo regex-test 0.1.1 impl#[TestRunner]should_skip().(&self, test: &RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#) -> bool {
913 if self.includerust-analyzer cargo regex-test 0.1.1 TestRunner#include..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
914 return false;
915 }
916
917 // If we don't have any whitelist patterns, then the test will be run
918 // unless it is blacklisted. Otherwise, if there are whitelist
919 // patterns, then the test must match at least one of them.
920 let mut skip = self.includerust-analyzer cargo regex-test 0.1.1 TestRunner#include..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]any().(|pat| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().pat.blacklistrust-analyzer cargo regex-test 0.1.1 IncludePattern#blacklist.);
921 for pat in &self.includerust-analyzer cargo regex-test 0.1.1 TestRunner#include. {
922 if test.full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]full_name().().as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().contains_strrust-analyzer cargo bstr 1.13.1 ext_slice/ByteSlice#contains_str().(&pat.substringrust-analyzer cargo regex-test 0.1.1 IncludePattern#substring.) {
923 skip = pat.blacklistrust-analyzer cargo regex-test 0.1.1 IncludePattern#blacklist.;
924 }
925 }
926 skip
927 }
928 }
929
930 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
931 struct IncludePatternrust-analyzer cargo regex-test 0.1.1 IncludePattern# {
932 blacklistrust-analyzer cargo regex-test 0.1.1 IncludePattern#blacklist.: bool,
933 substringrust-analyzer cargo regex-test 0.1.1 IncludePattern#substring.: BStringrust-analyzer cargo bstr 1.13.1 bstring/BString#,
934 }
935
936 struct Expanderrust-analyzer cargo regex-test 0.1.1 Expander# {
937 predicaterust-analyzer cargo regex-test 0.1.1 Expander#predicate.: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#) -> bool>,
938 additional_namesrust-analyzer cargo regex-test 0.1.1 Expander#additional_names.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
939 }
940
941 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Expanderrust-analyzer cargo regex-test 0.1.1 Expander# {
942 fn fmtrust-analyzer cargo regex-test 0.1.1 impl#[Expander][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
943 f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("Expander")
944 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("predicate", &"<FnMut(..)>")
945 .fieldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]field().("additional_names", &self.additional_namesrust-analyzer cargo regex-test 0.1.1 Expander#additional_names.)
946 .finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().()
947 }
948 }
949
950 /// A collection of test results, corresponding to passed, skipped and failed
951 /// tests.
952 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
953 struct RegexTestResultsrust-analyzer cargo regex-test 0.1.1 RegexTestResults# {
954 passrust-analyzer cargo regex-test 0.1.1 RegexTestResults#pass.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<RegexTestResultrust-analyzer cargo regex-test 0.1.1 RegexTestResult#>,
955 failrust-analyzer cargo regex-test 0.1.1 RegexTestResults#fail.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<RegexTestFailurerust-analyzer cargo regex-test 0.1.1 RegexTestFailure#>,
956 skiprust-analyzer cargo regex-test 0.1.1 RegexTestResults#skip.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<RegexTestResultrust-analyzer cargo regex-test 0.1.1 RegexTestResult#>,
957 }
958
959 /// A test that passed or skipped, along with its specific result.
960 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
961 struct RegexTestResultrust-analyzer cargo regex-test 0.1.1 RegexTestResult# {
962 testrust-analyzer cargo regex-test 0.1.1 RegexTestResult#test.: RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#,
963 }
964
965 /// A test that failed along with the reason why.
966 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
967 struct RegexTestFailurerust-analyzer cargo regex-test 0.1.1 RegexTestFailure# {
968 testrust-analyzer cargo regex-test 0.1.1 RegexTestFailure#test.: RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#,
969 kindrust-analyzer cargo regex-test 0.1.1 RegexTestFailure#kind.: RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#,
970 }
971
972 /// Describes the nature of the failed test.
973 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
974 enum RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind# {
975 /// UserFailure indicates that the test failed because the test function
976 /// explicitly failed it for the reason in the message given.
977 UserFailurerust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UserFailure# { whyrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UserFailure#why.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# },
978 /// This occurs when the test expected a match (or didn't expect a match),
979 /// but the actual regex implementation didn't match (or did match).
980 IsMatchrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#IsMatch#,
981 /// This occurs when a set of regexes is tested, and the matching regexes
982 /// returned by the regex implementation don't match the expected matching
983 /// regexes. This error contains the indices of the regexes that matched.
984 Manyrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Many# { gotrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Many#got.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize> },
985 /// This occurs when a single regex is used to find all non-overlapping
986 /// matches in a haystack, where the result did not match what was
987 /// expected. This reports the incorrect matches returned by the regex
988 /// implementation under test.
989 StartEndrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#StartEnd# { gotrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#StartEnd#got.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Matchrust-analyzer cargo regex-test 0.1.1 Match#> },
990 /// Like StartEnd, but for capturing groups.
991 Capturesrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Captures# { gotrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Captures#got.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Capturesrust-analyzer cargo regex-test 0.1.1 Captures#> },
992 /// This occurs when the test expected the regex to fail to compile, but it
993 /// compiled successfully.
994 NoCompileErrorrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#NoCompileError#,
995 /// This occurs when the test expected the regex to compile successfully,
996 /// but it failed to compile.
997 CompileErrorrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#CompileError# { errrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#CompileError#err.: anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Errorrust-analyzer cargo anyhow 1.0.104 Error# },
998 /// While compiling, a panic occurred. If possible, the panic message
999 /// is captured.
1000 UnexpectedPanicCompilerust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UnexpectedPanicCompile#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
1001 /// While searching, a panic occurred. If possible, the panic message
1002 /// is captured.
1003 UnexpectedPanicSearchrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UnexpectedPanicSearch#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
1004 }
1005
1006 impl RegexTestResultsrust-analyzer cargo regex-test 0.1.1 RegexTestResults# {
1007 fn newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]new().() -> RegexTestResultsrust-analyzer cargo regex-test 0.1.1 RegexTestResults# {
1008 RegexTestResultsrust-analyzer cargo regex-test 0.1.1 RegexTestResults# { passrust-analyzer cargo regex-test 0.1.1 RegexTestResults#pass.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], failrust-analyzer cargo regex-test 0.1.1 RegexTestResults#fail.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], skiprust-analyzer cargo regex-test 0.1.1 RegexTestResults#skip.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![] }
1009 }
1010
1011 fn passrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]pass().(&mut self, test: &RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#) {
1012 self.passrust-analyzer cargo regex-test 0.1.1 RegexTestResults#pass..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(RegexTestResultrust-analyzer cargo regex-test 0.1.1 RegexTestResult# { testrust-analyzer cargo regex-test 0.1.1 RegexTestResult#test.: test.clonerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest][Clone]clone().() });
1013 }
1014
1015 fn failrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]fail().(&mut self, test: &RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#, kind: RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#) {
1016 self.failrust-analyzer cargo regex-test 0.1.1 RegexTestResults#fail..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(RegexTestFailurerust-analyzer cargo regex-test 0.1.1 RegexTestFailure# { testrust-analyzer cargo regex-test 0.1.1 RegexTestFailure#test.: test.clonerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest][Clone]clone().(), kindrust-analyzer cargo regex-test 0.1.1 RegexTestFailure#kind. });
1017 }
1018
1019 fn skiprust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]skip().(&mut self, test: &RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#) {
1020 self.skiprust-analyzer cargo regex-test 0.1.1 RegexTestResults#skip..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(RegexTestResultrust-analyzer cargo regex-test 0.1.1 RegexTestResult# { testrust-analyzer cargo regex-test 0.1.1 RegexTestResult#test.: test.clonerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest][Clone]clone().() });
1021 }
1022
1023 fn assertrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]assert().(&self) {
1024 if read_envrust-analyzer cargo regex-test 0.1.1 read_env().(ENV_REGEX_TEST_VERBOSErust-analyzer cargo regex-test 0.1.1 ENV_REGEX_TEST_VERBOSE.).map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_or().(false, |s| s rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."1") {
1025 self.verboserust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]verbose().();
1026 }
1027 if self.failrust-analyzer cargo regex-test 0.1.1 RegexTestResults#fail..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
1028 return;
1029 }
1030 let failures = self
1031 .failrust-analyzer cargo regex-test 0.1.1 RegexTestResults#fail.
1032 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
1033 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|f| f.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
1034 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>()
1035 .joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n\n");
1036 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!(
1037 "found {} failures:\n{}\n{}\n{}\n\n\
1038 Set the REGEX_TEST environment variable to filter tests, \n\
1039 e.g., REGEX_TEST=foo,-foo2 runs every test whose name contains \n\
1040 foo but not foo2\n\n",
1041 self.failrust-analyzer cargo regex-test 0.1.1 RegexTestResults#fail..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
1042 "~".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(79),
1043 failures.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().(),
1044 "~".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(79),
1045 )
1046 }
1047
1048 fn verboserust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResults]verbose().(&self) {
1049 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}", "~".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(79));
1050 for t in &self.skiprust-analyzer cargo regex-test 0.1.1 RegexTestResults#skip. {
1051 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("skip: {}", t.full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResult]full_name().());
1052 }
1053 for t in &self.passrust-analyzer cargo regex-test 0.1.1 RegexTestResults#pass. {
1054 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("pass: {}", t.full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResult]full_name().());
1055 }
1056 for t in &self.failrust-analyzer cargo regex-test 0.1.1 RegexTestResults#fail. {
1057 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("FAIL: {}", t.testrust-analyzer cargo regex-test 0.1.1 RegexTestFailure#test..full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]full_name().());
1058 }
1059 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
1060 "\npassed: {}, skipped: {}, failed: {}",
1061 self.passrust-analyzer cargo regex-test 0.1.1 RegexTestResults#pass..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
1062 self.skiprust-analyzer cargo regex-test 0.1.1 RegexTestResults#skip..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(),
1063 self.failrust-analyzer cargo regex-test 0.1.1 RegexTestResults#fail..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()
1064 );
1065 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{}", "~".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(79));
1066 }
1067 }
1068
1069 impl RegexTestResultrust-analyzer cargo regex-test 0.1.1 RegexTestResult# {
1070 fn full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTestResult]full_name().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
1071 self.testrust-analyzer cargo regex-test 0.1.1 RegexTestResult#test..full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]full_name().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
1072 }
1073 }
1074
1075 impl RegexTestFailurerust-analyzer cargo regex-test 0.1.1 RegexTestFailure# {
1076 fn full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTestFailure]full_name().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
1077 self.testrust-analyzer cargo regex-test 0.1.1 RegexTestFailure#test..full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]full_name().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
1078 }
1079 }
1080
1081 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for RegexTestFailurerust-analyzer cargo regex-test 0.1.1 RegexTestFailure# {
1082 fn fmtrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestFailure][Display]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
1083 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
1084 f,
1085 "{}: {}\n\
1086 pattern: {:?}\n\
1087 haystack: {:?}",
1088 self.full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTestFailure]full_name().(),
1089 self.kindrust-analyzer cargo regex-test 0.1.1 RegexTestFailure#kind..fmtrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestFailureKind]fmt().(&self.testrust-analyzer cargo regex-test 0.1.1 RegexTestFailure#test.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
1090 self.testrust-analyzer cargo regex-test 0.1.1 RegexTestFailure#test..regexesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]regexes().(),
1091 self.testrust-analyzer cargo regex-test 0.1.1 RegexTestFailure#test..haystackrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]haystack().().as_bstrrust-analyzer cargo bstr 1.13.1 ext_slice/ByteSlice#as_bstr().(),
1092 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1093 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
1094 }
1095 }
1096
1097 impl RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind# {
1098 fn fmtrust-analyzer cargo regex-test 0.1.1 impl#[RegexTestFailureKind]fmt().(&self, test: &RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> {
1099 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#;
1100
1101 let mut buf = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
1102 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self {
1103 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::UserFailurerust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UserFailure# { ref whyrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UserFailure#why. } => {
1104 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(buf, "failed by implementor because: {}", why)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1105 }
1106 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::IsMatchrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#IsMatch# => {
1107 if test.is_matchrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]is_match().() {
1108 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(buf, "expected match, but none found")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1109 } else {
1110 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(buf, "expected no match, but found a match")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1111 }
1112 }
1113 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::Manyrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Many# { ref gotrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Many#got. } => {
1114 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
1115 buf,
1116 "expected regexes {:?} to match, but found {:?}",
1117 test.which_matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]which_matches().(),
1118 got
1119 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1120 }
1121 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::StartEndrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#StartEnd# { ref gotrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#StartEnd#got. } => {
1122 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
1123 buf,
1124 "did not find expected matches\n\
1125 expected: {:?}\n \
1126 got: {:?}",
1127 test.matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]matches().(),
1128 got,
1129 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1130 }
1131 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::Capturesrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Captures# { ref gotrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#Captures#got. } => {
1132 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
1133 buf,
1134 "expected to find {:?} captures, but got {:?}",
1135 test.capturesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]captures().(),
1136 got,
1137 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1138 }
1139 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::NoCompileErrorrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#NoCompileError# => {
1140 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(buf, "expected regex to NOT compile, but it did")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1141 }
1142 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::CompileErrorrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#CompileError# { ref errrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#CompileError#err. } => {
1143 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(buf, "expected regex to compile, failed: {}", err)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1144 }
1145 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::UnexpectedPanicCompilerust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UnexpectedPanicCompile#(ref msg) => {
1146 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(buf, "got unexpected panic while compiling:\n{}", msg)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1147 }
1148 RegexTestFailureKindrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#::UnexpectedPanicSearchrust-analyzer cargo regex-test 0.1.1 RegexTestFailureKind#UnexpectedPanicSearch#(ref msg) => {
1149 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(buf, "got unexpected panic while searching:\n{}", msg)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1150 }
1151 }
1152 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buf)
1153 }
1154 }
1155
1156 /// An iterator over regex tests.
1157 ///
1158 /// This iterator is created by the [`RegexTests::iter`] method.
1159 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
1160 pub struct RegexTestsIterrust-analyzer cargo regex-test 0.1.1 RegexTestsIter#<'a>(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#<'a, RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#>);
1161
1162 impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for RegexTestsIterrust-analyzer cargo regex-test 0.1.1 RegexTestsIter#<'a> {
1163 type Itemrust-analyzer cargo regex-test 0.1.1 impl#[`RegexTestsIter<'a>`][Iterator]Item# = &'a RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#;
1164
1165 fn nextrust-analyzer cargo regex-test 0.1.1 impl#[`RegexTestsIter<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a RegexTestrust-analyzer cargo regex-test 0.1.1 RegexTest#> {
1166 self.0rust-analyzer cargo regex-test 0.1.1 RegexTestsIter#0..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().()
1167 }
1168 }
1169
1170 /// Represents either a single regex or a list of regexes in a TOML.
1171 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
1172 #[serde(untagged)]
1173 enum RegexesFormatrust-analyzer cargo regex-test 0.1.1 RegexesFormat# {
1174 Singlerust-analyzer cargo regex-test 0.1.1 RegexesFormat#Single#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
1175 Manyrust-analyzer cargo regex-test 0.1.1 RegexesFormat#Many#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>),
1176 }
1177
1178 impl RegexesFormatrust-analyzer cargo regex-test 0.1.1 RegexesFormat# {
1179 fn patternsrust-analyzer cargo regex-test 0.1.1 impl#[RegexesFormat]patterns().(&self) -> &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#] {
1180 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self {
1181 RegexesFormatrust-analyzer cargo regex-test 0.1.1 RegexesFormat#::Singlerust-analyzer cargo regex-test 0.1.1 RegexesFormat#Single#(ref pat) => stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::from_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/raw/from_ref().(pat),
1182 RegexesFormatrust-analyzer cargo regex-test 0.1.1 RegexesFormat#::Manyrust-analyzer cargo regex-test 0.1.1 RegexesFormat#Many#(ref pats) => pats,
1183 }
1184 }
1185 }
1186
1187 /// Captures represents a single group of captured matches from a regex search.
1188 ///
1189 /// There is always at least 1 group, and the first group is always present and
1190 /// corresponds to the overall match.
1191 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
1192 #[serde(try_from = "CapturesFormat")]
1193 pub struct Capturesrust-analyzer cargo regex-test 0.1.1 Captures# {
1194 /// The ID of the regex that matched.
1195 ///
1196 /// The ID is the index of the regex provided to the regex compiler,
1197 /// starting from `0`. In the case of a single regex search, the only
1198 /// possible ID is `0`.
1199 idrust-analyzer cargo regex-test 0.1.1 Captures#id.: usize,
1200 /// The capturing groups that matched, along with the match offsets for
1201 /// each. The first group should always be non-None, as it corresponds to
1202 /// the overall match.
1203 ///
1204 /// This should either have length 1 (when not capturing group offsets are
1205 /// included in the tes tresult) or it should have length equal to the
1206 /// number of capturing groups in the regex pattern.
1207 groupsrust-analyzer cargo regex-test 0.1.1 Captures#groups.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Spanrust-analyzer cargo regex-test 0.1.1 Span#>>,
1208 }
1209
1210 impl Capturesrust-analyzer cargo regex-test 0.1.1 Captures# {
1211 /// Create a new set of captures for a single match of a regex.
1212 ///
1213 /// If available, iterator should provide items for every capturing group
1214 /// in the regex, including the 0th capturing group corresponding to the
1215 /// entire match. At minimum, the 0th capturing group should be provided.
1216 ///
1217 /// If a capturing group did not participate in the match, then a `None`
1218 /// value should be used. (The 0th capturing group should never be `None`.)
1219 ///
1220 /// If the iterator yields no elements or the first group is `None`, then
1221 /// this returns an error.
1222 ///
1223 /// The `id` should be the ID of the pattern that matched. This is always
1224 /// `0` for single-pattern regexes. Otherwise, the ID of a pattern starts
1225 /// at `0` and is incremented by 1 for each subsequent pattern.
1226 ///
1227 /// Note that there are possibly more convenient and infallible `From`
1228 /// impls for converting a `Match` or a `Span` into a `Captures`.
1229 pub fn newrust-analyzer cargo regex-test 0.1.1 impl#[Captures]new().<I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Spanrust-analyzer cargo regex-test 0.1.1 Span#>>>(
1230 id: usize,
1231 it: I,
1232 ) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<Capturesrust-analyzer cargo regex-test 0.1.1 Captures#> {
1233 let groups: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Spanrust-analyzer cargo regex-test 0.1.1 Span#>> = it.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1234 if groups.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
1235 bailrust-analyzer cargo anyhow 1.0.104 macros/bail!!("captures must contain at least one group");
1236 } else if groups[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() {
1237 bailrust-analyzer cargo anyhow 1.0.104 macros/bail!!("first group (index 0) of captures must be non-None");
1238 }
1239 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Capturesrust-analyzer cargo regex-test 0.1.1 Captures# { idrust-analyzer cargo regex-test 0.1.1 Captures#id., groupsrust-analyzer cargo regex-test 0.1.1 Captures#groups. })
1240 }
1241
1242 /// Returns the ID of the pattern that matched.
1243 ///
1244 /// For any single pattern regexes, this should always be zero.
1245 pub fn idrust-analyzer cargo regex-test 0.1.1 impl#[Captures]id().(&self) -> usize {
1246 self.idrust-analyzer cargo regex-test 0.1.1 Captures#id.
1247 }
1248
1249 /// Returns a slice of the underlying spans, each group corresponding to
1250 /// the (possibly) matched span. The first group in the slice returned
1251 /// is guaranteed to correspond to the overall match span and is thus
1252 /// non-`None`. All other groups may be `None`. Similarly, the slice is
1253 /// guaranteed to have length at least 1.
1254 pub fn groupsrust-analyzer cargo regex-test 0.1.1 impl#[Captures]groups().(&self) -> &[Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Spanrust-analyzer cargo regex-test 0.1.1 Span#>] {
1255 &self.groupsrust-analyzer cargo regex-test 0.1.1 Captures#groups.
1256 }
1257
1258 /// Returns the number of groups (including the first) in these captures.
1259 ///
1260 /// The length returned is guaranteed to be greater than zero.
1261 pub fn lenrust-analyzer cargo regex-test 0.1.1 impl#[Captures]len().(&self) -> usize {
1262 self.groupsrust-analyzer cargo regex-test 0.1.1 Captures#groups..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()
1263 }
1264
1265 /// Returns the overall match, including the pattern ID, for this group
1266 /// of captures.
1267 pub fn to_matchrust-analyzer cargo regex-test 0.1.1 impl#[Captures]to_match().(&self) -> Matchrust-analyzer cargo regex-test 0.1.1 Match# {
1268 Matchrust-analyzer cargo regex-test 0.1.1 Match# { idrust-analyzer cargo regex-test 0.1.1 Match#id.: self.idrust-analyzer cargo regex-test 0.1.1 impl#[Captures]id().(), spanrust-analyzer cargo regex-test 0.1.1 Match#span.: self.to_spanrust-analyzer cargo regex-test 0.1.1 impl#[Captures]to_span().() }
1269 }
1270
1271 /// Returns the overall match span for this group of captures.
1272 pub fn to_spanrust-analyzer cargo regex-test 0.1.1 impl#[Captures]to_span().(&self) -> Spanrust-analyzer cargo regex-test 0.1.1 Span# {
1273 // This is OK because a Captures value must always have at least one
1274 // group where the first group always corresponds to match offsets.
1275 self.groupsrust-analyzer cargo regex-test 0.1.1 Captures#groups.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()
1276 }
1277 }
1278
1279 /// Converts a plain `Match` to a `Captures` value, where the match corresponds
1280 /// to the first and only group in `Captures`.
1281 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Matchrust-analyzer cargo regex-test 0.1.1 Match#> for Capturesrust-analyzer cargo regex-test 0.1.1 Captures# {
1282 fn fromrust-analyzer cargo regex-test 0.1.1 impl#[Captures][`From<Match>`]from().(m: Matchrust-analyzer cargo regex-test 0.1.1 Match#) -> Capturesrust-analyzer cargo regex-test 0.1.1 Captures# {
1283 Capturesrust-analyzer cargo regex-test 0.1.1 Captures# { idrust-analyzer cargo regex-test 0.1.1 Captures#id.: m.idrust-analyzer cargo regex-test 0.1.1 Match#id., groupsrust-analyzer cargo regex-test 0.1.1 Captures#groups.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(m.spanrust-analyzer cargo regex-test 0.1.1 Match#span.)] }
1284 }
1285 }
1286
1287 /// Converts a plain `Span` to a `Captures` value, where the span corresponds to
1288 /// the first and only group in `Captures`. Since a `Span` does not contain a
1289 /// pattern ID, the pattern ID used in this conversion is always `0`.
1290 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Spanrust-analyzer cargo regex-test 0.1.1 Span#> for Capturesrust-analyzer cargo regex-test 0.1.1 Captures# {
1291 fn fromrust-analyzer cargo regex-test 0.1.1 impl#[Captures][`From<Span>`]from().(sp: Spanrust-analyzer cargo regex-test 0.1.1 Span#) -> Capturesrust-analyzer cargo regex-test 0.1.1 Captures# {
1292 Capturesrust-analyzer cargo regex-test 0.1.1 Captures# { idrust-analyzer cargo regex-test 0.1.1 Captures#id.: 0, groupsrust-analyzer cargo regex-test 0.1.1 Captures#groups.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(sp)] }
1293 }
1294 }
1295
1296 /// Represents the actual 'captures' key format more faithfully such that
1297 /// Serde can deserialize it.
1298 ///
1299 /// Namely, we need a way to represent a 'None' value inside a TOML array, and
1300 /// TOML has no 'null' value. So we make '[]' be 'None', and we use 'MaybeSpan'
1301 /// to recognize it.
1302 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:)]
1303 #[serde(untagged)]
1304 enum CapturesFormatrust-analyzer cargo regex-test 0.1.1 CapturesFormat# {
1305 Spanrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Span#([usize; 2]),
1306 Matchrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Match# { idrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Match#id.: usize, spanrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Match#span.: [usize; 2] },
1307 Spansrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Spans#(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<MaybeSpanrust-analyzer cargo regex-test 0.1.1 MaybeSpan#>),
1308 Capturesrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Captures# { idrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Captures#id.: usize, spansrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Captures#spans.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<MaybeSpanrust-analyzer cargo regex-test 0.1.1 MaybeSpan#> },
1309 }
1310
1311 impl TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#<CapturesFormatrust-analyzer cargo regex-test 0.1.1 CapturesFormat#> for Capturesrust-analyzer cargo regex-test 0.1.1 Captures# {
1312 type Errorrust-analyzer cargo regex-test 0.1.1 impl#[Captures][`TryFrom<CapturesFormat>`]Error# = anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Errorrust-analyzer cargo anyhow 1.0.104 Error#;
1313
1314 fn try_fromrust-analyzer cargo regex-test 0.1.1 impl#[Captures][`TryFrom<CapturesFormat>`]try_from().(data: CapturesFormatrust-analyzer cargo regex-test 0.1.1 CapturesFormat#) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<Capturesrust-analyzer cargo regex-test 0.1.1 Captures#> {
1315 match data {
1316 CapturesFormatrust-analyzer cargo regex-test 0.1.1 CapturesFormat#::Spanrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Span#([start, end]) => {
1317 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Capturesrust-analyzer cargo regex-test 0.1.1 Captures# { idrust-analyzer cargo regex-test 0.1.1 Captures#id.: 0, groupsrust-analyzer cargo regex-test 0.1.1 Captures#groups.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start., endrust-analyzer cargo regex-test 0.1.1 Span#end. })] })
1318 }
1319 CapturesFormatrust-analyzer cargo regex-test 0.1.1 CapturesFormat#::Matchrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Match# { idrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Match#id., spanrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Match#span.: [start, end] } => {
1320 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Capturesrust-analyzer cargo regex-test 0.1.1 Captures# { idrust-analyzer cargo regex-test 0.1.1 Captures#id., groupsrust-analyzer cargo regex-test 0.1.1 Captures#groups.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start., endrust-analyzer cargo regex-test 0.1.1 Span#end. })] })
1321 }
1322 CapturesFormatrust-analyzer cargo regex-test 0.1.1 CapturesFormat#::Spansrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Spans#(spans) => {
1323 Capturesrust-analyzer cargo regex-test 0.1.1 Captures#::newrust-analyzer cargo regex-test 0.1.1 impl#[Captures]new().(0, spans.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.into_optionrust-analyzer cargo regex-test 0.1.1 impl#[MaybeSpan]into_option().()))
1324 }
1325 CapturesFormatrust-analyzer cargo regex-test 0.1.1 CapturesFormat#::Capturesrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Captures# { idrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Captures#id., spansrust-analyzer cargo regex-test 0.1.1 CapturesFormat#Captures#spans. } => {
1326 Capturesrust-analyzer cargo regex-test 0.1.1 Captures#::newrust-analyzer cargo regex-test 0.1.1 impl#[Captures]new().(id, spans.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| s.into_optionrust-analyzer cargo regex-test 0.1.1 impl#[MaybeSpan]into_option().()))
1327 }
1328 }
1329 }
1330 }
1331
1332 /// A single match, consisting of the pattern that matched and its span.
1333 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
1334 pub struct Matchrust-analyzer cargo regex-test 0.1.1 Match# {
1335 /// The ID of the pattern that matched.
1336 ///
1337 /// This is always `0` for single-pattern regexes. Otherwise, patterns
1338 /// start at `0` and count upwards in increments of `1`.
1339 pub idrust-analyzer cargo regex-test 0.1.1 Match#id.: usize,
1340 /// The span of the overall match.
1341 pub spanrust-analyzer cargo regex-test 0.1.1 Match#span.: Spanrust-analyzer cargo regex-test 0.1.1 Span#,
1342 }
1343
1344 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Matchrust-analyzer cargo regex-test 0.1.1 Match# {
1345 fn fmtrust-analyzer cargo regex-test 0.1.1 impl#[Match][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
1346 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Match({:?}: {:?})", self.idrust-analyzer cargo regex-test 0.1.1 Match#id., self.spanrust-analyzer cargo regex-test 0.1.1 Match#span.)
1347 }
1348 }
1349
1350 /// A span of contiguous bytes, from start to end, represented via byte
1351 /// offsets.
1352 ///
1353 /// The range is inclusive at the beginning and exclusive at the end.
1354 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
1355 pub struct Spanrust-analyzer cargo regex-test 0.1.1 Span# {
1356 /// The starting byte offset of the match.
1357 pub startrust-analyzer cargo regex-test 0.1.1 Span#start.: usize,
1358 /// The ending byte offset of the match.
1359 pub endrust-analyzer cargo regex-test 0.1.1 Span#end.: usize,
1360 }
1361
1362 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for Spanrust-analyzer cargo regex-test 0.1.1 Span# {
1363 fn fmtrust-analyzer cargo regex-test 0.1.1 impl#[Span][Debug]fmt().(&self, f: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
1364 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{:?}..{:?}", self.startrust-analyzer cargo regex-test 0.1.1 Span#start., self.endrust-analyzer cargo regex-test 0.1.1 Span#end.)
1365 }
1366 }
1367
1368 /// Represents a single span, either present or empty.
1369 ///
1370 /// An empty span is spelled `[]` in TOML, and a present span is spelled `[m,
1371 /// n]`.
1372 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
1373 #[serde(untagged)]
1374 enum MaybeSpanrust-analyzer cargo regex-test 0.1.1 MaybeSpan# {
1375 Nonerust-analyzer cargo regex-test 0.1.1 MaybeSpan#None#([usize; 0]),
1376 Somerust-analyzer cargo regex-test 0.1.1 MaybeSpan#Some#([usize; 2]),
1377 }
1378
1379 impl MaybeSpanrust-analyzer cargo regex-test 0.1.1 MaybeSpan# {
1380 /// Converts this TOML representation of a possibly absent span to a proper
1381 /// `Option<Span>`.
1382 fn into_optionrust-analyzer cargo regex-test 0.1.1 impl#[MaybeSpan]into_option().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Spanrust-analyzer cargo regex-test 0.1.1 Span#> {
1383 match self {
1384 MaybeSpanrust-analyzer cargo regex-test 0.1.1 MaybeSpan#::Nonerust-analyzer cargo regex-test 0.1.1 MaybeSpan#None#(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
1385 MaybeSpanrust-analyzer cargo regex-test 0.1.1 MaybeSpan#::Somerust-analyzer cargo regex-test 0.1.1 MaybeSpan#Some#([start, end]) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start., endrust-analyzer cargo regex-test 0.1.1 Span#end. }),
1386 }
1387 }
1388 }
1389
1390 /// The match semantics to use for a search.
1391 ///
1392 /// When not specified in a test, the default is `MatchKind::LeftmostFirst`.
1393 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
1394 #[serde(rename_all = "kebab-case")]
1395 pub enum MatchKindrust-analyzer cargo regex-test 0.1.1 MatchKind# {
1396 /// All possible matches should be reported.
1397 ///
1398 /// Usually this makes it impossible for non-greedy repetition operators
1399 /// to exist. That is, they behave as greedy repetition operators.
1400 Allrust-analyzer cargo regex-test 0.1.1 MatchKind#All#,
1401 /// Report only the leftmost match. When there are multiple leftmost
1402 /// matches that start at the same position, prefer the one that comes
1403 /// "first" in the pattern. For example, `sam|samwise` matches `sam` in
1404 /// `samwise`.
1405 ///
1406 /// This typically corresponds to the semantics implemented by backtracking
1407 /// engines.
1408 LeftmostFirstrust-analyzer cargo regex-test 0.1.1 MatchKind#LeftmostFirst#,
1409 /// Report only the leftmost match. When there are multiple leftmost
1410 /// matches that start at the same position, prefer the one the longest
1411 /// match. For example, `sam|samwise` matches `samwise` in `samwise`.
1412 ///
1413 /// This typically corresponds to the semantics implemented by POSIX
1414 /// engines.
1415 LeftmostLongestrust-analyzer cargo regex-test 0.1.1 MatchKind#LeftmostLongest#,
1416 }
1417
1418 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for MatchKindrust-analyzer cargo regex-test 0.1.1 MatchKind# {
1419 fn defaultrust-analyzer cargo regex-test 0.1.1 impl#[MatchKind][Default]default().() -> MatchKindrust-analyzer cargo regex-test 0.1.1 MatchKind# {
1420 MatchKindrust-analyzer cargo regex-test 0.1.1 MatchKind#::LeftmostFirstrust-analyzer cargo regex-test 0.1.1 MatchKind#LeftmostFirst#
1421 }
1422 }
1423
1424 /// Represents the type of search to perform.
1425 ///
1426 /// When not specified in a test, the default is `SearchKind::Leftmost`.
1427 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
1428 #[serde(rename_all = "kebab-case")]
1429 pub enum SearchKindrust-analyzer cargo regex-test 0.1.1 SearchKind# {
1430 /// Report matches as soon as they are found.
1431 ///
1432 /// This is somewhat tricky to test, as this semantic is specified in terms
1433 /// of whatever the regex engine can do. For example, an automata oriented
1434 /// engine might be able to report a match earlier than a backtracking
1435 /// engine.
1436 Earliestrust-analyzer cargo regex-test 0.1.1 SearchKind#Earliest#,
1437 /// A standard leftmost search, returning either the leftmost-first or
1438 /// leftmost-longest match. Generally speaking, it doesn't make sense to
1439 /// use this type of search in combination with [`MatchKind::All`].
1440 Leftmostrust-analyzer cargo regex-test 0.1.1 SearchKind#Leftmost#,
1441 /// Return all possible matches, including ones that overlap. Typically
1442 /// this search kind is used in combination with [`MatchKind::All`].
1443 Overlappingrust-analyzer cargo regex-test 0.1.1 SearchKind#Overlapping#,
1444 }
1445
1446 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for SearchKindrust-analyzer cargo regex-test 0.1.1 SearchKind# {
1447 fn defaultrust-analyzer cargo regex-test 0.1.1 impl#[SearchKind][Default]default().() -> SearchKindrust-analyzer cargo regex-test 0.1.1 SearchKind# {
1448 SearchKindrust-analyzer cargo regex-test 0.1.1 SearchKind#::Leftmostrust-analyzer cargo regex-test 0.1.1 SearchKind#Leftmost#
1449 }
1450 }
1451
1452 /// Read the environment variable given. If it doesn't exist, then return an
1453 /// empty string. Otherwise, check that it is valid UTF-8. If it isn't, return
1454 /// a useful error message.
1455 fn read_envrust-analyzer cargo regex-test 0.1.1 read_env().(var: &str) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
1456 let val = match stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().(var) {
1457 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#("".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
1458 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) => val,
1459 };
1460 let val = val.into_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString]into_string().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|os| {
1461 anyhowrust-analyzer cargo anyhow 1.0.104 crate/::anyhowrust-analyzer cargo anyhow 1.0.104 macros/anyhow!!(
1462 "invalid UTF-8 in env var {}={:?}",
1463 var,
1464 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_os_str_lossyrust-analyzer cargo bstr 1.13.1 ext_vec/ByteVec#from_os_str_lossy().(&os)
1465 )
1466 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1467 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(val)
1468 }
1469
1470 /// Runs the given closure such that any panics are caught and converted into
1471 /// errors. If the panic'd value could not be converted to a known error type,
1472 /// then a generic string error message is used.
1473 ///
1474 /// This is useful for use inside the test runner such that bugs for certain
1475 /// tests don't prevent other tests from running.
1476 fn saferust-analyzer cargo regex-test 0.1.1 safe().<T, F>(fun: F) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<T, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>
1477 where
1478 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> T,
1479 {
1480 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/;
1481
1482 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::catch_unwindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/catch_unwind().(panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::AssertUnwindSaferust-analyzer cargo core https://github.com/rust-lang/rust/library/core panic/unwind_safe/AssertUnwindSafe#(fun)).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|any_err| {
1483 // Extract common types of panic payload:
1484 // panic and assert produce &str or String
1485 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&s) = any_err.downcast_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/impl#[`dyn Any + Send + 'static`]downcast_ref().::<&str>() {
1486 s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
1487 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) = any_err.downcast_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/impl#[`dyn Any + Send + 'static`]downcast_ref().::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>() {
1488 s.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().()
1489 } else {
1490 "UNABLE TO SHOW RESULT OF PANIC.".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()
1491 }
1492 })
1493 }
1494
1495 /// A function to set some boolean fields to a default of 'true'. We use a
1496 /// function so that we can hand a path to it to Serde.
1497 fn default_truerust-analyzer cargo regex-test 0.1.1 default_true().() -> bool {
1498 true
1499 }
1500
1501 #[cfg(test)]
1502 mod testsrust-analyzer cargo regex-test 0.1.1 tests/ {
1503 use superrust-analyzer cargo regex-test 0.1.1 crate/::*;
1504
1505 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1506 fn err_no_regexesrust-analyzer cargo regex-test 0.1.1 tests/err_no_regexes().() {
1507 let data = r#"
1508 [[test]]
1509 name = "foo"
1510 haystack = "lib.rs"
1511 matches = true
1512 case-insensitive = true
1513 "#;
1514
1515 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1516 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
1517 }
1518
1519 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1520 fn err_unknown_fieldrust-analyzer cargo regex-test 0.1.1 tests/err_unknown_field().() {
1521 let data = r#"
1522 [[test]]
1523 name = "foo"
1524 regex = ".*.rs"
1525 haystack = "lib.rs"
1526 matches = true
1527 something = 0
1528 "#;
1529
1530 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1531 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
1532 }
1533
1534 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1535 fn err_no_matchesrust-analyzer cargo regex-test 0.1.1 tests/err_no_matches().() {
1536 let data = r#"
1537 [[test]]
1538 name = "foo"
1539 regex = ".*.rs"
1540 haystack = "lib.rs"
1541 "#;
1542
1543 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1544 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
1545 }
1546
1547 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1548 fn load_matchrust-analyzer cargo regex-test 0.1.1 tests/load_match().() {
1549 let data = r#"
1550 [[test]]
1551 name = "foo"
1552 regex = ".*.rs"
1553 haystack = "lib.rs"
1554 matches = [[0, 6]]
1555 compiles = false
1556 anchored = true
1557 case-insensitive = true
1558 unicode = false
1559 utf8 = false
1560 "#;
1561
1562 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1563 tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1564
1565 let t0 = &tests.testsrust-analyzer cargo regex-test 0.1.1 RegexTests#tests.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
1566 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("test", t0.grouprust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]group().());
1567 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("foo", t0.namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]name().());
1568 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("test/foo", t0.full_namerust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]full_name().());
1569 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&[".*.rs"], t0.regexesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]regexes().());
1570 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(true, t0.is_matchrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]is_match().());
1571 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0], t0.which_matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]which_matches().());
1572
1573 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().t0.compilesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]compiles().());
1574 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t0.anchoredrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]anchored().());
1575 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t0.case_insensitiverust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]case_insensitive().());
1576 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().t0.unicoderust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]unicode().());
1577 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().t0.utf8rust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]utf8().());
1578 }
1579
1580 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1581 fn load_which_matchesrust-analyzer cargo regex-test 0.1.1 tests/load_which_matches().() {
1582 let data = r#"
1583 [[test]]
1584 name = "foo"
1585 regex = [".*.rs", ".*.toml"]
1586 haystack = "lib.rs"
1587 matches = [
1588 { id = 0, spans = [[0, 0]] },
1589 { id = 2, spans = [[0, 0]] },
1590 { id = 5, spans = [[0, 0]] },
1591 ]
1592 "#;
1593
1594 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1595 tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1596
1597 let t0 = &tests.testsrust-analyzer cargo regex-test 0.1.1 RegexTests#tests.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
1598 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(&[".*.rs", ".*.toml"], t0.regexesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]regexes().());
1599 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(true, t0.is_matchrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]is_match().());
1600 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0, 2, 5], t0.which_matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]which_matches().());
1601
1602 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t0.compilesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]compiles().());
1603 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().t0.anchoredrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]anchored().());
1604 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().t0.case_insensitiverust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]case_insensitive().());
1605 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t0.unicoderust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]unicode().());
1606 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(t0.utf8rust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]utf8().());
1607 }
1608
1609 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1610 fn load_spansrust-analyzer cargo regex-test 0.1.1 tests/load_spans().() {
1611 let data = r#"
1612 [[test]]
1613 name = "foo"
1614 regex = ".*.rs"
1615 haystack = "lib.rs"
1616 matches = [[0, 2], [5, 10]]
1617 "#;
1618
1619 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1620 tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1621
1622 let spans =
1623 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 0, endrust-analyzer cargo regex-test 0.1.1 Span#end.: 2 }, Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 5, endrust-analyzer cargo regex-test 0.1.1 Span#end.: 10 }];
1624 let t0 = &tests.testsrust-analyzer cargo regex-test 0.1.1 RegexTests#tests.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
1625 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(t0.regexesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]regexes().(), &[".*.rs"]);
1626 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(t0.is_matchrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]is_match().(), true);
1627 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(t0.which_matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]which_matches().(), &[0]);
1628 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1629 t0.matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]matches().(),
1630 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
1631 Matchrust-analyzer cargo regex-test 0.1.1 Match# { idrust-analyzer cargo regex-test 0.1.1 Match#id.: 0, spanrust-analyzer cargo regex-test 0.1.1 Match#span.: spans[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). },
1632 Matchrust-analyzer cargo regex-test 0.1.1 Match# { idrust-analyzer cargo regex-test 0.1.1 Match#id.: 0, spanrust-analyzer cargo regex-test 0.1.1 Match#span.: spans[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). },
1633 ]
1634 );
1635 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1636 t0.capturesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]captures().(),
1637 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
1638 Capturesrust-analyzer cargo regex-test 0.1.1 Captures#::newrust-analyzer cargo regex-test 0.1.1 impl#[Captures]new().(0, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(spans[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
1639 Capturesrust-analyzer cargo regex-test 0.1.1 Captures#::newrust-analyzer cargo regex-test 0.1.1 impl#[Captures]new().(0, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(spans[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)]).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
1640 ]
1641 );
1642 }
1643
1644 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1645 fn load_capture_spansrust-analyzer cargo regex-test 0.1.1 tests/load_capture_spans().() {
1646 let data = r#"
1647 [[test]]
1648 name = "foo"
1649 regex = ".*.rs"
1650 haystack = "lib.rs"
1651 matches = [
1652 [[0, 15], [5, 10], [], [13, 14]],
1653 [[20, 30], [22, 24], [25, 27], []],
1654 ]
1655 "#;
1656
1657 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1658 tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
1659
1660 let t0 = &tests.testsrust-analyzer cargo regex-test 0.1.1 RegexTests#tests.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().;
1661 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(t0.regexesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]regexes().(), &[".*.rs"]);
1662 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(t0.is_matchrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]is_match().(), true);
1663 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(t0.which_matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]which_matches().(), &[0]);
1664 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1665 t0.matchesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]matches().(),
1666 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
1667 Matchrust-analyzer cargo regex-test 0.1.1 Match# { idrust-analyzer cargo regex-test 0.1.1 Match#id.: 0, spanrust-analyzer cargo regex-test 0.1.1 Match#span.: Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 0, endrust-analyzer cargo regex-test 0.1.1 Span#end.: 15 } },
1668 Matchrust-analyzer cargo regex-test 0.1.1 Match# { idrust-analyzer cargo regex-test 0.1.1 Match#id.: 0, spanrust-analyzer cargo regex-test 0.1.1 Match#span.: Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 20, endrust-analyzer cargo regex-test 0.1.1 Span#end.: 30 } },
1669 ]
1670 );
1671 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
1672 t0.capturesrust-analyzer cargo regex-test 0.1.1 impl#[RegexTest]captures().(),
1673 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
1674 Capturesrust-analyzer cargo regex-test 0.1.1 Captures#::newrust-analyzer cargo regex-test 0.1.1 impl#[Captures]new().(
1675 0,
1676 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
1677 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 0, endrust-analyzer cargo regex-test 0.1.1 Span#end.: 15 }),
1678 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 5, endrust-analyzer cargo regex-test 0.1.1 Span#end.: 10 }),
1679 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
1680 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 13, endrust-analyzer cargo regex-test 0.1.1 Span#end.: 14 }),
1681 ]
1682 )
1683 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
1684 Capturesrust-analyzer cargo regex-test 0.1.1 Captures#::newrust-analyzer cargo regex-test 0.1.1 impl#[Captures]new().(
1685 0,
1686 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
1687 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 20, endrust-analyzer cargo regex-test 0.1.1 Span#end.: 30 }),
1688 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 22, endrust-analyzer cargo regex-test 0.1.1 Span#end.: 24 }),
1689 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Spanrust-analyzer cargo regex-test 0.1.1 Span# { startrust-analyzer cargo regex-test 0.1.1 Span#start.: 25, endrust-analyzer cargo regex-test 0.1.1 Span#end.: 27 }),
1690 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
1691 ]
1692 )
1693 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
1694 ]
1695 );
1696 }
1697
1698 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1699 fn fail_spans_empty1rust-analyzer cargo regex-test 0.1.1 tests/fail_spans_empty1().() {
1700 let data = r#"
1701 [[test]]
1702 name = "foo"
1703 regex = ".*.rs"
1704 haystack = "lib.rs"
1705 matches = [
1706 [],
1707 ]
1708 "#;
1709
1710 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1711 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
1712 }
1713
1714 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1715 fn fail_spans_empty2rust-analyzer cargo regex-test 0.1.1 tests/fail_spans_empty2().() {
1716 let data = r#"
1717 [[test]]
1718 name = "foo"
1719 regex = ".*.rs"
1720 haystack = "lib.rs"
1721 matches = [
1722 [[]],
1723 ]
1724 "#;
1725
1726 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1727 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
1728 }
1729
1730 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1731 fn fail_spans_empty3rust-analyzer cargo regex-test 0.1.1 tests/fail_spans_empty3().() {
1732 let data = r#"
1733 [[test]]
1734 name = "foo"
1735 regex = ".*.rs"
1736 haystack = "lib.rs"
1737 matches = [
1738 [[], [0, 2]],
1739 ]
1740 "#;
1741
1742 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1743 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
1744 }
1745
1746 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1747 fn fail_captures_empty1rust-analyzer cargo regex-test 0.1.1 tests/fail_captures_empty1().() {
1748 let data = r#"
1749 [[test]]
1750 name = "foo"
1751 regex = ".*.rs"
1752 haystack = "lib.rs"
1753 matches = [
1754 { id = 0, spans = [] },
1755 ]
1756 "#;
1757
1758 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1759 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
1760 }
1761
1762 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1763 fn fail_captures_empty2rust-analyzer cargo regex-test 0.1.1 tests/fail_captures_empty2().() {
1764 let data = r#"
1765 [[test]]
1766 name = "foo"
1767 regex = ".*.rs"
1768 haystack = "lib.rs"
1769 matches = [
1770 { id = 0, spans = [[]] },
1771 ]
1772 "#;
1773
1774 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1775 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
1776 }
1777
1778 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
1779 fn fail_captures_empty3rust-analyzer cargo regex-test 0.1.1 tests/fail_captures_empty3().() {
1780 let data = r#"
1781 [[test]]
1782 name = "foo"
1783 regex = ".*.rs"
1784 haystack = "lib.rs"
1785 matches = [
1786 { id = 0, spans = [[], [0, 2]] },
1787 ]
1788 "#;
1789
1790 let mut tests = RegexTestsrust-analyzer cargo regex-test 0.1.1 RegexTests#::newrust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]new().();
1791 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(tests.load_slicerust-analyzer cargo regex-test 0.1.1 impl#[RegexTests]load_slice().("test", data.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
1792 }
1793 }