GridLengthTests.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using System.Globalization;
  5. using System.Linq;
  6. using Xunit;
  7. namespace Avalonia.Controls.UnitTests
  8. {
  9. public class GridLengthTests
  10. {
  11. [Fact]
  12. public void Parse_Should_Parse_Auto()
  13. {
  14. var result = GridLength.Parse("Auto");
  15. Assert.Equal(GridLength.Auto, result);
  16. }
  17. [Fact]
  18. public void Parse_Should_Parse_Auto_Lowercase()
  19. {
  20. var result = GridLength.Parse("auto");
  21. Assert.Equal(GridLength.Auto, result);
  22. }
  23. [Fact]
  24. public void Parse_Should_Parse_Star()
  25. {
  26. var result = GridLength.Parse("*");
  27. Assert.Equal(new GridLength(1, GridUnitType.Star), result);
  28. }
  29. [Fact]
  30. public void Parse_Should_Parse_Star_Value()
  31. {
  32. var result = GridLength.Parse("2*");
  33. Assert.Equal(new GridLength(2, GridUnitType.Star), result);
  34. }
  35. [Fact]
  36. public void Parse_Should_Parse_Pixel_Value()
  37. {
  38. var result = GridLength.Parse("2");
  39. Assert.Equal(new GridLength(2, GridUnitType.Pixel), result);
  40. }
  41. [Fact]
  42. public void Parse_Should_Throw_FormatException_For_Invalid_String()
  43. {
  44. Assert.Throws<FormatException>(() => GridLength.Parse("2x"));
  45. }
  46. [Fact]
  47. public void ParseLengths_Accepts_Comma_Separators()
  48. {
  49. var result = GridLength.ParseLengths("*,Auto,2*,4").ToList();
  50. Assert.Equal(
  51. new[]
  52. {
  53. new GridLength(1, GridUnitType.Star),
  54. GridLength.Auto,
  55. new GridLength(2, GridUnitType.Star),
  56. new GridLength(4, GridUnitType.Pixel),
  57. },
  58. result);
  59. }
  60. [Fact]
  61. public void ParseLengths_Accepts_Space_Separators()
  62. {
  63. var result = GridLength.ParseLengths("* Auto 2* 4").ToList();
  64. Assert.Equal(
  65. new[]
  66. {
  67. new GridLength(1, GridUnitType.Star),
  68. GridLength.Auto,
  69. new GridLength(2, GridUnitType.Star),
  70. new GridLength(4, GridUnitType.Pixel),
  71. },
  72. result);
  73. }
  74. [Fact]
  75. public void ParseLengths_Accepts_Comma_Separators_With_Spaces()
  76. {
  77. var result = GridLength.ParseLengths("*, Auto, 2* ,4").ToList();
  78. Assert.Equal(
  79. new[]
  80. {
  81. new GridLength(1, GridUnitType.Star),
  82. GridLength.Auto,
  83. new GridLength(2, GridUnitType.Star),
  84. new GridLength(4, GridUnitType.Pixel),
  85. },
  86. result);
  87. }
  88. }
  89. }