Skip to content

Commit

Permalink
test(pattern): Assert all patterns when compiling in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Oct 9, 2024
1 parent 8c53a8a commit 6595a85
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions relay-pattern/src/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ impl<C: PatternConfig> FromIterator<String> for TypedPatterns<C> {
fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self {
let mut builder = Self::builder();
for pattern in iter.into_iter() {
let _ = builder.add(pattern);
let _err = builder.add(pattern);
#[cfg(debug_assertions)]
_err.expect("all patterns should be valid patterns");
}
builder.build()
}
Expand Down Expand Up @@ -248,7 +250,9 @@ impl<'de, C: PatternConfig> serde::Deserialize<'de> for TypedPatterns<C> {

while let Some(item) = seq.next_element()? {
// Ignore invalid patterns as documented.
let _ = builder.add(item);
let _err = builder.add(item);
#[cfg(debug_assertions)]
_err.expect("all patterns should be valid patterns");
}

Ok(builder.build())
Expand Down Expand Up @@ -398,7 +402,7 @@ mod tests {
}

#[test]
#[cfg(feature = "serde")]
#[cfg(all(feature = "serde", not(debug_assertions)))]
fn test_patterns_deserialize_err() {
let r: TypedPatterns<CaseInsensitive> =
serde_json::from_str(r#"["[invalid","foobar"]"#).unwrap();
Expand Down

0 comments on commit 6595a85

Please sign in to comment.