ContentsTests.cs 5.3 KB

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