Skip to content

Commit

Permalink
Merge pull request #975 from BDisp/rune-versions
Browse files Browse the repository at this point in the history
#41 and #949. Unit test to compare the difference between System.Rune and System.Text.Rune.
  • Loading branch information
tig authored Oct 28, 2020
2 parents 5f9ce32 + 9615769 commit b521a07
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions UnitTests/TextFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2242,5 +2242,69 @@ public void Reformat_Unicode_Wrap_Spaces_NewLines ()
Assert.Equal ("\u2460\u2461\u2462", list [0]);
Assert.Equal ("\u2460\u2461\u2462\u2463\u2464", list [1]);
}

[Fact]
public void System_Rune_ColumnWidth ()
{
var c = new System.Rune ('a');
Assert.Equal (1, Rune.ColumnWidth (c));
Assert.Equal (1, ustring.Make (c).ConsoleWidth);
Assert.Equal (1, ustring.Make (c).Length);

c = new System.Rune ('b');
Assert.Equal (1, Rune.ColumnWidth (c));
Assert.Equal (1, ustring.Make (c).ConsoleWidth);
Assert.Equal (1, ustring.Make (c).Length);

c = new System.Rune (123);
Assert.Equal (1, Rune.ColumnWidth (c));
Assert.Equal (1, ustring.Make (c).ConsoleWidth);
Assert.Equal (1, ustring.Make (c).Length);

c = new System.Rune ('\u1150');
Assert.Equal (2, Rune.ColumnWidth (c)); // 0x1150 ᅐ Unicode Technical Report #11
Assert.Equal (2, ustring.Make (c).ConsoleWidth);
Assert.Equal (3, ustring.Make (c).Length);

c = new System.Rune ('\u1161');
Assert.Equal (0, Rune.ColumnWidth (c)); // 0x1161 ᅡ column width of 0
Assert.Equal (0, ustring.Make (c).ConsoleWidth);
Assert.Equal (3, ustring.Make (c).Length);

c = new System.Rune (31);
Assert.Equal (0, Rune.ColumnWidth (c)); // non printable character
Assert.Equal (0, ustring.Make (c).ConsoleWidth);
Assert.Equal (1, ustring.Make (c).Length);

c = new System.Rune (127);
Assert.Equal (0, Rune.ColumnWidth (c)); // non printable character
Assert.Equal (0, ustring.Make (c).ConsoleWidth);
Assert.Equal (1, ustring.Make (c).Length);
}

[Fact]
public void System_Text_Rune ()
{
var c = new System.Text.Rune ('a');
Assert.Equal (1, c.Utf8SequenceLength);

c = new System.Text.Rune ('b');
Assert.Equal (1, c.Utf8SequenceLength);

c = new System.Text.Rune (123);
Assert.Equal (1, c.Utf8SequenceLength);

c = new System.Text.Rune ('\u1150');
Assert.Equal (3, c.Utf8SequenceLength); // 0x1150 ᅐ Unicode Technical Report #11

c = new System.Text.Rune ('\u1161');
Assert.Equal (3, c.Utf8SequenceLength); // 0x1161 ᅡ column width of 0

c = new System.Text.Rune (31);
Assert.Equal (1, c.Utf8SequenceLength); // non printable character

c = new System.Text.Rune (127);
Assert.Equal (1, c.Utf8SequenceLength); // non printable character
}
}
}

0 comments on commit b521a07

Please sign in to comment.