DimPosTests.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.IO;
  5. using System.Linq;
  6. using Terminal.Gui;
  7. using Xunit;
  8. // Alais Console to MockConsole so we don't accidentally use Console
  9. using Console = Terminal.Gui.MockConsole;
  10. namespace Terminal.Gui {
  11. public class DimPosTests {
  12. [Fact]
  13. public void TestNew ()
  14. {
  15. var pos = new Pos ();
  16. Assert.Equal ("Terminal.Gui.Pos", pos.ToString ());
  17. }
  18. [Fact]
  19. public void TestAnchorEnd ()
  20. {
  21. var pos = Pos.AnchorEnd ();
  22. Assert.Equal ("Pos.AnchorEnd(margin=0)", pos.ToString ());
  23. pos = Pos.AnchorEnd (5);
  24. Assert.Equal ("Pos.AnchorEnd(margin=5)", pos.ToString ());
  25. }
  26. [Fact]
  27. public void TestAt ()
  28. {
  29. var pos = Pos.At (0);
  30. Assert.Equal ("Pos.Absolute(0)", pos.ToString ());
  31. pos = Pos.At (5);
  32. Assert.Equal ("Pos.Absolute(5)", pos.ToString ());
  33. //Assert.Throws<ArgumentException> (() => pos = Pos.At (-1));
  34. }
  35. [Fact]
  36. public void TestLeft ()
  37. {
  38. var pos = Pos.Left (null);
  39. Assert.Throws<NullReferenceException> (() => pos.ToString ());
  40. pos = Pos.Left (new View ());
  41. Assert.Equal ("Pos.View(side=x, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ());
  42. pos = Pos.Left (new View (new Rect (1, 2, 3, 4)));
  43. Assert.Equal ("Pos.View(side=x, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ());
  44. }
  45. [Fact]
  46. public void TestTop ()
  47. {
  48. var pos = Pos.Top (null);
  49. Assert.Throws<NullReferenceException> (() => pos.ToString ());
  50. pos = Pos.Top (new View ());
  51. Assert.Equal ("Pos.View(side=y, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ());
  52. pos = Pos.Top (new View (new Rect (1, 2, 3, 4)));
  53. Assert.Equal ("Pos.View(side=y, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ());
  54. }
  55. [Fact]
  56. public void TestRight ()
  57. {
  58. var pos = Pos.Right (null);
  59. Assert.Throws<NullReferenceException> (() => pos.ToString ());
  60. pos = Pos.Right (new View ());
  61. Assert.Equal ("Pos.View(side=right, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ());
  62. pos = Pos.Right (new View (new Rect (1, 2, 3, 4)));
  63. Assert.Equal ("Pos.View(side=right, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ());
  64. }
  65. [Fact]
  66. public void TestBottom ()
  67. {
  68. var pos = Pos.Bottom (null);
  69. Assert.Throws<NullReferenceException> (() => pos.ToString ());
  70. pos = Pos.Bottom (new View ());
  71. Assert.Equal ("Pos.View(side=bottom, target=View()({X=0,Y=0,Width=0,Height=0})", pos.ToString ());
  72. pos = Pos.Bottom (new View (new Rect (1, 2, 3, 4)));
  73. Assert.Equal ("Pos.View(side=bottom, target=View()({X=1,Y=2,Width=3,Height=4})", pos.ToString ());
  74. //Assert.Throws<ArgumentException> (() => pos = Pos.Bottom (new View (new Rect (0, 0, -3, -4))));
  75. }
  76. [Fact]
  77. public void TestCenter ()
  78. {
  79. var pos = Pos.Center ();
  80. Assert.Equal ("Pos.Center", pos.ToString ());
  81. }
  82. [Fact]
  83. public void TestPercent ()
  84. {
  85. System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo ("en-US");
  86. var pos = Pos.Percent (0);
  87. Assert.Equal ("Pos.Factor(0)", pos.ToString ());
  88. pos = Pos.Percent (0.5F);
  89. Assert.Equal ("Pos.Factor(0.005)", pos.ToString ());
  90. pos = Pos.Percent (100);
  91. Assert.Equal ("Pos.Factor(1)", pos.ToString ());
  92. Assert.Throws<ArgumentException> (() => pos = Pos.Percent (-1));
  93. Assert.Throws<ArgumentException> (() => pos = Pos.Percent (101));
  94. Assert.Throws<ArgumentException> (() => pos = Pos.Percent (100.0001F));
  95. Assert.Throws<ArgumentException> (() => pos = Pos.Percent (1000001));
  96. }
  97. // TODO: Test operators
  98. // TODO: Test Dim
  99. }
  100. }