GridLengthsParserTests.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // -----------------------------------------------------------------------
  2. // <copyright file="GridLengthsParserTests.cs" company="Steven Kirk">
  3. // Copyright 2015 MIT Licence. See licence.md for more information.
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6. namespace Perspex.Controls.UnitTests.Parsers
  7. {
  8. using System;
  9. using System.Linq;
  10. using Perspex.Controls.Parsers;
  11. using Xunit;
  12. public class GridLengthsParserTests
  13. {
  14. [Fact]
  15. public void Parser_Should_Correctly_Parse_Grid_Lengths()
  16. {
  17. var s = "*,Auto,2*,4px";
  18. var result = GridLengthsParser.Parse(s);
  19. Assert.Equal(
  20. new[]
  21. {
  22. new GridLength(1, GridUnitType.Star),
  23. GridLength.Auto,
  24. new GridLength(2, GridUnitType.Star),
  25. new GridLength(4, GridUnitType.Pixel),
  26. },
  27. result);
  28. }
  29. [Fact]
  30. public void Parser_Should_Throw_For_Invalid_Star_Value()
  31. {
  32. var s = "*,Auto,x*,4px";
  33. Assert.Throws<FormatException>(() => GridLengthsParser.Parse(s).ToList());
  34. }
  35. [Fact]
  36. public void Parser_Should_Throw_For_Invalid_Unit_Value()
  37. {
  38. var s = "*,Auto,4ab,4px";
  39. Assert.Throws<FormatException>(() => GridLengthsParser.Parse(s).ToList());
  40. }
  41. [Fact]
  42. public void Parser_Should_Throw_For_Empty_Entry()
  43. {
  44. var s = "*,Auto,,4px";
  45. Assert.Throws<FormatException>(() => GridLengthsParser.Parse(s).ToList());
  46. }
  47. }
  48. }