|
|
|
@@ -22,8 +22,8 @@ package net.minecraftforge.test;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import net.minecraftforge.common.util.TextTable;
|
|
|
|
|
import net.minecraftforge.common.util.TextTable.Column;
|
|
|
|
|
import org.junit.Assert;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
|
|
|
|
import static net.minecraftforge.common.util.TextTable.column;
|
|
|
|
|
|
|
|
|
@@ -38,12 +38,12 @@ public class TextTableTest
|
|
|
|
|
Column column = column("Column", TextTable.Alignment.LEFT);
|
|
|
|
|
column.fit(WIDTH_REFERENCE);
|
|
|
|
|
String paddedHeader = column.formatHeader("-");
|
|
|
|
|
Assert.assertEquals("Formatted column header didn't have correct length", WIDTH_REFERENCE_LENGTH, paddedHeader.length());
|
|
|
|
|
Assert.assertEquals("Formatted column header wasn't padded properly", "Column---------", paddedHeader);
|
|
|
|
|
assertEquals(WIDTH_REFERENCE_LENGTH, paddedHeader.length(), "Formatted column header didn't have correct length");
|
|
|
|
|
assertEquals("Column---------", paddedHeader, "Formatted column header wasn't padded properly");
|
|
|
|
|
|
|
|
|
|
String paddedReference = column.format(WIDTH_REFERENCE, "-");
|
|
|
|
|
Assert.assertEquals("Formatted width reference didn't have correct length", WIDTH_REFERENCE_LENGTH, paddedReference.length());
|
|
|
|
|
Assert.assertEquals("Formatted width reference was changed despite defining width", WIDTH_REFERENCE, paddedReference);
|
|
|
|
|
assertEquals(WIDTH_REFERENCE_LENGTH, paddedReference.length(), "Formatted width reference didn't have correct length");
|
|
|
|
|
assertEquals(WIDTH_REFERENCE, paddedReference, "Formatted width reference was changed despite defining width");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@@ -52,12 +52,9 @@ public class TextTableTest
|
|
|
|
|
Column column = column("Left", TextTable.Alignment.LEFT);
|
|
|
|
|
column.fit(WIDTH_REFERENCE);
|
|
|
|
|
|
|
|
|
|
String paddedHeader = column.formatHeader("-");
|
|
|
|
|
Assert.assertEquals("Left-aligned header should be padded on the right", "Left-----------", paddedHeader);
|
|
|
|
|
String paddedReference = column.format(WIDTH_REFERENCE, "-");
|
|
|
|
|
Assert.assertEquals("Left-aligned reference should'nt be padded", WIDTH_REFERENCE, paddedReference);
|
|
|
|
|
String paddedValue = column.format("Value", "-");
|
|
|
|
|
Assert.assertEquals("Left-aligned value should be padded on the right", "Value----------", paddedValue);
|
|
|
|
|
assertEquals("Left-----------", column.formatHeader("-"), "Left-aligned header should be padded on the right");
|
|
|
|
|
assertEquals(WIDTH_REFERENCE, column.format(WIDTH_REFERENCE, "-"), "Left-aligned reference should'nt be padded");
|
|
|
|
|
assertEquals("Value----------", column.format("Value", "-"), "Left-aligned value should be padded on the right");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@@ -66,14 +63,10 @@ public class TextTableTest
|
|
|
|
|
Column column = column("Centered", TextTable.Alignment.CENTER);
|
|
|
|
|
column.fit(WIDTH_REFERENCE);
|
|
|
|
|
|
|
|
|
|
String paddedHeader = column.formatHeader("-");
|
|
|
|
|
Assert.assertEquals("Centered header should be padded equally on both sides", "---Centered----", paddedHeader);
|
|
|
|
|
String paddedReference = column.format(WIDTH_REFERENCE, "-");
|
|
|
|
|
Assert.assertEquals("Centered reference should'nt be padded", WIDTH_REFERENCE, paddedReference);
|
|
|
|
|
String paddedValue = column.format("Value", "-");
|
|
|
|
|
Assert.assertEquals("Centered value should be padded equally on both sides", "-----Value-----", paddedValue);
|
|
|
|
|
String paddedOffCenter = column.format("Value1", "-");
|
|
|
|
|
Assert.assertNotEquals("Center padding should be left-biased", "-----Value1----", paddedOffCenter);
|
|
|
|
|
assertEquals("---Centered----", column.formatHeader("-"), "Centered header should be padded equally on both sides");
|
|
|
|
|
assertEquals(WIDTH_REFERENCE, column.format(WIDTH_REFERENCE, "-"), "Centered reference should'nt be padded");
|
|
|
|
|
assertEquals("-----Value-----", column.format("Value", "-"), "Centered value should be padded equally on both sides");
|
|
|
|
|
assertNotEquals("-----Value1----", column.format("Value1", "-"), "Center padding should be left-biased");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@@ -82,12 +75,9 @@ public class TextTableTest
|
|
|
|
|
Column column = column("Right", TextTable.Alignment.RIGHT);
|
|
|
|
|
column.fit(WIDTH_REFERENCE);
|
|
|
|
|
|
|
|
|
|
String paddedHeader = column.formatHeader("-");
|
|
|
|
|
Assert.assertEquals("Right-aligned header should be padded on the left", "----------Right", paddedHeader);
|
|
|
|
|
String paddedReference = column.format(WIDTH_REFERENCE, "-");
|
|
|
|
|
Assert.assertEquals("Right-aligned reference should'nt be padded", WIDTH_REFERENCE, paddedReference);
|
|
|
|
|
String paddedValue = column.format("Value", "-");
|
|
|
|
|
Assert.assertEquals("Right-aligned value should be padded on the left", "----------Value", paddedValue);
|
|
|
|
|
assertEquals("----------Right", column.formatHeader("-"), "Right-aligned header should be padded on the left");
|
|
|
|
|
assertEquals(WIDTH_REFERENCE, column.format(WIDTH_REFERENCE, "-"), "Right-aligned reference should'nt be padded");
|
|
|
|
|
assertEquals("----------Value", column.format("Value", "-"), "Right-aligned value should be padded on the left");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@@ -102,18 +92,11 @@ public class TextTableTest
|
|
|
|
|
table.add("Value 1", "Long Value 2", "Value 3");
|
|
|
|
|
table.add("Value 1", "Value 2", "Long Value 3");
|
|
|
|
|
int[] columnWidths = table.getColumns().stream().mapToInt(Column::getWidth).toArray();
|
|
|
|
|
Assert.assertArrayEquals("Column widths should adjust for long values", new int[]{12, 12, 12}, columnWidths);
|
|
|
|
|
assertArrayEquals(new int[]{12, 12, 12}, columnWidths, "Column widths should adjust for long values");
|
|
|
|
|
|
|
|
|
|
String[] result = table.build("\n").split("\n");
|
|
|
|
|
Assert.assertEquals("Header row + separator row + value rows should result in 5 lines", 5, result.length);
|
|
|
|
|
Assert.assertEquals(
|
|
|
|
|
"Column headers should be properly formatted",
|
|
|
|
|
"| Left | Center | Right |",
|
|
|
|
|
result[0]);
|
|
|
|
|
Assert.assertEquals(
|
|
|
|
|
"Header-body separators should contain markdown alignment information",
|
|
|
|
|
"|:------------ |:------------:| ------------:|",
|
|
|
|
|
result[1]
|
|
|
|
|
);
|
|
|
|
|
assertEquals(5, result.length, "Header row + separator row + value rows should result in 5 lines");
|
|
|
|
|
assertEquals("| Left | Center | Right |", result[0], "Column headers should be properly formatted");
|
|
|
|
|
assertEquals("|:------------ |:------------:| ------------:|", result[1], "Header-body separators should contain markdown alignment information");
|
|
|
|
|
}
|
|
|
|
|
}
|