Skip to content

Enable wildcard indexers over dictionary elements #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 14, 2022
Merged
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
12 changes: 6 additions & 6 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ echo "build: Build started"
Push-Location $PSScriptRoot

if(Test-Path .\artifacts) {
echo "build: Cleaning .\artifacts"
Remove-Item .\artifacts -Force -Recurse
echo "build: Cleaning ./artifacts"
Remove-Item ./artifacts -Force -Recurse
}

& dotnet restore --no-cache
Expand All @@ -18,24 +18,24 @@ $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($c
echo "build: Package version suffix is $suffix"
echo "build: Build version suffix is $buildSuffix"

foreach ($src in ls src/*) {
foreach ($src in gci src/*) {
Push-Location $src

echo "build: Packaging project in $src"

& dotnet build -c Release --version-suffix=$buildSuffix

if($suffix) {
& dotnet pack -c Release --include-source --no-build -o ..\..\artifacts --version-suffix=$suffix
& dotnet pack -c Release --include-source --no-build -o ../../artifacts --version-suffix=$suffix
} else {
& dotnet pack -c Release --include-source --no-build -o ..\..\artifacts
& dotnet pack -c Release --include-source --no-build -o ../../artifacts
}
if($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
}

foreach ($test in ls test/*.Tests) {
foreach ($test in gci test/*.Tests) {
Push-Location $test

echo "build: Testing project in $test"
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2019
image: Visual Studio 2022
build_script:
- ps: ./Build.ps1
- pwsh: ./Build.ps1
artifacts:
- path: artifacts/Serilog.*.nupkg
deploy:
Expand Down
10 changes: 10 additions & 0 deletions src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ public static LogEventPropertyValue IsDefined(LogEventPropertyValue? value)
return ScalarBoolean(structure.Properties.Any(e => Coerce.IsTrue(pred(e.Value))));
}

if (items is DictionaryValue dictionary)
{
return ScalarBoolean(dictionary.Elements.Any(e => Coerce.IsTrue(pred(e.Value))));
}

return null;
}

Expand All @@ -391,6 +396,11 @@ public static LogEventPropertyValue IsDefined(LogEventPropertyValue? value)
{
return ScalarBoolean(structure.Properties.All(e => Coerce.IsTrue(pred(e.Value))));
}

if (items is DictionaryValue dictionary)
{
return ScalarBoolean(dictionary.Elements.All(e => Coerce.IsTrue(pred(e.Value))));
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ User.Name ⇶ 'nblumhardt'
// Wildcards
[1,2,3][?] > 2 ⇶ true
[1,2,3][*] > 2 ⇶ false
{k:'test'}[?] = 'test' ⇶ true
{k:'test'}[?] like 'test' ⇶ true
{k:'test'}[?] like 'TEST' ⇶ false
{k:'test'}[?] like 'TEST' ci ⇶ true
{k:'test'}[?] like '%TES%' ci ⇶ true
{k:'test'}[?] = 'none' ⇶ false
test_dict({k:'test'})[?] = 'test' ⇶ true
test_dict({k:'test'})[?] like 'test' ⇶ true
test_dict({k:'test'})[?] like 'TEST' ⇶ false
test_dict({k:'test'})[?] like 'TEST' ci ⇶ true
test_dict({k:'test'})[?] like '%TES%' ci ⇶ true
test_dict({k:'test'})[?] = 'none' ⇶ false

// Text and regex
ismatch('foo', 'f') ⇶ true
Expand Down
5 changes: 3 additions & 2 deletions test/Serilog.Expressions.Tests/ExpressionEvaluationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public void ExpressionsAreCorrectlyEvaluated(string expr, string result)
})));

var frFr = CultureInfo.GetCultureInfoByIetfLanguageTag("fr-FR");
var actual = SerilogExpression.Compile(expr, formatProvider: frFr)(evt);
var expected = SerilogExpression.Compile(result)(evt);
var testHelpers = new TestHelperNameResolver();
var actual = SerilogExpression.Compile(expr, formatProvider: frFr, testHelpers)(evt);
var expected = SerilogExpression.Compile(result, nameResolver: testHelpers)(evt);

if (expected is null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
<ItemGroup>
Expand Down
31 changes: 31 additions & 0 deletions test/Serilog.Expressions.Tests/Support/TestHelperNameResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using Serilog.Events;

namespace Serilog.Expressions.Tests.Support;

public class TestHelperNameResolver: NameResolver
{
public override bool TryResolveFunctionName(string name, [MaybeNullWhen(false)] out MethodInfo implementation)
{
if (name == "test_dict")
{
implementation = GetType().GetMethod(nameof(TestDict))!;
return true;
}

implementation = null;
return false;
}

public static LogEventPropertyValue? TestDict(LogEventPropertyValue? value)
{
if (value is not StructureValue sv)
return null;

return new DictionaryValue(sv.Properties.Select(kv =>
KeyValuePair.Create(new ScalarValue(kv.Name), kv.Value)));
}
}