Skip to content

Commit f806635

Browse files
isidoretstuttard
andcommitted
- B fixed issue where long header broke markdown table
Co-Authored-By: Thomas Stuttard <[email protected]>
1 parent 0a9bb4a commit f806635

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

approvaltests-tests/src/test/java/org/approvaltests/TableTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ void abilityModifier()
1515
Approvals.verify(table);
1616
}
1717
@Test
18+
void veryLongHeaders()
19+
{
20+
Integer[] inputs = Range.get(1, 2);
21+
VerifiableMarkdownTable table = VerifiableMarkdownTable.create(inputs, a -> getModifier(a),
22+
"The name is very long and it is a header", "Modifier");
23+
Approvals.verify(table);
24+
}
25+
@Test
1826
void differentCases()
1927
{
2028
// begin-snippet: markdown_table_example
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| The name is very long and it is a header | Modifier |
2+
|------------------------------------------|----------|
3+
| 1 | -5 |
4+
| 2 | -4 |

approvaltests-util-tests/src/test/java/com/spun/util/StringUtilsTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,14 @@ public void testSplitting()
142142
ParseInput.from(expected).withTypes(String.class, String.class)
143143
.verifyAll((i, p) -> Arrays.toString(StringUtils.split(i, p)));
144144
}
145+
@Test
146+
@UseReporter(AutoApproveReporter.class)
147+
public void testRepeating()
148+
{
149+
var expected = """
150+
Hello, 3 -> HelloHelloHello
151+
-, 56 -> --------------------------------------------------------
152+
""";
153+
ParseInput.from(expected).withTypes(String.class, Integer.class).verifyAll((s, i) -> StringUtils.repeat(s, i));
154+
}
145155
}

approvaltests-util/src/main/java/com/spun/util/StringUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,4 +621,8 @@ public static String removeFromEnd(String contents, int length)
621621
{
622622
return contents.substring(0, contents.length() - length);
623623
}
624+
public static String repeat(String string, int times)
625+
{
626+
return new String(new char[times]).replace("\0", string);
627+
}
624628
}

approvaltests-util/src/main/java/com/spun/util/markdown/table/MarkdownTableHeader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.spun.util.markdown.table;
22

3+
import com.spun.util.StringUtils;
4+
35
public class MarkdownTableHeader implements MarkdownTableElement, Resizable
46
{
57
private int padUntil = 1;
@@ -11,7 +13,7 @@ public MarkdownTableHeader()
1113
public String toString()
1214
{
1315
int dashCount = padUntil + 2; // Math.max(3, padUntil + 2);
14-
String dashes = "----------------------------------".substring(0, dashCount);
16+
String dashes = StringUtils.repeat("-", dashCount);
1517
if (columnProperties == MarkdownColumn.RIGHT_JUSTIFIED)
1618
{
1719
dashes = dashes.substring(0, dashCount - 1) + ":";

0 commit comments

Comments
 (0)