Skip to content

Commit

Permalink
Merge pull request #1 from SebastianWachsmuth/Fix/InvariantToString
Browse files Browse the repository at this point in the history
add FormattableString.Invariant to ICommand.ToString()
  • Loading branch information
zHaytam authored Sep 6, 2022
2 parents 4d0a975 + 27641d2 commit e1b84f3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
35 changes: 35 additions & 0 deletions SvgPathProperties.UnitTests/ToStringTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Globalization;

using Xunit;

namespace SvgPathProperties.UnitTests
{
public class ToStringTests
{
[Theory]
//with . separator
[InlineData("en-US", 0, 1.5, 0, 1.5, "L 1.5 1.5")]

[InlineData("en-US", 0, 1_000_000.5, 0, 1.5, "L 1000000.5 1.5")]
//with , separator
[InlineData("de-DE", 0, 1.5, 0, 1.5, "L 1.5 1.5")]
[InlineData("it-IT", 0, 1.5, 0, 1.5, "L 1.5 1.5")]
[InlineData("es-ES", 0, 1.5, 0, 1.5, "L 1.5 1.5")]
[InlineData("nl-BE", 0, 1.5, 0, 1.5, "L 1.5 1.5")]

[InlineData("de-DE", 0, 1_000_000.5, 0, 1_000_000.5, "L 1000000.5 1000000.5")]
[InlineData("it-IT", 0, 1_000_000.5, 0, 1_000_000.5, "L 1000000.5 1000000.5")]
[InlineData("es-ES", 0, 1_000_000.5, 0, 1_000_000.5, "L 1000000.5 1000000.5")]
[InlineData("nl-BE", 0, 1_000_000.5, 0, 1_000_000.5, "L 1000000.5 1000000.5")]
// with / separator
[InlineData("fa-IR", 0, 1.5, 0, 1.5, "L 1.5 1.5")]
[InlineData("fa-IR", 0, 1_000_000.5, 0, 1_000_000.5, "L 1000000.5 1000000.5")]
public void CuluresWithPointSeparator(string cultureCode, double fromX, double toX, double fromY, double toY, string result)
{
var command = new LineCommand(fromX, toX, fromY, toY);
CultureInfo.CurrentCulture = new CultureInfo(cultureCode); ;

Assert.Equal(result, command.ToString());
}
}
}
3 changes: 2 additions & 1 deletion SvgPathProperties/ArcCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SvgPathProperties.Base;

using System;

namespace SvgPathProperties
Expand Down Expand Up @@ -267,7 +268,7 @@ private static double ApproximateArcLengthOfCurve(double? resolution, Func<doubl

public override string ToString()
{
return $"A {Rx} {Ry} {XAxisRotate} {Convert.ToInt32(LargeArcFlag)} {Convert.ToInt32(SweepFlag)} {ToX} {ToY}";
return FormattableString.Invariant($"A {Rx} {Ry} {XAxisRotate} {Convert.ToInt32(LargeArcFlag)} {Convert.ToInt32(SweepFlag)} {ToX} {ToY}");
}
}
}
5 changes: 3 additions & 2 deletions SvgPathProperties/BezierCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SvgPathProperties.Base;

using System;

namespace SvgPathProperties
Expand Down Expand Up @@ -153,11 +154,11 @@ public override string ToString()
{
if (IsQuadratic)
{
return $"Q {Cp1.X} {Cp1.Y} {Cp2OrEnd.X} {Cp2OrEnd.Y}";
return FormattableString.Invariant($"Q {Cp1.X} {Cp1.Y} {Cp2OrEnd.X} {Cp2OrEnd.Y}");
}
else
{
return $"C {Cp1.X} {Cp1.Y} {Cp2OrEnd.X} {Cp2OrEnd.Y} {End.X} {End.Y}";
return FormattableString.Invariant($"C {Cp1.X} {Cp1.Y} {Cp2OrEnd.X} {Cp2OrEnd.Y} {End.X} {End.Y}");
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion SvgPathProperties/LineCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SvgPathProperties.Base;

using System;

namespace SvgPathProperties
Expand Down Expand Up @@ -55,7 +56,7 @@ public Point GetTangentAtLength(double pos)

public override string ToString()
{
return ClosePath ? "Z" : $"L {ToX} {ToY}";
return ClosePath ? "Z" : FormattableString.Invariant($"L {ToX} {ToY}");
}
}
}
4 changes: 3 additions & 1 deletion SvgPathProperties/MoveCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using SvgPathProperties.Base;

using System;

namespace SvgPathProperties
{
public class MoveCommand : ICommand
Expand Down Expand Up @@ -33,7 +35,7 @@ public PointProperties GetPropertiesAtLength(double pos)

public override string ToString()
{
return $"M {X} {Y}";
return FormattableString.Invariant($"M {X} {Y}");
}
}
}

0 comments on commit e1b84f3

Please sign in to comment.