Skip to content

Commit

Permalink
refactor: add strip_suffix_with_value helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Jul 24, 2024
1 parent 05b3d51 commit e70fd6b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions moz-webgpu-cts/src/wpt/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ impl SpecType {

pub fn from_base_name(base_name: &str) -> Option<(Self, &str)> {
Self::iter().find_map(|variant| {
base_name
.strip_suffix(variant.file_extension())
.map(|some| (variant, some))
strip_suffix_with_value(base_name, variant.file_extension(), variant)
})
}

Expand Down Expand Up @@ -432,6 +430,10 @@ impl From<ServoRootDir> for RootDir {
}
}

fn strip_suffix_with_value<'a, T>(s: &'a str, suffix: &str, t: T) -> Option<(T, &'a str)> {
s.strip_suffix(suffix).map(|some| (t, some))
}

#[test]
fn parse_test_entry_path() {
assert_eq!(
Expand Down

0 comments on commit e70fd6b

Please sign in to comment.