-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from BDisp/column-width
Fixes #47. ColumnWidth needs to differentiate between non-printable and null characters.
- Loading branch information
Showing
3 changed files
with
83 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,48 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using System; | ||
namespace NStackTests { | ||
public class RuneTest { | ||
public RuneTest () | ||
Rune a = 'a'; | ||
Rune b = 'b'; | ||
Rune c = 123; | ||
Rune d = '\u1150'; // 0x1150 ᅐ Unicode Technical Report #11 | ||
Rune e = '\u1161'; // 0x1161 ᅡ null character with column equal to 0 | ||
Rune f = 31; // non printable character | ||
Rune g = 127; // non printable character | ||
|
||
[Test] | ||
public void TestColumnWidth() | ||
{ | ||
Rune a = 'a'; | ||
Rune b = 'b'; | ||
var rt = new RuneTest(); | ||
|
||
Assert.AreEqual(1, Rune.ColumnWidth(rt.a)); | ||
Assert.AreEqual(1, Rune.ColumnWidth(rt.b)); | ||
var l = a < b; | ||
Rune c = 123; | ||
Assert.IsTrue(l); | ||
Assert.AreEqual(1, Rune.ColumnWidth(rt.c)); | ||
Assert.AreEqual(2, Rune.ColumnWidth(rt.d)); | ||
Assert.AreEqual(0, Rune.ColumnWidth(rt.e)); | ||
Assert.AreEqual(-1, Rune.ColumnWidth(rt.f)); | ||
Assert.AreEqual(-1, Rune.ColumnWidth(rt.g)); | ||
} | ||
|
||
[Test] | ||
public void TestRune() | ||
{ | ||
Rune a = new Rune('a'); | ||
Assert.AreEqual("a", a.ToString()); | ||
Rune b = new Rune(0x0061); | ||
Assert.AreEqual("a", b.ToString()); | ||
Rune c = new Rune('\u0061'); | ||
Assert.AreEqual("a", c.ToString()); | ||
Rune d = new Rune(0x10421); | ||
Assert.AreEqual("𐐡", d.ToString()); | ||
Assert.Throws<ArgumentOutOfRangeException>(() => new Rune('\ud799', '\udc21')); | ||
Rune e = new Rune('\ud801', '\udc21'); | ||
Assert.AreEqual("𐐡", e.ToString()); | ||
Assert.Throws<ArgumentException>(() => new Rune('\ud801')); | ||
Rune f = new Rune('\ud83c', '\udf39'); | ||
Assert.AreEqual("🌹", f.ToString()); | ||
} | ||
} | ||
} |