Skip to content

Commit

Permalink
Construct Paths and CandidatePaths in harness parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
olson-sean-k committed Feb 25, 2024
1 parent 470169f commit 1031220
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
21 changes: 12 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,12 +1116,15 @@ pub mod harness {
)
}

pub fn assert_match_program_with<'t, T, U, F>(program: T, path: &'t str, f: F) -> U
pub fn assert_match_program_with<'t, T, F>(
program: impl Program<'t>,
candidate: impl Into<CandidatePath<'t>>,
f: F,
) -> T
where
T: Program<'t>,
F: FnOnce(Option<MatchedText<'static>>) -> U,
F: FnOnce(Option<MatchedText<'static>>) -> T,
{
let candidate = CandidatePath::from(path);
let candidate = candidate.into();
f(program.matched(&candidate).map(MatchedText::into_owned))
}

Expand Down Expand Up @@ -1198,11 +1201,11 @@ pub mod harness {
}
}

pub fn assert_partitioned_has_prefix_and_is_match(
pub fn assert_partitioned_has_prefix_and_is_match<'p>(
partitioned: (PathBuf, Glob<'_>),
expected: (&str, &str),
expected: (impl AsRef<Path>, impl Into<CandidatePath<'p>>),
) -> MatchedText<'static> {
let expected = (Path::new(expected.0), expected.1);
let expected = (expected.0.as_ref(), expected.1.into());
let (prefix, glob) = partitioned;
assert!(
prefix == expected.0,
Expand All @@ -1216,10 +1219,10 @@ pub mod harness {

pub fn assert_partitioned_has_prefix_and_expression<'t>(
partitioned: (PathBuf, Glob<'t>),
expected: (&str, &str),
expected: (impl AsRef<Path>, &str),
) -> (PathBuf, Glob<'t>) {
let (prefix, glob) = partitioned;
let expected = (Path::new(expected.0), expected.1);
let expected = (expected.0.as_ref(), expected.1);
assert!(
prefix == expected.0,
"partitioned prefix is `{}`, but expected `{}`",
Expand Down
12 changes: 8 additions & 4 deletions src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1641,11 +1641,11 @@ pub mod harness {

pub fn assert_tokenized_invariant_path_prefix_eq<'t, A>(

Check failure on line 1642 in src/token/mod.rs

View workflow job for this annotation

GitHub Actions / Lint

the following explicit lifetimes could be elided: 't
tokenized: Tokenized<'t, A>,
expected: &str,
expected: impl AsRef<Path>,
) -> Tokenized<'t, A> {
let (_, text) = tokenized.as_token().invariant_text_prefix();
let text = Path::new(&text);
let expected = Path::new(expected);
let expected = expected.as_ref();
assert!(
text == expected,
"`Token::invariant_text_prefix` as path is `{}`, but expected `{}`: in `Tokenized`: `{}`",
Expand All @@ -1662,6 +1662,7 @@ pub mod harness {
mod tests {
use expect_macro::expect;
use rstest::{fixture, rstest};
use std::path::Path;

use crate::token::{harness, parse, ExpressionMetadata, Token, TokenTree, Tokenized};

Expand Down Expand Up @@ -1727,10 +1728,13 @@ mod tests {
#[case("a?/b", "")]
#[cfg_attr(unix, case("../foo/(?i)bar/(?-i)baz", "../foo/"))]
#[cfg_attr(windows, case("../foo/(?i)bar/(?-i)baz", "../foo/bar/"))]
fn parse_expression_invariant_path_prefix_eq(#[case] expression: &str, #[case] text: &str) {
fn parse_expression_invariant_path_prefix_eq(
#[case] expression: &str,
#[case] expected: impl AsRef<Path>,
) {
harness::assert_tokenized_invariant_path_prefix_eq(
parse::harness::assert_parse_expression_is_ok(expression),
text,
expected,
);
}
}
4 changes: 2 additions & 2 deletions src/token/variance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,11 @@ mod tests {
#[case("<foo*/:1,>*", harness::range(4, None))]
fn parse_expression_size_variance_eq(
#[case] expression: &str,
#[case] size: GlobVariance<Size>,
#[case] expected: GlobVariance<Size>,
) {
harness::assert_tokenized_variance_eq(
parse::harness::assert_parse_expression_is_ok(expression),
size,
expected,
);
}

Expand Down

0 comments on commit 1031220

Please sign in to comment.