From eec5d00c2cfe764aab17d5a11c0b8851513bc573 Mon Sep 17 00:00:00 2001 From: danwale Date: Mon, 28 Mar 2022 14:18:15 +0800 Subject: [PATCH 1/3] Added in tolong function and unit tests, can now handle numbers greater than Int32.MaxValue which previously returned 0. --- JUST.net/Transformer.cs | 5 +++++ UnitTests/TypeConversionTests.cs | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/JUST.net/Transformer.cs b/JUST.net/Transformer.cs index 440aa23..07d8a2b 100644 --- a/JUST.net/Transformer.cs +++ b/JUST.net/Transformer.cs @@ -712,6 +712,11 @@ public static object tointeger(object val, JUSTContext context) return ReflectionHelper.GetTypedValue(typeof(int), val, context.EvaluationMode); } + public static object tolong(object val, JUSTContext context) + { + return ReflectionHelper.GetTypedValue(typeof(long), val, context.EvaluationMode); + } + public static object tostring(object val, JUSTContext context) { return ReflectionHelper.GetTypedValue(typeof(string), val, context.EvaluationMode); diff --git a/UnitTests/TypeConversionTests.cs b/UnitTests/TypeConversionTests.cs index 5a83fd5..91b4712 100644 --- a/UnitTests/TypeConversionTests.cs +++ b/UnitTests/TypeConversionTests.cs @@ -58,6 +58,23 @@ public void ToIntegerConvertion(string typedValue, string expectedResult) Assert.AreEqual($"{{\"result\":{expectedResult}}}", result); } + [TestCase("\"12345678901\"", "12345678901")] + [TestCase("\"-12345678901\"", "-12345678901")] + [TestCase("\"0\"", "0")] + [TestCase("12345678901.23", "12345678901")] + [TestCase("-12345678901.56", "-12345678902")] + [TestCase("true", "1")] + [TestCase("false", "0")] + public void ToLongConversion(string typedValue, string expectedResult) + { + var input = $"{{ \"value\": {typedValue} }}"; + const string transformer = "{ \"result\": \"#tolong(#valueof($.value))\" }"; + + var result = new JsonTransformer().Transform(transformer, input); + + Assert.AreEqual($"{{\"result\":{expectedResult}}}", result); + } + [TestCase("\"0\"", "0.0")] [TestCase("\"1.01\"", "1.01")] [TestCase("123", "123.0")] From 48a1a1297f24c7f61a17925b52d4a4724a0e410f Mon Sep 17 00:00:00 2001 From: danwale Date: Mon, 28 Mar 2022 14:20:32 +0800 Subject: [PATCH 2/3] Corrected the TargetFramework to be net6.0, there is no net6.0-windows8.0 framework. --- ExternalMethods/ExternalMethods.csproj | 2 +- JUST.net/JUST.net.csproj | 2 +- UnitTests/JUST.net.UnitTests.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ExternalMethods/ExternalMethods.csproj b/ExternalMethods/ExternalMethods.csproj index 767f7fe..521cc26 100644 --- a/ExternalMethods/ExternalMethods.csproj +++ b/ExternalMethods/ExternalMethods.csproj @@ -1,7 +1,7 @@ - net6.0-windows8.0 + net6.0 diff --git a/JUST.net/JUST.net.csproj b/JUST.net/JUST.net.csproj index efed904..51013eb 100644 --- a/JUST.net/JUST.net.csproj +++ b/JUST.net/JUST.net.csproj @@ -2,7 +2,7 @@ JUST - JSON Under Simple Transformation - net6.0-windows8.0 + net6.0 This a cool .NET Standard library which enables you to transform a JSON document into another JSON document using JSON transformations using JSON path. This is the JSON equivalent of XSLT. This will repace the JUST and JUST.NETCore packages. This is the JSON equivalent of XSLT diff --git a/UnitTests/JUST.net.UnitTests.csproj b/UnitTests/JUST.net.UnitTests.csproj index 0d9320e..f454097 100644 --- a/UnitTests/JUST.net.UnitTests.csproj +++ b/UnitTests/JUST.net.UnitTests.csproj @@ -1,7 +1,7 @@ - net6.0-windows8.0 + net6.0 false From 56d30e9c962b910c87eab2e95922bdf17498c879 Mon Sep 17 00:00:00 2001 From: danwale Date: Mon, 28 Mar 2022 15:07:48 +0800 Subject: [PATCH 3/3] Corrected to netstandard2.0 target framework and left the unit tests as .NET 6.0 so that the library can be used with non .NET core projects. --- ExternalMethods/ExternalMethods.csproj | 2 +- JUST.net/JUST.net.csproj | 2 +- JUST.net/Properties/PublishProfiles/FolderProfile.pubxml | 2 +- .../UnitTestForExternalAssemblyBug.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ExternalMethods/ExternalMethods.csproj b/ExternalMethods/ExternalMethods.csproj index 521cc26..7977d1b 100644 --- a/ExternalMethods/ExternalMethods.csproj +++ b/ExternalMethods/ExternalMethods.csproj @@ -1,7 +1,7 @@ - net6.0 + netstandard2.0 diff --git a/JUST.net/JUST.net.csproj b/JUST.net/JUST.net.csproj index 51013eb..684cc47 100644 --- a/JUST.net/JUST.net.csproj +++ b/JUST.net/JUST.net.csproj @@ -2,7 +2,7 @@ JUST - JSON Under Simple Transformation - net6.0 + netstandard2.0 This a cool .NET Standard library which enables you to transform a JSON document into another JSON document using JSON transformations using JSON path. This is the JSON equivalent of XSLT. This will repace the JUST and JUST.NETCore packages. This is the JSON equivalent of XSLT diff --git a/JUST.net/Properties/PublishProfiles/FolderProfile.pubxml b/JUST.net/Properties/PublishProfiles/FolderProfile.pubxml index 5672e42..296ffbd 100644 --- a/JUST.net/Properties/PublishProfiles/FolderProfile.pubxml +++ b/JUST.net/Properties/PublishProfiles/FolderProfile.pubxml @@ -7,7 +7,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt FileSystem Release - netstandard1.6 + netstandard2.0 bin\Release\PublishOutput \ No newline at end of file diff --git a/UnitTestForExternalAssemblyBug/UnitTestForExternalAssemblyBug.csproj b/UnitTestForExternalAssemblyBug/UnitTestForExternalAssemblyBug.csproj index 4a22afc..d255ec2 100644 --- a/UnitTestForExternalAssemblyBug/UnitTestForExternalAssemblyBug.csproj +++ b/UnitTestForExternalAssemblyBug/UnitTestForExternalAssemblyBug.csproj @@ -1,7 +1,7 @@ - net6.0-windows8.0 + net6.0 false