UnicodeTests.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using NStack;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Terminal.Gui;
  6. using Xunit;
  7. using Xunit.Abstractions;
  8. // Alias Console to MockConsole so we don't accidentally use Console
  9. using Console = Terminal.Gui.FakeConsole;
  10. namespace Terminal.Gui.TextTests {
  11. public class UnicodeTests {
  12. readonly ITestOutputHelper output;
  13. public UnicodeTests (ITestOutputHelper output)
  14. {
  15. this.output = output;
  16. }
  17. [Theory]
  18. [InlineData (0x0000001F, 0x241F)]
  19. [InlineData (0x0000007F, 0x247F)]
  20. [InlineData (0x0000009F, 0x249F)]
  21. [InlineData (0x0001001A, 0x1001A)]
  22. public void MakePrintable_Converts_Control_Chars_To_Proper_Unicode (uint code, uint expected)
  23. {
  24. var actual = ConsoleDriver.MakePrintable (code);
  25. Assert.Equal (expected, actual.Value);
  26. }
  27. [Theory]
  28. [InlineData (0x20)]
  29. [InlineData (0x7E)]
  30. [InlineData (0xA0)]
  31. [InlineData (0x010020)]
  32. public void MakePrintable_Does_Not_Convert_Ansi_Chars_To_Unicode (uint code)
  33. {
  34. var actual = ConsoleDriver.MakePrintable (code);
  35. Assert.Equal (code, actual.Value);
  36. }
  37. [Fact, AutoInitShutdown]
  38. public void AddRune_On_Clip_Left_Or_Right_Replace_Previous_Or_Next_Wide_Rune_With_Space ()
  39. {
  40. var tv = new TextView () {
  41. Width = Dim.Fill (),
  42. Height = Dim.Fill (),
  43. Text = @"これは広いルーンラインです。
  44. これは広いルーンラインです。
  45. これは広いルーンラインです。
  46. これは広いルーンラインです。
  47. これは広いルーンラインです。
  48. これは広いルーンラインです。
  49. これは広いルーンラインです。
  50. これは広いルーンラインです。"
  51. };
  52. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  53. win.Add (tv);
  54. Application.Top.Add (win);
  55. var lbl = new Label ("ワイドルーン。");
  56. var dg = new Dialog (new Button ("選ぶ")) { Width = 14, Height = 4 };
  57. dg.Add (lbl);
  58. Application.Begin (Application.Top);
  59. Application.Begin (dg);
  60. ((FakeDriver)Application.Driver).SetBufferSize (30, 10);
  61. var expected = @$"
  62. ┌────────────────────────────┐
  63. │これは広いルーンラインです。│
  64. │これは広いルーンラインです。│
  65. │これは ┌────────────┐ です。│
  66. │これは │ワイドルーン│ です。│
  67. │これは │ {CM.Glyphs.LeftBracket} 選ぶ {CM.Glyphs.RightBracket} │ です。│
  68. │これは └────────────┘ です。│
  69. │これは広いルーンラインです。│
  70. │これは広いルーンラインです。│
  71. └────────────────────────────┘
  72. ";
  73. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  74. Assert.Equal (new Rect (0, 0, 30, 10), pos);
  75. }
  76. }
  77. }