Sfoglia il codice sorgente

Merge pull request #975 from BDisp/rune-versions

#41 and #949. Unit test to compare the difference between System.Rune and System.Text.Rune.
Charlie Kindel 4 anni fa
parent
commit
b521a07c77
1 ha cambiato i file con 64 aggiunte e 0 eliminazioni
  1. 64 0
      UnitTests/TextFormatterTests.cs

+ 64 - 0
UnitTests/TextFormatterTests.cs

@@ -2242,5 +2242,69 @@ namespace Terminal.Gui {
 			Assert.Equal ("\u2460\u2461\u2462", list [0]);
 			Assert.Equal ("\u2460\u2461\u2462", list [0]);
 			Assert.Equal ("\u2460\u2461\u2462\u2463\u2464", list [1]);
 			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
+		}
 	}
 	}
 }
 }