From 909c54a093002475aa24fb3c2be9ed0cfa2902fb Mon Sep 17 00:00:00 2001 From: Davide Icardi Date: Sun, 11 Aug 2024 19:00:02 +0200 Subject: [PATCH 1/3] feat: .net 8 and github issue 311 --- .github/workflows/ci.yml | 24 ++++++++++++++----- .github/workflows/publish.yml | 14 +++++------ .../DynamicExpresso.UnitTest.csproj | 2 +- test/DynamicExpresso.UnitTest/GithubIssues.cs | 19 ++++++++++++++- .../MemberInvocationTest.cs | 2 +- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 34599c4..0f89696 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,19 +8,23 @@ on: jobs: test-linux: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: '0' # all - name: Setup .NET Core 3.1 - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: '3.1.x' - name: Setup .NET 7.0 - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: '7.0.x' + - name: Setup .NET 8.0 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' - name: Setup gitversion run: dotnet tool install --global GitVersion.Tool - name: Calculate version @@ -36,14 +40,20 @@ jobs: run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release --verbosity normal -f netcoreapp3.1 - name: Test .net core 7.0 run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release --verbosity normal -f net7.0 + - name: Test .net core 8.0 + run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release --verbosity normal -f net8.0 test-win: runs-on: windows-2019 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup .NET 7.0 - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: '7.0.x' + - name: Setup .NET 8.0 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' - name: Restore packages run: dotnet restore DynamicExpresso.sln - name: Build @@ -52,3 +62,5 @@ jobs: run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release --verbosity normal -f net461 - name: Test .net 4.5 run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release --verbosity normal -f net45 + - name: Test .net core 8.0 + run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release --verbosity normal -f net8.0 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 09e9c54..c717a9d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,16 +14,16 @@ on: default: 'true' jobs: publish-nuget: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: "${{ github.event.inputs.ref }}" fetch-depth: '0' # all - - name: Setup .NET Core 7.0 - uses: actions/setup-dotnet@v3 + - name: Setup .NET Core 8.0 + uses: actions/setup-dotnet@v4 with: - dotnet-version: '7.0.x' + dotnet-version: '8.0.x' - name: Setup gitversion run: dotnet tool install --global GitVersion.Tool - name: Calculate version @@ -37,8 +37,8 @@ jobs: run: dotnet build DynamicExpresso.sln --no-restore -c Release /p:Version=${{steps.calc_version.outputs.PROJECT_VERSION}} - name: Test .net core 3.1 run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release /p:Version=${{steps.calc_version.outputs.PROJECT_VERSION}} --verbosity normal -f netcoreapp3.1 - - name: Test .net core 7.0 - run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release /p:Version=${{steps.calc_version.outputs.PROJECT_VERSION}} --verbosity normal -f net7.0 + - name: Test .net core 8.0 + run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release /p:Version=${{steps.calc_version.outputs.PROJECT_VERSION}} --verbosity normal -f net8.0 - name: Setup nuget sources run: dotnet nuget add source --name github "https://nuget.pkg.github.com/dynamicexpresso/index.json" - name: Pack diff --git a/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj b/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj index 0a0e7ad..40e1290 100644 --- a/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj +++ b/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj @@ -1,7 +1,7 @@ - net7.0;net5.0;netcoreapp3.1;net462 + net8.0;net7.0;net5.0;netcoreapp3.1;net462 false diff --git a/test/DynamicExpresso.UnitTest/GithubIssues.cs b/test/DynamicExpresso.UnitTest/GithubIssues.cs index 010292e..0edcc81 100644 --- a/test/DynamicExpresso.UnitTest/GithubIssues.cs +++ b/test/DynamicExpresso.UnitTest/GithubIssues.cs @@ -254,7 +254,7 @@ static bool GetGFunction2(string arg) Assert.Throws(() => interpreter.Eval("GFunction(arg)")); // GFunction1 is used - // because gFunc1.Method.GetParameters()[0].HasDefaultValue == true + // because gFunc1.Method.GetParameters()[0].HasDefaultValue == true // and gFunc2.Method.GetParameters()[0].HasDefaultValue == false Assert.False((bool)interpreter.Eval("GFunction()")); } @@ -819,6 +819,23 @@ public void GitHub_Issue_305() } #endregion + + [Test] + public void GitHub_Issue_311() + { + var a = "AABB"; + + var interpreter1 = new Interpreter(); + interpreter1.SetVariable("a", a); + Assert.AreEqual("AA", interpreter1.Eval("a.Substring(0, 2)")); + + var interpreter2 = new Interpreter().SetDefaultNumberType(DefaultNumberType.Decimal); + interpreter2.SetVariable("a", a); + // expected to throw because Substring is not defined for decimal + Assert.Throws(() => interpreter2.Eval("a.Substring(0, 2)")); + // It works if we cast to int + Assert.AreEqual("AA", interpreter2.Eval("a.Substring((int)0, (int)2)")); + } } internal static class GithubIssuesTestExtensionsMethods diff --git a/test/DynamicExpresso.UnitTest/MemberInvocationTest.cs b/test/DynamicExpresso.UnitTest/MemberInvocationTest.cs index e42727a..56abe7a 100644 --- a/test/DynamicExpresso.UnitTest/MemberInvocationTest.cs +++ b/test/DynamicExpresso.UnitTest/MemberInvocationTest.cs @@ -108,7 +108,7 @@ public void Indexer_Getter_MultiDimensional() target.SetVariable("x", x); var y = new MyTestService(); target.SetVariable("y", y); - + Assert.AreEqual(x[1, 2], target.Eval("x[1, 2]")); Assert.AreEqual(y[y.Today, 2], target.Eval("y[y.Today, 2]")); Assert.AreEqual(y[y.Today], target.Eval("y[y.Today]")); From 3f0f0943ee0395907978c78e43e6ea6bcd6b35cd Mon Sep 17 00:00:00 2001 From: Davide Icardi Date: Sun, 11 Aug 2024 19:08:00 +0200 Subject: [PATCH 2/3] fix invariant globalization --- test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj b/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj index 40e1290..d19f8d4 100644 --- a/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj +++ b/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj @@ -4,6 +4,8 @@ net8.0;net7.0;net5.0;netcoreapp3.1;net462 false + + true From 20d5c5329258d65f1822638d4fdd6da7c6cf1580 Mon Sep 17 00:00:00 2001 From: Davide Icardi Date: Sun, 11 Aug 2024 19:12:52 +0200 Subject: [PATCH 3/3] fix --- .github/workflows/ci.yml | 12 ------------ .github/workflows/publish.yml | 2 -- .../DynamicExpresso.UnitTest.csproj | 4 +--- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f89696..4491657 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,14 +13,6 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: '0' # all - - name: Setup .NET Core 3.1 - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '3.1.x' - - name: Setup .NET 7.0 - uses: actions/setup-dotnet@v4 - with: - dotnet-version: '7.0.x' - name: Setup .NET 8.0 uses: actions/setup-dotnet@v4 with: @@ -36,10 +28,6 @@ jobs: run: dotnet restore DynamicExpresso.sln - name: Build run: dotnet build DynamicExpresso.sln --no-restore -c Release /p:Version=${{steps.calc_version.outputs.PROJECT_VERSION}} - - name: Test .net core 3.1 - run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release --verbosity normal -f netcoreapp3.1 - - name: Test .net core 7.0 - run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release --verbosity normal -f net7.0 - name: Test .net core 8.0 run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release --verbosity normal -f net8.0 test-win: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c717a9d..46bf8e7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -35,8 +35,6 @@ jobs: run: dotnet restore DynamicExpresso.sln - name: Build run: dotnet build DynamicExpresso.sln --no-restore -c Release /p:Version=${{steps.calc_version.outputs.PROJECT_VERSION}} - - name: Test .net core 3.1 - run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release /p:Version=${{steps.calc_version.outputs.PROJECT_VERSION}} --verbosity normal -f netcoreapp3.1 - name: Test .net core 8.0 run: dotnet test DynamicExpresso.sln --no-build --no-restore -c Release /p:Version=${{steps.calc_version.outputs.PROJECT_VERSION}} --verbosity normal -f net8.0 - name: Setup nuget sources diff --git a/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj b/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj index d19f8d4..3df1cae 100644 --- a/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj +++ b/test/DynamicExpresso.UnitTest/DynamicExpresso.UnitTest.csproj @@ -1,11 +1,9 @@ - net8.0;net7.0;net5.0;netcoreapp3.1;net462 + net8.0;net7.0;net5.0;net462 false - - true