[
https://issues.apache.org/jira/browse/TEXT-231?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17763460#comment-17763460
]
Michael Karnerfors edited comment on TEXT-231 at 9/10/23 10:47 PM:
-------------------------------------------------------------------
[~ggregory]
The PR is created: [https://github.com/apache/commons-text/pull/458]
The reason for reorganising the test cases in this particular instance was that
I literally had a hard time understanding the test cases, the test method names
for the wrap method meant little and in my IDE it was hard to find which test
case had actually failed.
What I have done is use JUnit 5's ability to give test methods and test cases
human-readable names.
This — I believe — will better the developer experience by increasing the
legibility and the maintainability of the code. And since JUnit integrates with
commonly used IDEs and Continuous Development tools, I believe the change will
give better reporting on testing, especially letting developers pinpoint failed
test cases faster and more accurately.
was (Author: michaelkarnerfors):
[~ggregory]
The PR is created: [https://github.com/apache/commons-text/pull/458]
The reason for reorganising the test cases in this particular instance was that
I literally had a hard time understanding the test cases, the test method names
for the wrap method meant little and in my IDEA it was hard to find which test
case had actually failed.
What I have done is use JUnit 5's ability to give test methods and test cases
human-readable names.
This — I believe — will better the developer experience by increasing the
legibility and the maintainability of the code. And since JUnit integrates with
commonly used IDEAs and Continuous Development tools, I believe the change will
give better reporting on testing, especially letting developers pinpoint failed
test cases faster and more accurately.
> WordUtils.wrap should react to prexisting "new line string" as a wrap
> ---------------------------------------------------------------------
>
> Key: TEXT-231
> URL: https://issues.apache.org/jira/browse/TEXT-231
> Project: Commons Text
> Issue Type: Improvement
> Affects Versions: 1.10.0
> Reporter: Michael Karnerfors
> Priority: Minor
>
> WordUtils.wrap ignores pre-existing occurrences of the "new line string" and
> counts them as part of a line, instead of as a wrap.
> Example:
> {code:java}
> public static final String LINE_SEPARATOR = "\n";
> void wrap() {
> String line = "Alpha"+ LINE_SEPARATOR + "Bravo Charlie Delta Echo
> Foxtrot";
> System.out.println(WordUtils.wrap(line, 13));
> } {code}
> The default new line string is just newline ("\n"). So in this case I would
> expect this to output...
> {noformat}
> Alpha
> Bravo Charlie
> Delta Echo
> Foxtrot
> {noformat}
> However, since WordUtils.wrap does not consider the pre-existing newline
> after "Alpha" as one of its own wraps, I instead get...
> {noformat}
> Alpha
> Bravo
> Charlie Delta
> Echo Foxtrot
> {noformat}
> There is a work-around, but it is not as elegant...
> {code:java}
> String wrappedLine =
> Arrays
> .stream(
> line.split(LINE_SEPARATOR)
> )
> .map(
> subLine -> WordUtils.wrap(subLine, 13)
> )
> .collect(
> Collectors.joining(LINE_SEPARATOR)
> );
> System.out.println(wrappedLine);
> {code}
> Hence, I suggest that WordUtils.wrap should consider matches of "newLineStr"
> as a wrap, and any directly following text as the beginning of the next line.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)