Skip to content
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

Unify handling of file & inline snapshots #468

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

max-sixty
Copy link
Sponsor Contributor

This is the code for #456 (comment), as mentioned in #466.

There's a very small breaking change in YAML inline snapshots — shown here in the tests. In return, it cuts some complicated code from macros.rs, making them more maintainable and less likely to hit some of our recent issues, such as inconsistent support for trailing commas etc

This is the code for mitsuhiko#456 (comment), as mentioned in mitsuhiko#466.

There's a very small change in yaml inline snapshots — shown here in the tests. In return, it makes the macros simpler & more maintainable.
@mitsuhiko
Copy link
Owner

I'm not a huge fan of this. The current logic means that leading whitespace is handled better for yaml snapshots. What's the benefit of changing this?

@max-sixty
Copy link
Sponsor Contributor Author

The current logic means that leading whitespace is handled better for yaml snapshots. What's the benefit of changing this?

Couple of reasons:

  • Currently snapshots are the same for file & inline everywhere except yaml snapshots
  • I agree better handling of leading & trailing whitespace would be nice — but these are yaml snapshots — they can't have leading whitespace! (or am I wrong?). And why handle it differently between file & inline?
  • Because we're handling file & inline differently in this one place, we need to thread that arg all the way through the code, which makes the code more complicated

(not my most important contribution, won't be offended if you close! Though I also don't quite see the reason to have the existing code...)

@mitsuhiko
Copy link
Owner

Yeah this might be right. I'm generally quite hesitant to changing formatting the format. Today this choice means that every line starts with --- which means even that when you assert_yaml_snapshot!(true, ...); you end up in multi-line mode. So it's not as much that the leading whitespace is relevant as that you end up with stuff in the next line. Maybe that's not ideal but I also did not think that much to begin with.

@max-sixty
Copy link
Sponsor Contributor Author

OK! I don't think there are any cases that would be worse like this, but if you have any lingering doubts then happy to test them...

@mitsuhiko
Copy link
Owner

I think I would be okay making this change with insta 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants