Skip to content

Commit c18143e

Browse files
authored
Merge pull request #15 from cowwoc/v10.2
Version 10.2
2 parents 504babf + af68ea0 commit c18143e

File tree

10 files changed

+56
-17
lines changed

10 files changed

+56
-17
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# <img src="docs/checklist.svg" width=64 height=64 alt="checklist"> Requirements API
55

6-
[![API](https://img.shields.io/badge/api_docs-5B45D5.svg)](https://cowwoc.github.io/requirements.java/10.1/docs/api/)
6+
[![API](https://img.shields.io/badge/api_docs-5B45D5.svg)](https://cowwoc.github.io/requirements.java/10.2/docs/api/)
77
[![Changelog](https://img.shields.io/badge/changelog-A345D5.svg)](docs/Changelog.md)
88
[![javascript, typescript](https://img.shields.io/badge/other%20languages-javascript,%20typescript-457FD5.svg)](../../../requirements.js)
99

@@ -22,7 +22,7 @@ To get started, add this Maven dependency:
2222
<dependency>
2323
<groupId>com.github.cowwoc.requirements</groupId>
2424
<artifactId>java</artifactId>
25-
<version>10.1</version>
25+
<version>10.2</version>
2626
</dependency>
2727
```
2828

@@ -152,14 +152,14 @@ This library offers the following features:
152152
Designed for discovery using your favorite IDE's auto-complete feature.
153153
The main entry points are:
154154

155-
* [requireThat(value, name)](https://cowwoc.github.io/requirements.java/10.1/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html#requireThat(T,java.lang.String))
155+
* [requireThat(value, name)](https://cowwoc.github.io/requirements.java/10.2/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html#requireThat(T,java.lang.String))
156156
for method preconditions.
157-
* [that(value, name)](https://cowwoc.github.io/requirements.java/10.1/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html#that(T,java.lang.String))
157+
* [that(value, name)](https://cowwoc.github.io/requirements.java/10.2/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html#that(T,java.lang.String))
158158
for [class invariants, method postconditions and private methods](docs/Features.md#assertion-support).
159-
* [checkIf(value, name)](https://cowwoc.github.io/requirements.java/10.1/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html#checkIf(T,java.lang.String))
159+
* [checkIf(value, name)](https://cowwoc.github.io/requirements.java/10.2/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html#checkIf(T,java.lang.String))
160160
for multiple failures and customized error handling.
161161

162-
See the [API documentation](https://cowwoc.github.io/requirements.java/10.1/docs/api/) for more details.
162+
See the [API documentation](https://cowwoc.github.io/requirements.java/10.2/docs/api/) for more details.
163163

164164
## Best practices
165165

docs/Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
See https://github.com/cowwoc/requirements.java/commits/master for a full list.
44

5+
## Version 10.2 - 2024/12/07
6+
7+
* Improvement: Escape linefeed characters in diffs.
8+
59
## Version 10.1 - 2024/12/06
610

711
* Improvements

docs/Supported_Libraries.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Each module uses a separate class pair for validation. For example,
2-
[DefaultJavaValidators](https://cowwoc.github.io/requirements.java/10.1/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html)
2+
[DefaultJavaValidators](https://cowwoc.github.io/requirements.java/10.2/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/DefaultJavaValidators.html)
33
and
4-
[JavaValidators](https://cowwoc.github.io/requirements.java/10.1/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/JavaValidators.html)
4+
[JavaValidators](https://cowwoc.github.io/requirements.java/10.2/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/java/JavaValidators.html)
55
validate the core Java API. Similarly,
6-
[DefaultGuavaValidators](https://cowwoc.github.io/requirements.java/10.1/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/guava/DefaultGuavaValidators.html)
6+
[DefaultGuavaValidators](https://cowwoc.github.io/requirements.java/10.2/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/guava/DefaultGuavaValidators.html)
77
and
8-
[GuavaValidators](https://cowwoc.github.io/requirements.java/10.1/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/guava/GuavaValidators.html)
8+
[GuavaValidators](https://cowwoc.github.io/requirements.java/10.2/docs/api/com.github.cowwoc.requirements.java/com/github/cowwoc/requirements10/guava/GuavaValidators.html)
99
validate the Guava API.
1010

1111
The following table lists validators for third-party libraries:

java/src/main/java/com/github/cowwoc/requirements10/java/internal/message/diff/AbstractDiffWriter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.util.Map.Entry;
1212
import java.util.function.Consumer;
1313

14+
import static com.github.cowwoc.requirements10.java.internal.message.diff.DiffConstants.LINEFEED_MARKER;
15+
1416
/**
1517
* Base implementation for all diff writers.
1618
*/
@@ -126,7 +128,7 @@ protected void splitLines(CharSequence text, Consumer<String> lineConsumer)
126128
{
127129
boolean isLastLine = i == lines.length - 1;
128130
line.delete(0, line.length());
129-
line.append(lines[i]);
131+
line.append(lines[i].replace("\r", LINEFEED_MARKER));
130132
if (!isLastLine)
131133
line.append(DiffConstants.NEWLINE_MARKER);
132134
if (!line.isEmpty())

java/src/main/java/com/github/cowwoc/requirements10/java/internal/message/diff/DiffConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
*/
1212
public final class DiffConstants
1313
{
14+
/**
15+
* Character denoting a linefeed character.
16+
*/
17+
public static final String LINEFEED_MARKER = "\\r";
1418
/**
1519
* Character denoting a newline character.
1620
*/

java/src/main/java/com/github/cowwoc/requirements10/java/internal/message/section/ContextSection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public int getMaxKeyLength()
2626
}
2727

2828
@Override
29-
public List<String> getLines(int maxKeyLength)
29+
public List<String> getLinesWithPaddedKeys(int maxKeyLength)
3030
{
3131
// Align the colons vertically
3232
List<String> lines = new ArrayList<>();

java/src/main/java/com/github/cowwoc/requirements10/java/internal/message/section/MessageBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private String toString(List<MessageSection> context)
188188
StringJoiner lines = new StringJoiner("\n");
189189
for (MessageSection section : context)
190190
{
191-
for (String line : section.getLines(maxKeyLength))
191+
for (String line : section.getLinesWithPaddedKeys(maxKeyLength))
192192
lines.add(line);
193193
}
194194
return lines.toString();

java/src/main/java/com/github/cowwoc/requirements10/java/internal/message/section/MessageSection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ public sealed interface MessageSection permits ContextSection, StringSection
99
{
1010
/**
1111
* @return if the section contains key-value pairs, returns the maximum length of all keys; otherwise
12-
* returns 0
12+
* returns 0
1313
*/
1414
int getMaxKeyLength();
1515

1616
/**
1717
* @param maxKeyLength the maximum key length across all sections
18-
* @return this section's lines
18+
* @return this section's lines, with the keys padded to fill {@code maxKeyLength} characters
1919
*/
20-
List<String> getLines(int maxKeyLength);
20+
List<String> getLinesWithPaddedKeys(int maxKeyLength);
2121
}

java/src/main/java/com/github/cowwoc/requirements10/java/internal/message/section/StringSection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public int getMaxKeyLength()
2020
}
2121

2222
@Override
23-
public List<String> getLines(int maxKeyLength)
23+
public List<String> getLinesWithPaddedKeys(int maxKeyLength)
2424
{
2525
return List.of(value);
2626
}

test/src/test/java/com/github/cowwoc/requirements10/test/java/internal/diff/DiffTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static com.github.cowwoc.requirements10.java.internal.message.diff.DiffConstants.DIFF_EQUAL;
3030
import static com.github.cowwoc.requirements10.java.internal.message.diff.DiffConstants.DIFF_INSERT;
3131
import static com.github.cowwoc.requirements10.java.internal.message.diff.DiffConstants.EOS_MARKER;
32+
import static com.github.cowwoc.requirements10.java.internal.message.diff.DiffConstants.LINEFEED_MARKER;
3233
import static com.github.cowwoc.requirements10.java.internal.message.diff.DiffConstants.NEWLINE_MARKER;
3334
import static com.github.cowwoc.requirements10.java.internal.message.diff.TextOnly.DIFF_PADDING;
3435
import static org.testng.Assert.fail;
@@ -204,6 +205,34 @@ public void diffNewlinePostfix()
204205
}
205206
}
206207

208+
/**
209+
* Test multi-line text-mode diffs where actual contains a trailing linefeed character.
210+
*/
211+
@Test
212+
public void diffLinefeedPostfix()
213+
{
214+
try (ApplicationScope scope = new TestApplicationScope(NONE))
215+
{
216+
String actual = EXTEND_LENGTH("actual") + "\r";
217+
String expected = EXTEND_LENGTH("expected");
218+
new TestValidatorsImpl(scope).requireThat(actual, "actual").isEqualTo(expected);
219+
fail("Expected method to throw exception");
220+
}
221+
catch (IllegalArgumentException e)
222+
{
223+
String actualMessage = e.getMessage();
224+
String expectedMessage = "actual : \"" + EXTEND_LENGTH("actual") + LINEFEED_MARKER + "\"" +
225+
DIFF_PADDING.repeat(("\"" + EXTEND_LENGTH("expected") + "\"").length()) + EOS_MARKER + "\n" +
226+
"diff : " + DIFF_DELETE.repeat(("\"" + EXTEND_LENGTH("actual") + LINEFEED_MARKER +
227+
"\"").length()) + DIFF_INSERT.repeat(("\"" + EXTEND_LENGTH("expected") + "\"").length()) +
228+
DIFF_EQUAL.repeat(EOS_MARKER.length()) + "\n" +
229+
"expected: " + DIFF_PADDING.repeat(("\"" + EXTEND_LENGTH("actual") + LINEFEED_MARKER + "\"").
230+
length()) + "\"" + EXTEND_LENGTH("expected") + "\"" + EOS_MARKER;
231+
assert (actualMessage.contains(expectedMessage)) : "**************** Actual:\n" + actualMessage +
232+
"\n**************** Expected:\n" + expectedMessage;
233+
}
234+
}
235+
207236
/**
208237
* Test multi-line text-mode diffs containing matching text across different lines.
209238
*/

0 commit comments

Comments
 (0)