20 package net.sf.gridarta.utils;
22 import org.jetbrains.annotations.NotNull;
23 import org.jetbrains.annotations.Nullable;
24 import org.junit.Assert;
25 import org.junit.Test;
31 @SuppressWarnings(
"JavaDoc")
39 testRemoveTrailingWhitespace(
"",
"");
40 testRemoveTrailingWhitespace(
" ",
"");
41 testRemoveTrailingWhitespace(
" abc def ",
" abc def");
42 testRemoveTrailingWhitespace(
" abc \n def ",
" abc \n def");
59 testRemoveTrailingWhitespaceFromLines(
"",
"");
60 testRemoveTrailingWhitespaceFromLines(
" ",
"");
61 testRemoveTrailingWhitespaceFromLines(
" abc def ",
" abc def");
62 testRemoveTrailingWhitespaceFromLines(
"\n",
"\n");
63 testRemoveTrailingWhitespaceFromLines(
"abc\n" +
"def\n" +
"ghi\n",
"abc\n" +
"def\n" +
"ghi\n");
64 testRemoveTrailingWhitespaceFromLines(
" abc\n" +
"def\n" +
"ghi\n",
" abc\n" +
"def\n" +
"ghi\n");
65 testRemoveTrailingWhitespaceFromLines(
"abc \n" +
"def\n" +
"ghi\n",
"abc\n" +
"def\n" +
"ghi\n");
66 testRemoveTrailingWhitespaceFromLines(
" abc \n d e f \n g h i \n ",
" abc\n d e f\n g h i\n");
83 testEnsureTrailingNewline(
"",
"");
84 testEnsureTrailingNewline(
"\n",
"\n");
85 testEnsureTrailingNewline(
" abc def ",
" abc def \n");
86 testEnsureTrailingNewline(
"\n\n\n",
"\n\n\n");
87 testEnsureTrailingNewline(
"abc\n\n" +
"def",
"abc\n\n" +
"def\n");
105 testDiffTextString(
"",
"abc",
null,
null);
107 testDiffTextString(
"abc",
"abc",
"abc",
"abc");
108 testDiffTextString(
"abc\n" +
"def",
"abc",
"abc",
"abc");
109 testDiffTextString(
"def\n" +
"abc\n" +
"def",
"abc",
"abc",
"abc");
110 testDiffTextString(
"def\n" +
"abc",
"abc",
"abc",
"abc");
112 testDiffTextString(
"abc def",
"abc",
null,
"abc def");
113 testDiffTextString(
"def abc\n" +
"abc def",
"abc",
null,
"abc def");
114 testDiffTextString(
"abc def\n" +
"def abc",
"abc",
null,
"abc def");
115 testDiffTextString(
"def abc\n" +
"abc def\n" +
"def abc",
"abc",
null,
"abc def");
128 private static void testDiffTextString(@NotNull
final CharSequence base, @NotNull
final String str, @Nullable
final String expectedFalse, @Nullable
final String expectedTrue) {
138 testGetAttribute(
"",
"abc",
null);
139 testGetAttribute(
"abc def",
"abc",
"def");
140 testGetAttribute(
"abc def",
"ab",
null);
141 testGetAttribute(
"abc def",
"def",
null);
142 testGetAttribute(
"abc def\n" +
"ghi jkl\n" +
"mno pqr\n",
"abc",
"def");
143 testGetAttribute(
"abc def\n" +
"ghi jkl\n" +
"mno pqr\n",
"ghi",
"jkl");
144 testGetAttribute(
"abc def\n" +
"ghi jkl\n" +
"mno pqr\n",
"mno",
"pqr");
145 testGetAttribute(
"abc def\n" +
"ghi jkl\n" +
"mno pqr\n",
"xxx",
null);
155 private static void testGetAttribute(@NotNull
final CharSequence attributes, @NotNull
final String attributeName, @Nullable
final String expectedAttributeValue) {
157 Assert.assertEquals(expectedAttributeValue, attributeValue);