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

Tests getting weird characters in the output #982

Closed
lahodaj opened this issue May 15, 2024 · 2 comments
Closed

Tests getting weird characters in the output #982

lahodaj opened this issue May 15, 2024 · 2 comments
Milestone

Comments

@lahodaj
Copy link
Contributor

lahodaj commented May 15, 2024

I think this is happens typically in tests, not so important in real uses. Caused by:
#975

When the Display is set to size 0x0, it used to have Integer.MAX_VALUE-1 columns, and 1 row. #975 changed that to 1 column, 1 row, which, by itself seems to make sense. But, there's some special handling when writing at the very right edge of the terminal:

terminal.writer().write(" \b");

So, some tests, which effectively run with Display size 0x0 get the internal size of 1x1, and write odd number of character then get \b in the output, which they didn't before. And it is hard to defend adding these characters to the expected test output. Not sure at this time what is the more appropriate way out of this, but though I would report it.

To see the problem, try to add this test into reader/src/test/java/org/jline/reader/impl/LineReaderTest.java:

    @Test
    public void x() throws IOException {
        ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {'\n'});
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (Terminal terminal = new DumbTerminal(in, out)) {
            LineReader r = new LineReaderImpl(terminal);
            r.readLine("123");
            String written = new String(out.toByteArray());

            assertEquals("123", written);
        }
    }
lahodaj referenced this issue May 15, 2024
Co-authored-by: Kay Werndli <kay@spinque.com>
@gnodet
Copy link
Member

gnodet commented May 15, 2024

I think this is happens typically in tests, not so important in real uses. Caused by: #975

When the Display is set to size 0x0, it used to have Integer.MAX_VALUE-1 columns, and 1 row. #975 changed that to 1 column, 1 row, which, by itself seems to make sense. But, there's some special handling when writing at the very right edge of the terminal:

To see the problem, try to add this test into reader/src/test/java/org/jline/reader/impl/LineReaderTest.java:

    @Test
    public void x() throws IOException {
        ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {'\n'});
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (Terminal terminal = new DumbTerminal(in, out)) {
            LineReader r = new LineReaderImpl(terminal);
            r.readLine("1234");
            String written = new String(out.toByteArray());

            assertEquals("1234", written);
        }
    }

The test succeeds for me on master on MacOS...

@lahodaj
Copy link
Contributor Author

lahodaj commented May 16, 2024

Uh, sorry. Just before submitting I was double-checking the behavior for various lengths of the prompt, an accidentally copied the version which prints 1234. The prompt length must be odd to see the problem, i.e. either 123 or 12345 (or similar). I've fixed the test in the original comment, removing the 4 from the prompt.

Sorry for the trouble.

@gnodet gnodet added this to the 3.26.2 milestone Jun 7, 2024
gnodet added a commit to gnodet/jline3 that referenced this issue Jun 7, 2024
@gnodet gnodet closed this as completed in f712b51 Jun 13, 2024
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

2 participants