Skip to content

Commit

Permalink
Account for double-spaced characters.
Browse files Browse the repository at this point in the history
  • Loading branch information
khalidabuhakmeh committed Jul 27, 2023
1 parent 78df8bd commit e9d4841
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
24 changes: 24 additions & 0 deletions ConsoleTables.Tests/ConsoleTableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ namespace ConsoleTables.Tests
{
public class ConsoleTableTest
{
[Fact]
public void ShouldAccountForUnicodeCharacters()
{
var table = new ConsoleTable("one", "two", "three")
.AddRow(1, 2, 3)
.AddRow("this line should be longer 哈哈哈哈", "yes it is", "oh")
.ToString();

Assert.Equal(
"""
-----------------------------------------------------------
| one | two | three |
-----------------------------------------------------------
| 1 | 2 | 3 |
-----------------------------------------------------------
| this line should be longer 哈哈哈哈 | yes it is | oh |
-----------------------------------------------------------
Count: 2
""",
table
);
}

[Fact]
public void ShouldBeToStringFromList()
{
Expand Down
6 changes: 0 additions & 6 deletions src/ConsoleTables/ConsoleTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ public string ToStringAlternative()
{
var builder = new StringBuilder();

// find the longest column by searching each row
var columnLengths = ColumnLengths();

// create the string format with padding
var format = Format(columnLengths);

// find the longest formatted line
var columnHeaders = string.Format(Formats[0].TrimStart(), Columns.ToArray());

Expand Down

0 comments on commit e9d4841

Please sign in to comment.