From 6013e86d654003bce55ad47870c9d62c3bbb04e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabr=C3=ADcio=20Barros=20Cabral?= Date: Thu, 18 Jan 2024 13:29:45 -0300 Subject: [PATCH] (#1704) Fix bug related to 80-character limit --- src/main/java/org/cactoos/text/Multiline.java | 16 ++++++++-------- .../java/org/cactoos/text/MultilineTest.java | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/cactoos/text/Multiline.java b/src/main/java/org/cactoos/text/Multiline.java index 71adf3c84..ccaef6bfc 100644 --- a/src/main/java/org/cactoos/text/Multiline.java +++ b/src/main/java/org/cactoos/text/Multiline.java @@ -105,14 +105,14 @@ public Multiline(final Text text, final int limit) { Multiline.SPLIT_REGEX ); final StringBuilder lines = new StringBuilder(); - final StringBuilder word = new StringBuilder(0); + final StringBuilder line = new StringBuilder(0); int length = 0; for (int idx = 0; idx < words.length; ++idx) { - word.setLength(0); - word.append(words[idx]); + line.setLength(0); + line.append(words[idx]); final int size = Multiline.SPACE.length() - + word.length(); - if (length + size > limit) { + + line.length(); + if (length + size > limit + 1) { if (idx > 0) { lines.append(Multiline.NEW_LINE); } @@ -123,10 +123,10 @@ public Multiline(final Text text, final int limit) { && length + size + words[idx + 1].length() <= limit ) { - word.append(Multiline.SPACE); + line.append(Multiline.SPACE); } - lines.append(word); - length = length + word.length(); + lines.append(line); + length = length + line.length(); } return new IteratorOf<>( lines.toString().split(Multiline.NEW_LINE) diff --git a/src/test/java/org/cactoos/text/MultilineTest.java b/src/test/java/org/cactoos/text/MultilineTest.java index d2d55228a..b56a477e0 100644 --- a/src/test/java/org/cactoos/text/MultilineTest.java +++ b/src/test/java/org/cactoos/text/MultilineTest.java @@ -103,9 +103,9 @@ void multilineTextBiggerThanDefaultLimit() { new Joined( " ", "The quick brown fox jumps over the lazy", - "black dog and after that returned to " + "black dog and after that returned to the" ), - new TextOf("the cave") + new TextOf("cave") ) ) ).affirm();