ContentsTests.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 UnitTests_Parallelizable.DriverTests;
  6. public class ContentsTests (ITestOutputHelper output) : FakeDriverBase
  7. {
  8. [Fact]
  9. public void AddStr_Combining_Character_1st_Column ()
  10. {
  11. IDriver driver = CreateFakeDriver ();
  12. var expected = "\u0301!";
  13. driver.AddStr ("\u0301!"); // acute accent + exclamation mark
  14. DriverAssert.AssertDriverContentsAre (expected, output, driver);
  15. driver.End ();
  16. }
  17. [Fact]
  18. public void AddStr_With_Combining_Characters ()
  19. {
  20. IDriver driver = CreateFakeDriver ();
  21. var acuteAccent = new Rune (0x0301); // Combining acute accent (é)
  22. string combined = "e" + acuteAccent;
  23. var expected = "é";
  24. driver.AddStr (combined);
  25. DriverAssert.AssertDriverContentsAre (expected, output, driver);
  26. // 3 char combine
  27. // a + ogonek + acute = <U+0061, U+0328, U+0301> ( ą́ )
  28. var oGonek = new Rune (0x0328); // Combining ogonek (a small hook or comma shape)
  29. combined = "a" + oGonek + acuteAccent;
  30. expected = ("a" + oGonek + acuteAccent).Normalize (NormalizationForm.FormC); // See Issue #2616
  31. driver.Move (0, 0);
  32. driver.AddStr (combined);
  33. DriverAssert.AssertDriverContentsAre (expected, output, driver);
  34. // e + ogonek + acute = <U+0061, U+0328, U+0301> ( ę́́ )
  35. combined = "e" + oGonek + acuteAccent;
  36. expected = ("e" + oGonek + acuteAccent).Normalize (NormalizationForm.FormC); // See Issue #2616
  37. driver.Move (0, 0);
  38. driver.AddStr (combined);
  39. DriverAssert.AssertDriverContentsAre (expected, output, driver);
  40. // i + ogonek + acute = <U+0061, U+0328, U+0301> ( į́́́ )
  41. combined = "i" + oGonek + acuteAccent;
  42. expected = ("i" + oGonek + acuteAccent).Normalize (NormalizationForm.FormC); // See Issue #2616
  43. driver.Move (0, 0);
  44. driver.AddStr (combined);
  45. DriverAssert.AssertDriverContentsAre (expected, output, driver);
  46. // u + ogonek + acute = <U+0061, U+0328, U+0301> ( ų́́́́ )
  47. combined = "u" + oGonek + acuteAccent;
  48. expected = ("u" + oGonek + acuteAccent).Normalize (NormalizationForm.FormC); // See Issue #2616
  49. driver.Move (0, 0);
  50. driver.AddStr (combined);
  51. DriverAssert.AssertDriverContentsAre (expected, output, driver);
  52. driver.End ();
  53. }
  54. [Fact]
  55. public void Move_Bad_Coordinates ()
  56. {
  57. IDriver driver = CreateFakeDriver ();
  58. Assert.Equal (0, driver.Col);
  59. Assert.Equal (0, driver.Row);
  60. driver.Move (-1, 0);
  61. Assert.Equal (-1, driver.Col);
  62. Assert.Equal (0, driver.Row);
  63. driver.Move (0, -1);
  64. Assert.Equal (0, driver.Col);
  65. Assert.Equal (-1, driver.Row);
  66. driver.Move (driver.Cols, 0);
  67. Assert.Equal (driver.Cols, driver.Col);
  68. Assert.Equal (0, driver.Row);
  69. driver.Move (0, driver.Rows);
  70. Assert.Equal (0, driver.Col);
  71. Assert.Equal (driver.Rows, driver.Row);
  72. driver.Move (500, 500);
  73. Assert.Equal (500, driver.Col);
  74. Assert.Equal (500, driver.Row);
  75. driver.End ();
  76. }
  77. // TODO: Add these unit tests
  78. // AddRune moves correctly
  79. // AddRune with wide characters are handled correctly
  80. // AddRune with wide characters and Col < 0 are handled correctly
  81. // AddRune with wide characters and Col == Cols - 1 are handled correctly
  82. // AddRune with wide characters and Col == Cols are handled correctly
  83. // AddStr moves correctly
  84. // AddStr with wide characters moves correctly
  85. // AddStr where Col is negative works
  86. // AddStr where Col is negative and characters include wide / combining characters works
  87. // AddStr where Col is near Cols and characters include wide / combining characters works
  88. // Clipping works correctly
  89. // Clipping works correctly with wide characters
  90. // Clipping works correctly with combining characters
  91. // Clipping works correctly with combining characters and wide characters
  92. // ResizeScreen works correctly
  93. // Refresh works correctly
  94. // IsDirty tests
  95. }