-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wildcard semantics; fix like clause anchoring
- Loading branch information
1 parent
e10eae6
commit 6ad474f
Showing
14 changed files
with
138 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
test/Serilog.Expressions.Tests/Cases/translation-cases.asv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Like | ||
A like 'a' ⇶ _Internal_NotEqual(_Internal_IndexOfMatch(A, '^a$'), -1) | ||
A like 'a%' ⇶ _Internal_NotEqual(_Internal_IndexOfMatch(A, '^a'), -1) | ||
A like '%a%' ⇶ _Internal_NotEqual(_Internal_IndexOfMatch(A, 'a'), -1) | ||
A like '%a' ⇶ _Internal_NotEqual(_Internal_IndexOfMatch(A, 'a$'), -1) | ||
A like '%a_b%' ⇶ _Internal_NotEqual(_Internal_IndexOfMatch(A, 'a.b'), -1) | ||
A like 'a%b%' ⇶ _Internal_NotEqual(_Internal_IndexOfMatch(A, '^a(?:.|\r|\n)*b'), -1) | ||
A like '%' ⇶ _Internal_NotEqual(_Internal_IndexOfMatch(A, '.*'), -1) | ||
|
||
// Variadics | ||
coalesce(A, B, C, D) ⇶ coalesce(A, coalesce(B, coalesce(C, D))) | ||
|
||
// Wildcards! | ||
A[?] ⇶ _Internal_Any(A, |$$p0| {$$p0}) | ||
A or B[*] ⇶ _Internal_Or(A, _Internal_All(B, |$$p0| {$$p0})) | ||
not (A is not null) or not (A[?] = 'a') ⇶ _Internal_Or(_Internal_Not(_Internal_IsNotNull(A)), _Internal_Not(_Internal_Any(A, |$$p0| {_Internal_Equal($$p0, 'a')}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/Serilog.Expressions.Tests/ExpressionTranslationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Serilog.Events; | ||
using Serilog.Expressions.Compilation; | ||
using Serilog.Expressions.Parsing; | ||
using Serilog.Expressions.Runtime; | ||
using Serilog.Expressions.Tests.Support; | ||
using Xunit; | ||
|
||
namespace Serilog.Expressions.Tests | ||
{ | ||
public class ExpressionTranslationTests | ||
{ | ||
public static IEnumerable<object[]> ExpressionEvaluationCases => | ||
AsvCases.ReadCases("translation-cases.asv"); | ||
|
||
[Theory] | ||
[MemberData(nameof(ExpressionEvaluationCases))] | ||
public void ExpressionsAreCorrectlyTranslated(string expr, string expected) | ||
{ | ||
var parsed = ExpressionParser.Parse(expr); | ||
var translated = ExpressionCompiler.Translate(parsed); | ||
var actual = translated.ToString(); | ||
Assert.Equal(expected, actual); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace Serilog.Expressions.Tests.Support | ||
{ | ||
// "Arrow-separated values ;-) ... convenient because the Unicode `⇶` character doesn't appear in | ||
// any of the cases themselves, and so we ignore any need for special character escaping (which is | ||
// troublesome when the language the cases are written in uses just about all special characters somehow | ||
// or other!). | ||
// | ||
// The ASV format informally supports `//` comment lines, as long as they don't contain the arrow character. | ||
static class AsvCases | ||
{ | ||
static readonly string CasesPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory!, "Cases"); | ||
|
||
public static IEnumerable<object[]> ReadCases(string filename) | ||
{ | ||
return from line in File.ReadLines(Path.Combine(CasesPath, filename)) | ||
select line.Split("⇶", StringSplitOptions.RemoveEmptyEntries) into cols | ||
where cols.Length == 2 | ||
select cols.Select(c => c.Trim()).ToArray<object>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters