Skip to content

Commit 94645ab

Browse files
authored
Merge pull request #77 from nblumhardt/additional-wildcard-cases
Add test cases to cover object accessor wildcards
2 parents 4f28ad5 + 08e7700 commit 94645ab

File tree

7 files changed

+65
-11
lines changed

7 files changed

+65
-11
lines changed

Build.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ echo "build: Build started"
33
Push-Location $PSScriptRoot
44

55
if(Test-Path .\artifacts) {
6-
echo "build: Cleaning .\artifacts"
7-
Remove-Item .\artifacts -Force -Recurse
6+
echo "build: Cleaning ./artifacts"
7+
Remove-Item ./artifacts -Force -Recurse
88
}
99

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

21-
foreach ($src in ls src/*) {
21+
foreach ($src in gci src/*) {
2222
Push-Location $src
2323

2424
echo "build: Packaging project in $src"
2525

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

2828
if($suffix) {
29-
& dotnet pack -c Release --include-source --no-build -o ..\..\artifacts --version-suffix=$suffix
29+
& dotnet pack -c Release --include-source --no-build -o ../../artifacts --version-suffix=$suffix
3030
} else {
31-
& dotnet pack -c Release --include-source --no-build -o ..\..\artifacts
31+
& dotnet pack -c Release --include-source --no-build -o ../../artifacts
3232
}
3333
if($LASTEXITCODE -ne 0) { exit 1 }
3434

3535
Pop-Location
3636
}
3737

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

4141
echo "build: Testing project in $test"

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: '{build}'
22
skip_tags: true
3-
image: Visual Studio 2019
3+
image: Visual Studio 2022
44
build_script:
5-
- ps: ./Build.ps1
5+
- pwsh: ./Build.ps1
66
artifacts:
77
- path: artifacts/Serilog.*.nupkg
88
deploy:

src/Serilog.Expressions/Expressions/Runtime/RuntimeOperators.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ public static LogEventPropertyValue IsDefined(LogEventPropertyValue? value)
374374
return ScalarBoolean(structure.Properties.Any(e => Coerce.IsTrue(pred(e.Value))));
375375
}
376376

377+
if (items is DictionaryValue dictionary)
378+
{
379+
return ScalarBoolean(dictionary.Elements.Any(e => Coerce.IsTrue(pred(e.Value))));
380+
}
381+
377382
return null;
378383
}
379384

@@ -391,6 +396,11 @@ public static LogEventPropertyValue IsDefined(LogEventPropertyValue? value)
391396
{
392397
return ScalarBoolean(structure.Properties.All(e => Coerce.IsTrue(pred(e.Value))));
393398
}
399+
400+
if (items is DictionaryValue dictionary)
401+
{
402+
return ScalarBoolean(dictionary.Elements.All(e => Coerce.IsTrue(pred(e.Value))));
403+
}
394404

395405
return null;
396406
}

test/Serilog.Expressions.Tests/Cases/expression-evaluation-cases.asv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,18 @@ User.Name ⇶ 'nblumhardt'
197197
// Wildcards
198198
[1,2,3][?] > 2 ⇶ true
199199
[1,2,3][*] > 2 ⇶ false
200+
{k:'test'}[?] = 'test' ⇶ true
201+
{k:'test'}[?] like 'test' ⇶ true
202+
{k:'test'}[?] like 'TEST' ⇶ false
203+
{k:'test'}[?] like 'TEST' ci ⇶ true
204+
{k:'test'}[?] like '%TES%' ci ⇶ true
205+
{k:'test'}[?] = 'none' ⇶ false
206+
test_dict({k:'test'})[?] = 'test' ⇶ true
207+
test_dict({k:'test'})[?] like 'test' ⇶ true
208+
test_dict({k:'test'})[?] like 'TEST' ⇶ false
209+
test_dict({k:'test'})[?] like 'TEST' ci ⇶ true
210+
test_dict({k:'test'})[?] like '%TES%' ci ⇶ true
211+
test_dict({k:'test'})[?] = 'none' ⇶ false
200212

201213
// Text and regex
202214
ismatch('foo', 'f') ⇶ true

test/Serilog.Expressions.Tests/ExpressionEvaluationTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public void ExpressionsAreCorrectlyEvaluated(string expr, string result)
2727
})));
2828

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

3334
if (expected is null)
3435
{

test/Serilog.Expressions.Tests/Serilog.Expressions.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net5.0</TargetFramework>
3+
<TargetFramework>net6.0</TargetFramework>
44
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
55
</PropertyGroup>
66
<ItemGroup>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Collections.Generic;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.Linq;
4+
using System.Reflection;
5+
using Serilog.Events;
6+
7+
namespace Serilog.Expressions.Tests.Support;
8+
9+
public class TestHelperNameResolver: NameResolver
10+
{
11+
public override bool TryResolveFunctionName(string name, [MaybeNullWhen(false)] out MethodInfo implementation)
12+
{
13+
if (name == "test_dict")
14+
{
15+
implementation = GetType().GetMethod(nameof(TestDict))!;
16+
return true;
17+
}
18+
19+
implementation = null;
20+
return false;
21+
}
22+
23+
public static LogEventPropertyValue? TestDict(LogEventPropertyValue? value)
24+
{
25+
if (value is not StructureValue sv)
26+
return null;
27+
28+
return new DictionaryValue(sv.Properties.Select(kv =>
29+
KeyValuePair.Create(new ScalarValue(kv.Name), kv.Value)));
30+
}
31+
}

0 commit comments

Comments
 (0)