Skip to content

Commit

Permalink
Add check.
Browse files Browse the repository at this point in the history
  • Loading branch information
ltratt committed Jul 23, 2024
1 parent 9ed39c9 commit 4b8ad4f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ impl<'a> FMBuilder<'a> {
/// ```
///
/// As this shows, once `$1` has matched "a", all further instances of `$1` must also match
/// "a", but `_` can match different values at different points. This is true even if distinct
/// name matching (see [Self::distinct_name_matching] is enabled.
/// "a", but `_` can match different values at different points.
pub fn name_matcher_ignore(mut self, ptn_re: Regex, text_re: Regex) -> Self {
self.options.name_matchers.push((ptn_re, text_re, true));
self
Expand Down Expand Up @@ -256,6 +255,11 @@ impl<'a> FMBuilder<'a> {

/// Turn this `FMBuilder` into a `FMatcher`.
pub fn build(self) -> Result<FMatcher<'a>, Box<dyn Error>> {
if !self.options.name_matching_processors.is_empty()
&& self.options.name_matchers.is_empty()
{
return Err("If a name matching processor(s) is/are specified, one or more name matchers must also be specified".into());
}
self.validate()?;
let (ptn_lines, ptn_lines_off) = line_trimmer(self.options.trim_whitespace, self.ptn);
Ok(FMatcher {
Expand Down Expand Up @@ -1101,6 +1105,18 @@ mod tests {
.unwrap();
}

#[test]
#[should_panic(
expected = "If a name matching processor(s) is/are specified, one or more name matchers must also be specified"
)]
fn name_matching_processor_requires_name_matcher() {
FMBuilder::new("$1")
.unwrap()
.name_matching_processor(|_| true)
.build()
.unwrap();
}

#[test]
fn consecutive_wildcards_disallowed() {
match FMatcher::new("...\n...") {
Expand Down

0 comments on commit 4b8ad4f

Please sign in to comment.