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

Use inline block format also for strings of form "foo\n" #225

Merged
merged 1 commit into from Apr 27, 2022

Conversation

martinvonz
Copy link
Contributor

The generated inline strings for snapshots with a single trailing
newline currently look something like this:

    insta::assert_snapshot!(stdout, @"foo
");

The unindented line there is distracting. I think it looks neater with
the block-style strings, like this:

    insta::assert_snapshot!(stdout, @###"
    foo
    "###);

I suspect the reason it isn't currently generated like that is just an
oversight caused by the fact that Rust's str::lines() returns a
single line for that kind of strings. This patch fixes it by looking
for \n characters instead.

The generated inline strings for snapshots with a single trailing
newline currently look something like this:

```
    insta::assert_snapshot!(stdout, @"foo
");
```

The unindented line there is distracting. I think it looks neater with
the block-style strings, like this:

```
    insta::assert_snapshot!(stdout, @###"
    foo
    "###);
```

I suspect the reason it isn't currently generated like that is just an
oversight caused by the fact that Rust's `str::lines()` returns a
single line for that kind of strings. This patch fixes it by looking
for `\n` characters instead.
@mitsuhiko mitsuhiko merged commit 56504f1 into mitsuhiko:master Apr 27, 2022
mitsuhiko added a commit that referenced this pull request Apr 27, 2022
@martinvonz martinvonz deleted the single_trailing_newline branch April 28, 2022 23:43
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