ContentsTests.cs 5.2 KB

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