Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
# Build script for dotliquid is presently stored securely on AppVeyor.
# Below is ignored and kept for informational purposes only
version: 2.2.{build}
version: 2.4.{build}
image: Visual Studio 2022
configuration: Release
assembly_info:
dotnet_csproj:
patch: true
file: AssemblyInfo.*
file: '**\*.csproj'
version: '{version}'
version_prefix: '{version}'
package_version: '{version}'
assembly_version: '{version}'
assembly_file_version: '{version}'
assembly_informational_version: '{version}-$(APPVEYOR_REPO_COMMIT)'
file_version: '{version}'
informational_version: '{version}-$(APPVEYOR_REPO_COMMIT)'
install:
- cmd: >-
choco install opencover.portable -y

choco install codecov -y

choco install dotnetcore-runtime.install --version=1.1.13 --allow-downgrade -y
dotnet --list-runtimes | find "Microsoft.NETCore.App 3.1" >nul

choco install dotnetcore-runtime.install --version=2.1.30 -y
if %errorlevel% neq 0 ( choco install dotnetcore-runtime.install --version=3.1.32 -y )

dotnet restore src/DotLiquid.sln
cache:
Expand All @@ -32,7 +35,7 @@ after_build:
- ps: >-
New-Item -Path build\pkg -ItemType Directory

nuget pack src/DotLiquid/DotLiquid.nuspec -Symbols -SymbolPackageFormat snupkg -Version "$($env:APPVEYOR_BUILD_VERSION)" -OutputDirectory build\pkg
dotnet pack src\DotLiquid\DotLiquid.csproj --configuration Release --include-symbols -p:SymbolPackageFormat=snupkg --output build\pkg --no-build
test_script:
- cmd: >-
opencover.console -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:"test src\DotLiquid.Tests\DotLiquid.Tests.csproj /clp:ErrorsOnly" -output:TestsCoverage.xml -filter:"+[DotLiquid]*" -register:user -returntargetcode -oldstyle
Expand Down
1 change: 1 addition & 0 deletions src/DotLiquid.Tests/BlockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void TestWithBlock()
public void TestWithCustomTag()
{
Template.RegisterTag<Block>("testtag");
Assert.That(Template.GetTagType("testtag"), Is.EqualTo(typeof(Block)));
Assert.DoesNotThrow(() => Template.Parse("{% testtag %} {% endtesttag %}"));
}

Expand Down
1 change: 0 additions & 1 deletion src/DotLiquid.Tests/ConditionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ public void TestExpandoHasValue()
testDictionary.type = "cleaning";
_context["dictionary"] = testDictionary;


AssertEvaluatesTrue("dictionary", "hasvalue", "'Vacuum'");
AssertEvaluatesFalse("dictionary", "hasvalue", "'title'");
}
Expand Down
52 changes: 43 additions & 9 deletions src/DotLiquid.Tests/ContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Dynamic;
using System.Globalization;
using System.Linq;
using System.Threading;
using DotLiquid.Exceptions;
using Newtonsoft.Json;
using NUnit.Framework;
Expand Down Expand Up @@ -236,15 +237,15 @@ public void TestVariables()
[Test]
public void TestVariablesArray()
{
List<int> list = new List<int> { 1, 2, 3, 4, 5 };
var list = new List<int> { 1, 2, 3, 4, 5 };
_context["list"] = list;
Assert.That(_context["list"], Is.EqualTo(list));
Assert.That(_context["list[0]"], Is.EqualTo(1));
Assert.That(_context["list[-1]"], Is.EqualTo(5));
Assert.That(_context["list[12]"], Is.Null);
Assert.That(_context["list[-12]"], Is.Null);

List<string> emptyList = new List<string>();
var emptyList = new List<string>();
_context["empty_list"] = emptyList;
Assert.That(_context["empty_list"], Is.EqualTo(emptyList));
Assert.That(_context["empty_list[0]"], Is.Null);
Expand Down Expand Up @@ -394,12 +395,19 @@ public void TestAddFilter()
Context context = new Context(CultureInfo.InvariantCulture);
context.AddFilters(new[] { typeof(TestFilters) });
Assert.That(context.Invoke("hi", new List<object> { "hi?" }), Is.EqualTo("hi? hi!"));
context.SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid22;
Assert.That(context.Invoke("hi", new List<object> { "hi?" }), Is.EqualTo("hi? hi!"));


context = new Context(CultureInfo.InvariantCulture);
Assert.That(context.Invoke("hi", new List<object> { "hi?" }), Is.EqualTo("hi?"));
context.SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid22;
}

[Test]
public void TestAddFilter_NotFoundException()
{
var context = new Context(CultureInfo.InvariantCulture) { SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid22 };
context.AddFilters(new[] { typeof(TestFilters) });
Assert.That(context.Invoke("hi", new List<object> { "hi?" }), Is.EqualTo("hi? hi!"));

context = new Context(CultureInfo.InvariantCulture) { SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid22 };
Assert.Throws<FilterNotFoundException>(() => context.Invoke("hi", new List<object> { "hi?" }));
}

Expand All @@ -412,15 +420,32 @@ public void TestAddContextFilter()

context.AddFilters(new[] { typeof(TestContextFilters) });
Assert.That(context.Invoke("hi", new List<object> { "hi?" }), Is.EqualTo("hi? hi from King Kong!"));
context.SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid22;
Assert.That(context.Invoke("hi", new List<object> { "hi?" }), Is.EqualTo("hi? hi from King Kong!"));

context = new Context(CultureInfo.InvariantCulture) { SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid20 };
Assert.That(context.Invoke("hi", new List<object> { "hi?" }), Is.EqualTo("hi?"));
context.SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid22;
}

[Test]
public void TestAddContextFilter_NotFoundException()
{
// This test differs from TestAddFilter only in that the Hi method within this class has a Context parameter in addition to the input string
Context context = new Context(CultureInfo.InvariantCulture) { SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid22 };
context["name"] = "King Kong";
context.AddFilters(new[] { typeof(TestContextFilters) });
Assert.That(context.Invoke("hi", new List<object> { "hi?" }), Is.EqualTo("hi? hi from King Kong!"));

context = new Context(CultureInfo.InvariantCulture) { SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid22 };
Assert.Throws<FilterNotFoundException>(() => context.Invoke("hi", new List<object> { "hi?" }));
}

[Test]
public void TestSyntaxCompatibilityReadonly()
{
Context context = new Context(CultureInfo.InvariantCulture) { SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid20 };
context.AddFilters(new[] { typeof(TestFilters) });
Assert.Throws<ContextException>(() => context.SyntaxCompatibilityLevel = SyntaxCompatibility.DotLiquid22);
}

[Test]
public void TestOverrideGlobalFilter()
{
Expand Down Expand Up @@ -1063,6 +1088,15 @@ public void TestConstructor()
Assert.That(context.CurrentCulture.Name, Is.EqualTo("jp-JP"));
}

//
[Test]
public void TestConstructorNullHandling()
{
Assert.Throws<ArgumentNullException>(() => {
_ = new Context(environments: null, outerScope: new Hash(), registers: new Hash(), errorsOutputMode: ErrorsOutputMode.Display, maxIterations: 1, formatProvider: CultureInfo.CurrentCulture, cancellationToken: CancellationToken.None);
});
}

/// <summary>
/// The expectation is that a Context is created with a CultureInfo, however,
/// the parameter is defined as an IFormatProvider so this is not enforced by
Expand Down
13 changes: 2 additions & 11 deletions src/DotLiquid.Tests/CultureHelper.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
using System;
using System;
using System.Globalization;

namespace DotLiquid
namespace DotLiquid.Tests
{
internal static class CultureHelper
{
public static IDisposable SetCulture(string name)
{
var scope = new CultureScope(CultureInfo.CurrentCulture);

#if CORE
CultureInfo.CurrentCulture = new CultureInfo(name);
#else
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(name);
#endif
return scope;
}

Expand All @@ -28,11 +23,7 @@ public CultureScope(CultureInfo culture)

public void Dispose()
{
#if CORE
CultureInfo.CurrentCulture = this.culture;
#else
System.Threading.Thread.CurrentThread.CurrentCulture = this.culture;
#endif
}
}
}
Expand Down
44 changes: 14 additions & 30 deletions src/DotLiquid.Tests/DotLiquid.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net6.0;netcoreapp1.0;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net462;netcoreapp3.1;net6.0</TargetFrameworks>
<AssemblyName>DotLiquid.Tests</AssemblyName>
<AssemblyOriginatorKeyFile>../Formosatek-OpenSource.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
<PackageId>DotLiquid.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);portable-net451+win8;dnxcore5</PackageTargetFallback>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">1.0.16</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">2.0.9</RuntimeFrameworkVersion>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
Expand All @@ -32,48 +29,35 @@
<ItemGroup>
<ProjectReference Include="..\DotLiquid\DotLiquid.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net6.0' ">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />

<ItemGroup>
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Data" />
<Reference Include="System" />
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="Microsoft.CSharp" />
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);CORE</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<!-- This is simply to ensure formatting differences of .NET 5+ don't cause tests to fail -->
<RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup>

<ItemGroup>
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-7mfr-774f-w5r9" /><!-- 'Microsoft.NETCore.App' 1.x Unpatched -->
</ItemGroup>
</Project>
49 changes: 45 additions & 4 deletions src/DotLiquid.Tests/DropTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public IEnumerator GetEnumerator()
}
}

#if !CORE
internal class DataRowDrop : Drop
{
private readonly System.Data.DataRow _dataRow;
Expand All @@ -162,7 +161,6 @@ public override object BeforeMethod(string method)
return null;
}
}
#endif

internal class CamelCaseDrop : Drop
{
Expand All @@ -172,6 +170,11 @@ public int ProductID
}
}

internal class MethodDrop : Drop
{
public int ProductID() => 1;
}

internal static class ProductFilter
{
public static string ProductText(object input)
Expand Down Expand Up @@ -375,7 +378,6 @@ public void TestNullCatchAll()
Assert.That(Template.Parse("{{ nulldrop.a_method }}").Render(Hash.FromAnonymousObject(new { nulldrop = new NullDrop() })), Is.EqualTo(""));
}

#if !CORE
[Test]
public void TestDataRowDrop()
{
Expand All @@ -390,7 +392,6 @@ public void TestDataRowDrop()
Template tpl = Template.Parse(" {{ row.column1 }} ");
Assert.That(tpl.Render(Hash.FromAnonymousObject(new { row = new DataRowDrop(dataRow) })), Is.EqualTo(" Hello "));
}
#endif

[Test]
public void TestRubyNamingConventionPrintsHelpfulErrorIfMissingPropertyWouldMatchCSharpNamingConvention()
Expand Down Expand Up @@ -420,5 +421,45 @@ public void TestTypeResolutionDuplicateNames()
localVariables: Hash.FromAnonymousObject(new { value = new ConflictingChildDrop() }));
});
}

[Test]
public void TestDropRootKeys()
{
Helper.AssertTemplateResult(
expected: "1",
template: "{{ product_id }}",
localVariables: new CamelCaseDrop(),
namingConvention: new RubyNamingConvention());
}

[Test]
public void TestDropRootMethods()
{
Helper.AssertTemplateResult(
expected: "1",
template: "{{ product_id }}",
localVariables: new MethodDrop(),
namingConvention: new RubyNamingConvention());
}

[Test]
public void TestDropRootCatchall()
{
var dataTable = new System.Data.DataTable();
dataTable.Columns.Add("Column1");
dataTable.Columns.Add("Column2");

var dataRow = dataTable.NewRow();
dataRow["Column1"] = "Hello";
dataRow["Column2"] = "World";

Template tpl = Template.Parse("");
Helper.AssertTemplateResult(
expected: " Hello ",
template: " {{ column1 }} ",
localVariables: new DataRowDrop(dataRow),
namingConvention: new RubyNamingConvention());

}
}
}
Loading
Loading