diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0330d4e5..48139aee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,9 +60,9 @@ jobs: uses: actions/setup-dotnet@v1 with: dotnet-version: 3.1.x - - uses: actions/setup-java@v1 + - uses: actions/setup-java@v4 with: - java-version: '13' # The JDK version to make available on the path. + java-version: '17' # The JDK version to make available on the path. - name: Clean package cache as a temporary workaround for https://github.com/actions/setup-dotnet/issues/155 working-directory: ./source run: dotnet clean -c Release && dotnet nuget locals all --clear diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index fae4b16c..97d02eb2 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -62,7 +62,7 @@ jobs: dotnet-version: 3.1.x - uses: actions/setup-java@v1 with: - java-version: '13' # The JDK version to make available on the path. + java-version: '17' # The JDK version to make available on the path. - name: Clean package cache as a temporary workaround for https://github.com/actions/setup-dotnet/issues/155 working-directory: ./source run: dotnet clean -c Release && dotnet nuget locals all --clear diff --git a/source/Handlebars.Test/NumericLiteralTests.cs b/source/Handlebars.Test/NumericLiteralTests.cs index c9ab1683..552de90f 100644 --- a/source/Handlebars.Test/NumericLiteralTests.cs +++ b/source/Handlebars.Test/NumericLiteralTests.cs @@ -1,6 +1,4 @@ -using System; -using System.Linq; -using HandlebarsDotNet.Compiler; +using System.Linq; using Xunit; namespace HandlebarsDotNet.Test @@ -14,10 +12,37 @@ public NumericLiteralTests() var arr = args.AsEnumerable().Select(a => (object)int.Parse(a.ToString())); writer.Write(arr.Aggregate(0, (a, i) => a + (int)i)); }); + + Handlebars.RegisterHelper("longAdd", (writer, context, args) => + { + var arr = args.AsEnumerable().Select(a => long.Parse(a.ToString())); + var sum = arr.Sum(); + writer.Write(sum); + }); + } + + [Theory] + [InlineData("{{longAdd 1000000000 9999999999}}")] + [InlineData("{{longAdd 1000000000 9999999999}}")] + [InlineData("{{longAdd 1000000000 9999999999 }}")] + [InlineData("{{longAdd 1000000000 9999999999}}")] + [InlineData("{{longAdd 1000000000 9999999999}}")] + [InlineData("{{longAdd 1000000000 \"9999999999\"}}")] + [InlineData("{{longAdd 1000000000 \"9999999999\" }}")] + [InlineData("{{longAdd 1000000000 \"9999999999\"}}")] + [InlineData("{{longAdd 1000000000 \"9999999999\" }}")] + [InlineData("{{longAdd \"1000000000\" 9999999999}}")] + [InlineData("{{longAdd \"1000000000\" \"9999999999\"}}")] + public void NumericLiteralLongTests(string source) + { + var template = Handlebars.Compile(source); + var data = new { }; + var result = template(data); + Assert.Equal("10999999999", result); } [Fact] - public void NumericLiteralTest1() + public void NumericLiteralIntegerTest1() { var source = "{{numericLiteralAdd 3 4}}"; var template = Handlebars.Compile(source); @@ -27,7 +52,7 @@ public void NumericLiteralTest1() } [Fact] - public void NumericLiteralTest2() + public void NumericLiteralIntegerTest2() { var source = "{{numericLiteralAdd 3 4}}"; var template = Handlebars.Compile(source); @@ -37,7 +62,7 @@ public void NumericLiteralTest2() } [Fact] - public void NumericLiteralTest3() + public void NumericLiteralIntegerTest3() { var source = "{{numericLiteralAdd 3 4 }}"; var template = Handlebars.Compile(source); @@ -47,7 +72,7 @@ public void NumericLiteralTest3() } [Fact] - public void NumericLiteralTest4() + public void NumericLiteralIntegerTest4() { var source = "{{numericLiteralAdd 3 4 }}"; var template = Handlebars.Compile(source); @@ -57,7 +82,7 @@ public void NumericLiteralTest4() } [Fact] - public void NumericLiteralTest5() + public void NumericLiteralIntegerTest5() { var source = "{{numericLiteralAdd 3 4 }}"; var template = Handlebars.Compile(source); @@ -67,7 +92,7 @@ public void NumericLiteralTest5() } [Fact] - public void NumericLiteralTest6() + public void NumericLiteralIntegerTest6() { var source = "{{numericLiteralAdd 3 \"4\"}}"; var template = Handlebars.Compile(source); @@ -77,7 +102,7 @@ public void NumericLiteralTest6() } [Fact] - public void NumericLiteralTest7() + public void NumericLiteralIntegerTest7() { var source = "{{numericLiteralAdd 3 \"4\" }}"; var template = Handlebars.Compile(source); @@ -87,7 +112,7 @@ public void NumericLiteralTest7() } [Fact] - public void NumericLiteralTest8() + public void NumericLiteralIntegerTest8() { var source = "{{numericLiteralAdd 3 \"4\" }}"; var template = Handlebars.Compile(source); @@ -97,7 +122,7 @@ public void NumericLiteralTest8() } [Fact] - public void NumericLiteralTest9() + public void NumericLiteralIntegerTest9() { var source = "{{numericLiteralAdd 3 \"4\" }}"; var template = Handlebars.Compile(source); @@ -107,7 +132,7 @@ public void NumericLiteralTest9() } [Fact] - public void NumericLiteralTest10() + public void NumericLiteralIntegerTest10() { var source = "{{numericLiteralAdd \"3\" 4}}"; var template = Handlebars.Compile(source); @@ -117,7 +142,7 @@ public void NumericLiteralTest10() } [Fact] - public void NumericLiteralTest11() + public void NumericLiteralIntegerTest11() { var source = "{{numericLiteralAdd \"3\" 4 }}"; var template = Handlebars.Compile(source); @@ -126,5 +151,4 @@ public void NumericLiteralTest11() Assert.Equal("7", result); } } -} - +} \ No newline at end of file diff --git a/source/Handlebars.sln b/source/Handlebars.sln index adaa5299..fa8e7177 100644 --- a/source/Handlebars.sln +++ b/source/Handlebars.sln @@ -9,11 +9,19 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E9AC0BCD-C060-4634-BBBB-636167C809B4}" ProjectSection(SolutionItems) = preProject Directory.Build.props = Directory.Build.props + ..\.github\workflows\pull_request.yml = ..\.github\workflows\pull_request.yml ..\README.md = ..\README.md EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Handlebars.Benchmark", "Handlebars.Benchmark\Handlebars.Benchmark.csproj", "{417E2E51-2DD2-4045-84E5-BA66484E957B}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Github Actions", "Github Actions", "{0683EE49-625C-473D-B600-079FDB9AF55B}" + ProjectSection(SolutionItems) = preProject + ..\.github\workflows\ci.yml = ..\.github\workflows\ci.yml + ..\.github\workflows\pull_request.yml = ..\.github\workflows\pull_request.yml + ..\.github\workflows\release.yml = ..\.github\workflows\release.yml + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/source/Handlebars/Compiler/Lexer/Converter/LiteralConverter.cs b/source/Handlebars/Compiler/Lexer/Converter/LiteralConverter.cs index 8c81689f..6bf092f1 100644 --- a/source/Handlebars/Compiler/Lexer/Converter/LiteralConverter.cs +++ b/source/Handlebars/Compiler/Lexer/Converter/LiteralConverter.cs @@ -1,15 +1,14 @@ -using System; using System.Collections.Generic; -using HandlebarsDotNet.Compiler.Lexer; -using System.Linq.Expressions; using System.Linq; +using System.Linq.Expressions; +using HandlebarsDotNet.Compiler.Lexer; namespace HandlebarsDotNet.Compiler { internal class LiteralConverter : TokenConverter { private static readonly LiteralConverter Converter = new LiteralConverter(); - + public static IEnumerable Convert(IEnumerable sequence) { return Converter.ConvertTokens(sequence).ToList(); @@ -28,15 +27,22 @@ public override IEnumerable ConvertTokens(IEnumerable sequence) switch (item) { case LiteralExpressionToken literalExpression: - { - result = Expression.Convert(Expression.Constant(literalExpression.Value), typeof(object)); - if (!literalExpression.IsDelimitedLiteral && int.TryParse(literalExpression.Value, out var intValue)) { - result = Expression.Convert(Expression.Constant(intValue), typeof(object)); + result = Expression.Convert(Expression.Constant(literalExpression.Value), typeof(object)); + if (!literalExpression.IsDelimitedLiteral) + { + if (int.TryParse(literalExpression.Value, out var intValue)) + { + result = Expression.Convert(Expression.Constant(intValue), typeof(object)); + } + else if (long.TryParse(literalExpression.Value, out var longValue)) + { + result = Expression.Convert(Expression.Constant(longValue), typeof(object)); + } + } + + break; } - - break; - } case WordExpressionToken wordExpression when bool.TryParse(wordExpression.Value, out var boolValue): result = Expression.Convert(Expression.Constant(boolValue), typeof(object)); @@ -47,5 +53,4 @@ public override IEnumerable ConvertTokens(IEnumerable sequence) } } } -} - +} \ No newline at end of file