Skip to content

Commit

Permalink
fix: make SnapTestRunner::with_fn more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
nfejzic committed Oct 12, 2024
1 parent 38b7519 commit c262f6c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
19 changes: 1 addition & 18 deletions commons/src/test_runner/snap_test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct SnapTestRunner<'a, I = ()> {
}

impl<'a> SnapTestRunner<'a> {
pub fn with_fn_any<I, F>(name: &str, input: &'a I, mut func: F) -> SnapTestRunner<'a, ()>
pub fn with_fn<I, F>(name: &str, input: &'a I, mut func: F) -> SnapTestRunner<'a, ()>
where
I: AsRef<str>,
F: FnMut(&I) -> String,
Expand All @@ -30,23 +30,6 @@ impl<'a> SnapTestRunner<'a> {
snapshot,
}
}

pub fn with_fn<S, PF>(name: &str, input: &'a S, mut parser: PF) -> SnapTestRunner<'a, ()>
where
S: AsRef<[Token<'a>]>,
PF: for<'s, 'i> FnMut(&'s [Token<'i>]) -> String,
{
let snapshot = parser(input.as_ref());

SnapTestRunner {
info: None,
desc: None,
input: Token::flatten(input.as_ref()),
name: name.into(),
sub_path: None,
snapshot,
}
}
}

impl<'a, I> SnapTestRunner<'a, I>
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub(crate) fn collect_snapshot_tests() -> Vec<Trial> {
}

fn run_snap_test(case: test_runner::test_file::TestCase) {
let runner = SnapTestRunner::with_fn_any(&case.test.name, &case.test.input, |input_str| {
let runner = SnapTestRunner::with_fn(&case.test.name, &case.test.input, |input_str| {
let token_stream = unimarkup_frontend::lexer::TokenStream::tokenize(input_str);

let token_snaps = token_stream
Expand Down

0 comments on commit c262f6c

Please sign in to comment.