-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Whitespace issues with inline snapshots #117
Comments
This is a somewhat known limitation. Leading whitespace with inline snapshots will cause this. I'm not sure if there is a good solution for this with the current model for whitespace trimming we have. |
I'm running into what I think is a related issue. The following use insta::assert_display_snapshot;
#[test]
fn test_foo() {
let body_txt = r#"
# title
### subtitle
"#.trim_matches('\n');
println!("{:#?}", body_txt);
assert_display_snapshot!(body_txt, @r###"
# title
### subtitle
"###);
} prompts a snapshot update and Instead what seems to work is removing the indent for the generated inline snapshot. diff --git a/src/main.rs b/src/main.rs
index afdacba..1fce772 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,8 +14,8 @@ fn test_foo() {
"#.trim_matches('\n');
println!("{:#?}", body_txt);
assert_display_snapshot!(body_txt, @r###"
- # title
+# title
- ### subtitle
+### subtitle
"###);
} So when updating the snapshot I |
My recommendation would be to prefix the string with a non whitespace character. |
Does anyone have an example of an inline display snapshot that spans multiple lines working? I can't seem to get any combination of trimming or indenting to make things consistent. Would there be a difference between I see whitespace errors when I #[test]
fn test_completions_when_algo() {
insta::assert_display_snapshot!(completions_for("when algo|"),
@r###"
# "Services"
<"Algolia">
[Algolia]
# "Services"
<"Magic">
[Magic]
<"Maps">
[Maps]
<"Salesforce">
[Salesforce]
<"PagerDuty">
[PagerDuty]
<"Twilio">
[Twilio]
<"Slack">
[Slack]
"###);
} Currently using |
@colelawrence that's a bug that #166 will solve. |
To what extent could we solve this by removing leading whitespace from both the result and the snapshot? The downside of that is the test will still pass even if they have different leading whitespace — inline snapshots would quietly allow for some false passes, rather than the current situation of loudly always raising a false fail. An alternative advanced approach would be to try and calculate the exact leading whitespace from the location of the result, rather than the current approach of removing all leading whitespace. But that would make results indentation sensitive, and possibly have a tail of complication. |
I feel like touching this is tricky and will trade one issue for another. A pretty crappy but trivial solution would be to provide a helper to add markers before and after. |
I would vote to close this:
|
I'm just starting to use insta and it's really cool. But I've run into some problems with whitespace and inline snapshots.
Let's start with:
This obviously fails. Running
cargo insta review
and accepting the new output gives:But the test still fails with:
Am I doing something wrong here?
The text was updated successfully, but these errors were encountered: