ContentsTests.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Xunit;
  6. using Xunit.Abstractions;
  7. // Alias Console to MockConsole so we don't accidentally use Console
  8. using Console = Terminal.Gui.FakeConsole;
  9. namespace Terminal.Gui.DriverTests;
  10. public class ContentsTests {
  11. readonly ITestOutputHelper output;
  12. public ContentsTests (ITestOutputHelper output)
  13. {
  14. this.output = output;
  15. }
  16. [Theory]
  17. [InlineData (typeof (FakeDriver))]
  18. //[InlineData (typeof (NetDriver))]
  19. //[InlineData (typeof (CursesDriver))]
  20. //[InlineData (typeof (WindowsDriver))]
  21. public void AddStr_With_Combining_Characters (Type driverType)
  22. {
  23. var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
  24. Application.Init (driver);
  25. // driver.Init (null);
  26. var acuteaccent = new System.Text.Rune (0x0301); // Combining acute accent (é)
  27. var combined = "e" + acuteaccent;
  28. var expected = "é";
  29. driver.AddStr (combined);
  30. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  31. #if false // Disabled Until #2616 is fixed
  32. // 3 char combine
  33. // a + ogonek + acute = <U+0061, U+0328, U+0301> ( ǫ́ )
  34. var ogonek = new System.Text.Rune (0x0328); // Combining ogonek (a small hook or comma shape)
  35. combined = "a" + ogonek + acuteaccent;
  36. expected = "ǫ́";
  37. driver.Move (0, 0);
  38. driver.AddStr (combined);
  39. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  40. #endif
  41. // Shutdown must be called to safely clean up Application if Init has been called
  42. Application.Shutdown ();
  43. }
  44. [Theory]
  45. [InlineData (typeof (FakeDriver))]
  46. //[InlineData (typeof (NetDriver))]
  47. //[InlineData (typeof (CursesDriver))]
  48. //[InlineData (typeof (WindowsDriver))]
  49. public void Move_Bad_Coordinates (Type driverType)
  50. {
  51. var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
  52. Application.Init (driver);
  53. Assert.Equal (0, driver.Col);
  54. Assert.Equal (0, driver.Row);
  55. driver.Move (-1, 0);
  56. Assert.Equal (-1, driver.Col);
  57. Assert.Equal (0, driver.Row);
  58. driver.Move (0, -1);
  59. Assert.Equal (0, driver.Col);
  60. Assert.Equal (-1, driver.Row);
  61. driver.Move (driver.Cols, 0);
  62. Assert.Equal (driver.Cols, driver.Col);
  63. Assert.Equal (0, driver.Row);
  64. driver.Move (0, driver.Rows);
  65. Assert.Equal (0, driver.Col);
  66. Assert.Equal (driver.Rows, driver.Row);
  67. driver.Move (500, 500);
  68. Assert.Equal (500, driver.Col);
  69. Assert.Equal (500, driver.Row);
  70. // Shutdown must be called to safely clean up Application if Init has been called
  71. Application.Shutdown ();
  72. }
  73. // TODO: Add these unit tests
  74. // AddRune moves correctly
  75. // AddRune with wide characters are handled correctly
  76. // AddRune with wide characters and Col < 0 are handled correctly
  77. // AddRune with wide characters and Col == Cols - 1 are handled correctly
  78. // AddRune with wide characters and Col == Cols are handled correctly
  79. // AddStr moves correctly
  80. // AddStr with wide characters moves correctly
  81. // AddStr where Col is negative works
  82. // AddStr where Col is negative and characters include wide / combining characters works
  83. // AddStr where Col is near Cols and characters include wide / combining characters works
  84. // Clipping works correctly
  85. // Clipping works correctly with wide characters
  86. // Clipping works correctly with combining characters
  87. // Clipping works correctly with combining characters and wide characters
  88. // ResizeScreen works correctly
  89. // Refresh works correctly
  90. // IsDirty tests
  91. }