2
0

ContentsTests.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System.Text;
  2. using UnitTests;
  3. using Xunit.Abstractions;
  4. // Alias Console to MockConsole so we don't accidentally use Console
  5. namespace Terminal.Gui.DriverTests;
  6. public class ContentsTests
  7. {
  8. private readonly ITestOutputHelper _output;
  9. public ContentsTests (ITestOutputHelper output)
  10. {
  11. ConsoleDriver.RunningUnitTests = true;
  12. _output = output;
  13. }
  14. [Theory]
  15. [InlineData (typeof (FakeDriver))]
  16. [InlineData (typeof (NetDriver))]
  17. //[InlineData (typeof (ANSIDriver))]
  18. //[InlineData (typeof (CursesDriver))] // TODO: Uncomment when #2796 and #2615 are fixed
  19. //[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed
  20. public void AddStr_Combining_Character_1st_Column (Type driverType)
  21. {
  22. var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
  23. driver!.Init ();
  24. var expected = "\u0301!";
  25. driver.AddStr ("\u0301!"); // acute accent + exclamation mark
  26. DriverAssert.AssertDriverContentsAre (expected, _output, driver);
  27. driver.End ();
  28. }
  29. [Theory]
  30. [InlineData (typeof (FakeDriver))]
  31. [InlineData (typeof (NetDriver))]
  32. //[InlineData (typeof (ANSIDriver))]
  33. //[InlineData (typeof (CursesDriver))] // TODO: Uncomment when #2796 and #2615 are fixed
  34. //[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed
  35. public void AddStr_With_Combining_Characters (Type driverType)
  36. {
  37. var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
  38. driver!.Init ();
  39. var acuteAccent = new Rune (0x0301); // Combining acute accent (é)
  40. string combined = "e" + acuteAccent;
  41. var expected = "é";
  42. driver.AddStr (combined);
  43. DriverAssert.AssertDriverContentsAre (expected, _output, driver);
  44. // 3 char combine
  45. // a + ogonek + acute = <U+0061, U+0328, U+0301> ( ą́ )
  46. var oGonek = new Rune (0x0328); // Combining ogonek (a small hook or comma shape)
  47. combined = "a" + oGonek + acuteAccent;
  48. expected = ("a" + oGonek).Normalize (NormalizationForm.FormC); // See Issue #2616
  49. driver.Move (0, 0);
  50. driver.AddStr (combined);
  51. DriverAssert.AssertDriverContentsAre (expected, _output, driver);
  52. // e + ogonek + acute = <U+0061, U+0328, U+0301> ( ę́́ )
  53. combined = "e" + oGonek + acuteAccent;
  54. expected = ("e" + oGonek).Normalize (NormalizationForm.FormC); // See Issue #2616
  55. driver.Move (0, 0);
  56. driver.AddStr (combined);
  57. DriverAssert.AssertDriverContentsAre (expected, _output, driver);
  58. // i + ogonek + acute = <U+0061, U+0328, U+0301> ( į́́́ )
  59. combined = "i" + oGonek + acuteAccent;
  60. expected = ("i" + oGonek).Normalize (NormalizationForm.FormC); // See Issue #2616
  61. driver.Move (0, 0);
  62. driver.AddStr (combined);
  63. DriverAssert.AssertDriverContentsAre (expected, _output, driver);
  64. // u + ogonek + acute = <U+0061, U+0328, U+0301> ( ų́́́́ )
  65. combined = "u" + oGonek + acuteAccent;
  66. expected = ("u" + oGonek).Normalize (NormalizationForm.FormC); // See Issue #2616
  67. driver.Move (0, 0);
  68. driver.AddStr (combined);
  69. DriverAssert.AssertDriverContentsAre (expected, _output, driver);
  70. driver.End ();
  71. }
  72. [Theory]
  73. [InlineData (typeof (FakeDriver))]
  74. [InlineData (typeof (NetDriver))]
  75. //[InlineData (typeof (ANSIDriver))]
  76. [InlineData (typeof (WindowsDriver))]
  77. [InlineData (typeof (CursesDriver))]
  78. public void Move_Bad_Coordinates (Type driverType)
  79. {
  80. var driver = (IConsoleDriver)Activator.CreateInstance (driverType);
  81. driver.Init ();
  82. Assert.Equal (0, driver.Col);
  83. Assert.Equal (0, driver.Row);
  84. driver.Move (-1, 0);
  85. Assert.Equal (-1, driver.Col);
  86. Assert.Equal (0, driver.Row);
  87. driver.Move (0, -1);
  88. Assert.Equal (0, driver.Col);
  89. Assert.Equal (-1, driver.Row);
  90. driver.Move (driver.Cols, 0);
  91. Assert.Equal (driver.Cols, driver.Col);
  92. Assert.Equal (0, driver.Row);
  93. driver.Move (0, driver.Rows);
  94. Assert.Equal (0, driver.Col);
  95. Assert.Equal (driver.Rows, driver.Row);
  96. driver.Move (500, 500);
  97. Assert.Equal (500, driver.Col);
  98. Assert.Equal (500, driver.Row);
  99. driver.End ();
  100. }
  101. // TODO: Add these unit tests
  102. // AddRune moves correctly
  103. // AddRune with wide characters are handled correctly
  104. // AddRune with wide characters and Col < 0 are handled correctly
  105. // AddRune with wide characters and Col == Cols - 1 are handled correctly
  106. // AddRune with wide characters and Col == Cols are handled correctly
  107. // AddStr moves correctly
  108. // AddStr with wide characters moves correctly
  109. // AddStr where Col is negative works
  110. // AddStr where Col is negative and characters include wide / combining characters works
  111. // AddStr where Col is near Cols and characters include wide / combining characters works
  112. // Clipping works correctly
  113. // Clipping works correctly with wide characters
  114. // Clipping works correctly with combining characters
  115. // Clipping works correctly with combining characters and wide characters
  116. // ResizeScreen works correctly
  117. // Refresh works correctly
  118. // IsDirty tests
  119. }