Skip to content

Commit

Permalink
- B fixed issue where long header broke markdown table
Browse files Browse the repository at this point in the history
Co-Authored-By: Thomas Stuttard <tom.e.stuttard@gmail.com>
  • Loading branch information
isidore and tstuttard committed Mar 27, 2024
1 parent 0a9bb4a commit f806635
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ void abilityModifier()
Approvals.verify(table);
}
@Test
void veryLongHeaders()
{
Integer[] inputs = Range.get(1, 2);
VerifiableMarkdownTable table = VerifiableMarkdownTable.create(inputs, a -> getModifier(a),
"The name is very long and it is a header", "Modifier");
Approvals.verify(table);
}
@Test
void differentCases()
{
// begin-snippet: markdown_table_example
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| The name is very long and it is a header | Modifier |
|------------------------------------------|----------|
| 1 | -5 |
| 2 | -4 |
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,14 @@ public void testSplitting()
ParseInput.from(expected).withTypes(String.class, String.class)
.verifyAll((i, p) -> Arrays.toString(StringUtils.split(i, p)));
}
@Test
@UseReporter(AutoApproveReporter.class)
public void testRepeating()
{
var expected = """
Hello, 3 -> HelloHelloHello
-, 56 -> --------------------------------------------------------
""";
ParseInput.from(expected).withTypes(String.class, Integer.class).verifyAll((s, i) -> StringUtils.repeat(s, i));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,8 @@ public static String removeFromEnd(String contents, int length)
{
return contents.substring(0, contents.length() - length);
}
public static String repeat(String string, int times)
{
return new String(new char[times]).replace("\0", string);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.spun.util.markdown.table;

import com.spun.util.StringUtils;

public class MarkdownTableHeader implements MarkdownTableElement, Resizable
{
private int padUntil = 1;
Expand All @@ -11,7 +13,7 @@ public MarkdownTableHeader()
public String toString()
{
int dashCount = padUntil + 2; // Math.max(3, padUntil + 2);
String dashes = "----------------------------------".substring(0, dashCount);
String dashes = StringUtils.repeat("-", dashCount);
if (columnProperties == MarkdownColumn.RIGHT_JUSTIFIED)
{
dashes = dashes.substring(0, dashCount - 1) + ":";
Expand Down

0 comments on commit f806635

Please sign in to comment.