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

AbstractPathAssert.hasContent ignores a single trailing newline #62

Closed
rupert-madden-abbott opened this issue Mar 21, 2023 · 1 comment

Comments

@rupert-madden-abbott
Copy link

rupert-madden-abbott commented Mar 21, 2023

Given a file named foo.txt with the following contents:

Hello, world!

The following assertions pass:

assertThat(Path.of("foo.txt"))
    .hasContent("Hello, world!")
    .hasContent("Hello, world!\r")
    .hasContent("Hello, world!\n")
    .hasContent("Hello, world!\r\n");

However, newlines elsewhere in the expected value are not ignored. For example, this assertion fails: assertThat(Path.of("foo.txt")).hasContent("\nHello, world"); with the following error:

java.lang.AssertionError: 
Path:
  foo.txt
read with charset UTF-8 does not have the expected content:

Missing content at line 1:
  [""]

Equally, multiple newlines are not ignored. For example, this assertion fails: assertThat(Path.of("foo.txt")).hasContent("Hello, world\n\n"); with the following error:

java.lang.AssertionError: 
Path:
  foo.txt
read with charset UTF-8 does not have the expected content:

Missing content at line 2:
  [""]

Finally, a trailing newline is also ignored in the actual value. For example, given a file named foo.txt with the following contents:

Hello, world!

The following assertions pass:

assertThat(Path.of("foo.txt"))
    .hasContent("Hello, world!")
    .hasContent("Hello, world!\r")
    .hasContent("Hello, world!\n")
    .hasContent("Hello, world!\r\n");
@rupert-madden-abbott rupert-madden-abbott changed the title AbstractPathAssert.hasContent ignores trailing newlines AbstractPathAssert.hasContent ignores a single trailing newline Mar 21, 2023
@rupert-madden-abbott
Copy link
Author

Sorry this is the wrong repo. Reopened here: assertj/assertj#2993

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

No branches or pull requests

1 participant