ContentsTests.cs 4.9 KB

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