Skip to content

Commit

Permalink
Add a hacky mechanism for allowing string adjustments in tests (#9)
Browse files Browse the repository at this point in the history
It's nice to be able to track tests that are "almost" passing, modulo string normalization, so this PR adds a dedicated section for snippets that fit that description.
  • Loading branch information
charliermarsh committed Feb 15, 2023
1 parent 8081cf5 commit 20d7c95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion crates/ruff_fmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ edition = "2021"
[dependencies]
anyhow = "1.0.68"
clap = { version = "4.0.1", features = ["derive"] }
insta = { version = "1.19.1", features = ["yaml"] }
once_cell = "1.17.0"
rome_formatter = { path = "../../../tools/crates/rome_formatter" }
rome_text_size = { path = "../../../tools/crates/rome_text_size" }
rustc-hash = "1.1.0"
rustpython-common = { workspace = true }
rustpython-parser = { workspace = true }

[dev-dependencies]
insta = { version = "1.19.0", features = [] }
test-case = { version = "2.2.2" }
18 changes: 16 additions & 2 deletions crates/ruff_fmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,22 @@ mod tests {
Ok(())
}

// Passing modulo string normalization.
// #[test_case(Path::new("simple_cases/collections.py"); "collections")]
#[test_case(Path::new("simple_cases/collections.py"); "collections")]
fn passing_modulo_string_normalization(path: &Path) -> Result<()> {
fn adjust_quotes(contents: &str) -> String {
// Replace all single quotes with double quotes.
contents.replace("'", "\"")
}

let snapshot = format!("{}", path.display());
let content = std::fs::read_to_string(test_resource_path(
Path::new("fixtures/black").join(path).as_path(),
))?;
let formatted = fmt(&content)?;
insta::assert_display_snapshot!(snapshot, adjust_quotes(formatted.print()?.as_code()));
Ok(())
}

// Passing apart from one deviation in RHS tuple assignment.
// #[test_case(Path::new("simple_cases/tupleassign.py"); "tupleassign")]
// Lots of deviations, _mostly_ related to string normalization and wrapping.
Expand Down

0 comments on commit 20d7c95

Please sign in to comment.