ContentsTests.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 (CursesDriver))] // TODO: Uncomment when #2796 and #2615 are fixed
  22. //[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed
  23. public void AddStr_Combining_Character_1st_Column (Type driverType)
  24. {
  25. var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
  26. driver.Init ();
  27. var expected = "\u0301!";
  28. driver.AddStr ("\u0301!"); // acute accent + exclamation mark
  29. TestHelpers.AssertDriverContentsAre (expected, output, driver);
  30. driver.End ();
  31. }
  32. [Theory]
  33. [InlineData (typeof (FakeDriver))]
  34. [InlineData (typeof (NetDriver))]
  35. //[InlineData (typeof (CursesDriver))] // TODO: Uncomment when #2796 and #2615 are fixed
  36. //[InlineData (typeof (WindowsDriver))] // TODO: Uncomment when #2610 is fixed
  37. public void AddStr_With_Combining_Characters (Type driverType)
  38. {
  39. var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
  40. driver.Init ();
  41. var acuteaccent = new System.Text.Rune (0x0301); // Combining acute accent (é)
  42. var combined = "e" + acuteaccent;
  43. var expected = "é";
  44. driver.AddStr (combined);
  45. TestHelpers.AssertDriverContentsAre (expected, output, driver);
  46. // 3 char combine
  47. // a + ogonek + acute = <U+0061, U+0328, U+0301> ( ą́ )
  48. var ogonek = new System.Text.Rune (0x0328); // Combining ogonek (a small hook or comma shape)
  49. combined = "a" + ogonek + acuteaccent;
  50. expected = ("a" + ogonek).Normalize(NormalizationForm.FormC); // See Issue #2616
  51. driver.Move (0, 0);
  52. driver.AddStr (combined);
  53. TestHelpers.AssertDriverContentsAre (expected, output, driver);
  54. // e + ogonek + acute = <U+0061, U+0328, U+0301> ( ę́́ )
  55. combined = "e" + ogonek + acuteaccent;
  56. expected = ("e" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616
  57. driver.Move (0, 0);
  58. driver.AddStr (combined);
  59. TestHelpers.AssertDriverContentsAre (expected, output, driver);
  60. // i + ogonek + acute = <U+0061, U+0328, U+0301> ( į́́́ )
  61. combined = "i" + ogonek + acuteaccent;
  62. expected = ("i" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616
  63. driver.Move (0, 0);
  64. driver.AddStr (combined);
  65. TestHelpers.AssertDriverContentsAre (expected, output, driver);
  66. // u + ogonek + acute = <U+0061, U+0328, U+0301> ( ų́́́́ )
  67. combined = "u" + ogonek + acuteaccent;
  68. expected = ("u" + ogonek).Normalize (NormalizationForm.FormC); // See Issue #2616
  69. driver.Move (0, 0);
  70. driver.AddStr (combined);
  71. TestHelpers.AssertDriverContentsAre (expected, output, driver);
  72. driver.End ();
  73. }
  74. [Theory]
  75. [InlineData (typeof (FakeDriver))]
  76. [InlineData (typeof (NetDriver))]
  77. [InlineData (typeof (CursesDriver))]
  78. [InlineData (typeof (WindowsDriver))]
  79. public void Move_Bad_Coordinates (Type driverType)
  80. {
  81. var driver = (ConsoleDriver)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. }