Repository navigation
Preserve leading whitespace in YAML literal blocks - #958
Open
NgoQuocViet2001 wants to merge 1 commit into
Open
NgoQuocViet2001 wants to merge 1 commit into
NgoQuocViet2001 wants to merge 1 commit into
Conversation
With INSTA_YAML_BLOCK_STYLE=1, a multiline string whose first line starts with a space or tab was written as a literal block without an indentation indicator. The parser then takes the indentation from that first line, so the leading whitespace was dropped on read, or the snapshot failed to parse when a later line was less indented. Write the indentation indicator (e.g. `|2-`) in that case. Output for other strings is unchanged. With the variable set, assert_yaml_snapshot! uses the same emitter, so its output for such strings changes from `|-` to `|2-` and those snapshots need to be accepted once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
INSTA_YAML_BLOCK_STYLE=1, a multiline string whose first line starts with whitespace is written as a literal block without an indentation indicator. YAML takes the indentation from that first line, so the leading whitespace is lost on read. If a later line is less indented, the file no longer parses: withdescription => " return x;\n }", the next run prints "Failed to parse snapshot file; a new snapshot will be generated" and the assertion fails even though the contents match.This writes the indentation indicator when the first non-empty line starts with a space or tab, so
description: |-becomesdescription: |2-. The vendored parser already reads the indicator, and output for all other strings is unchanged. With the variable set,assert_yaml_snapshot!uses the same emitter, so its output for such strings changes from|-to|2-and those snapshots need to be accepted once. Falling back to the quoted style for these strings would also work if you prefer that.Ran:
cargo test -p insta --lib --locked: 80 passed. Both new emitter tests fail on master.cargo test -p insta --all-features --locked: passes except the threetest_globs_follow_links*tests, which fail the same way on master in this checkout.cargo clippy -p insta --all-targets --all-features -- --deny warningsandcargo fmt --all -- --check: clean.Checked: a crate using
with_settings!({description => ...})withINSTA_YAML_BLOCK_STYLE=1fails on master (the parse warning above, and anINSTA_REQUIRE_FULL_MATCH=1mismatch for a uniformly indented description) and passes with this change.