PathMarkupParserTests.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 Avalonia.Media;
  4. using Avalonia.Platform;
  5. using Moq;
  6. using Xunit;
  7. namespace Avalonia.Visuals.UnitTests.Media
  8. {
  9. public class PathMarkupParserTests
  10. {
  11. [Fact]
  12. public void Parses_Move()
  13. {
  14. using (AvaloniaLocator.EnterScope())
  15. {
  16. var result = new Mock<IStreamGeometryContextImpl>();
  17. var parser = PrepareParser(result);
  18. parser.Parse("M10 10");
  19. result.Verify(x => x.BeginFigure(new Point(10, 10), true));
  20. }
  21. }
  22. [Fact]
  23. public void Parses_Line()
  24. {
  25. using (AvaloniaLocator.EnterScope())
  26. {
  27. var result = new Mock<IStreamGeometryContextImpl>();
  28. var parser = PrepareParser(result);
  29. parser.Parse("M0 0L10 10");
  30. result.Verify(x => x.LineTo(new Point(10, 10)));
  31. }
  32. }
  33. [Fact]
  34. public void Parses_Close()
  35. {
  36. using (AvaloniaLocator.EnterScope())
  37. {
  38. var result = new Mock<IStreamGeometryContextImpl>();
  39. var parser = PrepareParser(result);
  40. parser.Parse("M0 0L10 10z");
  41. result.Verify(x => x.EndFigure(true));
  42. }
  43. }
  44. [Theory]
  45. [InlineData("F1 M24,14 A2,2,0,1,1,20,14 A2,2,0,1,1,24,14 z")] // issue #1107
  46. [InlineData("M0 0L10 10z")]
  47. [InlineData("M50 50 L100 100 L150 50")]
  48. [InlineData("M50 50L100 100L150 50")]
  49. [InlineData("M50,50 L100,100 L150,50")]
  50. [InlineData("M50 50 L-10 -10 L10 50")]
  51. [InlineData("M50 50L-10-10L10 50")]
  52. [InlineData("M50 50 L100 100 L150 50zM50 50 L70 70 L120 50z")]
  53. [InlineData("M 50 50 L 100 100 L 150 50")]
  54. [InlineData("M50 50 L100 100 L150 50 H200 V100Z")]
  55. [InlineData("M 80 200 A 100 50 45 1 0 100 50")]
  56. [InlineData(
  57. "F1 M 16.6309 18.6563C 17.1309 8.15625 29.8809 14.1563 29.8809 14.1563C 30.8809 11.1563 34.1308 11.4063" +
  58. " 34.1308 11.4063C 33.5 12 34.6309 13.1563 34.6309 13.1563C 32.1309 13.1562 31.1309 14.9062 31.1309 14.9" +
  59. "062C 41.1309 23.9062 32.6309 27.9063 32.6309 27.9062C 24.6309 24.9063 21.1309 22.1562 16.6309 18.6563 Z" +
  60. " M 16.6309 19.9063C 21.6309 24.1563 25.1309 26.1562 31.6309 28.6562C 31.6309 28.6562 26.3809 39.1562 18" +
  61. ".3809 36.1563C 18.3809 36.1563 18 38 16.3809 36.9063C 15 36 16.3809 34.9063 16.3809 34.9063C 16.3809 34" +
  62. ".9063 10.1309 30.9062 16.6309 19.9063 Z ")]
  63. [InlineData(
  64. "F1M16,12C16,14.209 14.209,16 12,16 9.791,16 8,14.209 8,12 8,11.817 8.03,11.644 8.054,11.467L6.585,10 4,10 " +
  65. "4,6.414 2.5,7.914 0,5.414 0,3.586 3.586,0 4.414,0 7.414,3 7.586,3 9,1.586 11.914,4.5 10.414,6 " +
  66. "12.461,8.046C14.45,8.278,16,9.949,16,12")]
  67. public void Should_Parse(string pathData)
  68. {
  69. using (AvaloniaLocator.EnterScope())
  70. {
  71. var parser = PrepareParser();
  72. parser.Parse(pathData);
  73. Assert.True(true);
  74. }
  75. }
  76. private static PathMarkupParser PrepareParser(Mock<IStreamGeometryContextImpl> implMock = null)
  77. {
  78. AvaloniaLocator.CurrentMutable
  79. .Bind<IPlatformRenderInterface>()
  80. .ToConstant(Mock.Of<IPlatformRenderInterface>());
  81. return new PathMarkupParser(
  82. new StreamGeometryContext(implMock != null ? implMock.Object : Mock.Of<IStreamGeometryContextImpl>()));
  83. }
  84. }
  85. }