-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: improved query syntax #90
Open
Xiaoy312
wants to merge
1
commit into
main
Choose a base branch
from
dev/xygu/20230412/improve-query-filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
#if HAS_UNO_WINUI || WINDOWS_WINUI | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
#else | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
#endif | ||
|
||
namespace Uno.UI.RuntimeTests.Engine | ||
{ | ||
/// <summary> | ||
/// Contains tests relevant to the RTT engine features. | ||
/// </summary> | ||
[TestClass] | ||
public class MetaTests | ||
{ | ||
[TestMethod] | ||
[RunsOnUIThread] | ||
public async Task When_Test_ContentHelper() | ||
{ | ||
var SUT = new TextBlock() { Text = "Hello" }; | ||
UnitTestsUIContentHelper.Content = SUT; | ||
|
||
await UnitTestsUIContentHelper.WaitForIdle(); | ||
await UnitTestsUIContentHelper.WaitForLoaded(SUT); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("hello", DisplayName = "hello test")] | ||
[DataRow("goodbye", DisplayName = "goodbye test")] | ||
public void When_DisplayName(string text) | ||
{ | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("at index 0")] | ||
[DataRow("at index 1")] | ||
[DataRow("at index 2")] | ||
public void When_DataRows(string arg) | ||
{ | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("at index 0", "asd")] | ||
[DataRow("at index 1", "asd")] | ||
[DataRow("at index 2", "zxc")] | ||
public void When_DataRows2(string arg, string arg2) | ||
{ | ||
} | ||
|
||
[DataTestMethod] | ||
[DynamicData(nameof(GetDynamicData), DynamicDataSourceType.Method)] | ||
public void When_DynamicData(string arg, string arg2) | ||
{ | ||
} | ||
|
||
[TestMethod] | ||
[InjectedPointer(Windows.Devices.Input.PointerDeviceType.Touch)] | ||
[InjectedPointer(Windows.Devices.Input.PointerDeviceType.Pen)] | ||
public void When_InjectedPointers() | ||
{ | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("at index 0")] | ||
[DataRow("at index 1")] | ||
[InjectedPointer(Windows.Devices.Input.PointerDeviceType.Touch)] | ||
[InjectedPointer(Windows.Devices.Input.PointerDeviceType.Pen)] | ||
public void When_InjectedPointers_DataRows(string arg) | ||
{ | ||
} | ||
|
||
public static IEnumerable<object[]> GetDynamicData() | ||
{ | ||
yield return new object[] { "at index 0", "asd" }; | ||
yield return new object[] { "at index 1", "asd" }; | ||
yield return new object[] { "at index 2", "zxc" }; | ||
} | ||
} | ||
} |
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,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Uno.UI.RuntimeTests.Engine.Extensions; | ||
|
||
internal static class AssertExtensions | ||
{ | ||
public static void AreEqual<T>(this Assert assert, T expected, T actual, IEqualityComparer<T> comparer) | ||
{ | ||
if (!comparer.Equals(expected, actual)) | ||
{ | ||
Assert.Fail(string.Join("\n", | ||
"AreEqual failed.", | ||
$"Expected: {expected}", | ||
$"Actual: {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
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,123 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Uno.UI.RuntimeTests.Engine.Extensions; | ||
using static Uno.UI.RuntimeTests.UnitTestsControl; | ||
|
||
namespace Uno.UI.RuntimeTests.Engine; | ||
|
||
[TestClass] | ||
public partial class SearchQueryTests | ||
{ | ||
[TestMethod] | ||
[DataRow("asd")] // simple | ||
[DataRow("^asd")] // match start | ||
[DataRow("asd$")] // match end | ||
[DataRow("^asd$")] // full match | ||
public void When_SearchPredicatePart_Parse(string input) | ||
{ | ||
var actual = SearchPredicatePart.Parse(input); | ||
var expected = input switch | ||
{ | ||
"asd" => new SearchPredicatePart(input, "asd"), | ||
"^asd" => new SearchPredicatePart(input, "asd", MatchStart: true), | ||
"asd$" => new SearchPredicatePart(input, "asd", MatchEnd: true), | ||
"^asd$" => new SearchPredicatePart(input, "asd", MatchStart: true, MatchEnd: true), | ||
|
||
_ => throw new ArgumentOutOfRangeException(input), | ||
}; | ||
|
||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("asd")] // simple | ||
[DataRow("^asd,qwe$,^zxc$")] // multi parts | ||
[DataRow("-asd")] // exclusion | ||
[DataRow("tag:asd")] // tagged | ||
public void When_SearchPredicate_ParseFragment(string input) | ||
{ | ||
var actual = SearchPredicate.ParseFragment(input); | ||
var expected = input switch | ||
{ | ||
"asd" => new SearchPredicate("asd", "asd", Parts: new SearchPredicatePart("asd", "asd")), | ||
"^asd,qwe$,^zxc$" => new SearchPredicate("^asd,qwe$,^zxc$", "^asd,qwe$,^zxc$", Parts: new[]{ | ||
new SearchPredicatePart("^asd", "asd", MatchStart: true), | ||
new SearchPredicatePart("qwe$", "qwe", MatchEnd: true), | ||
new SearchPredicatePart("^zxc$", "zxc", MatchStart: true, MatchEnd: true), | ||
}), | ||
"-asd" => new SearchPredicate("-asd", "asd", Exclusion: true, Parts: new[]{ | ||
new SearchPredicatePart("asd", "asd"), | ||
}), | ||
"tag:asd" => new SearchPredicate("tag:asd", "asd", Tag: "tag", Parts: new[]{ | ||
new SearchPredicatePart("asd", "asd"), | ||
}), | ||
|
||
_ => throw new ArgumentOutOfRangeException(input), | ||
}; | ||
|
||
Assert.That.AreEqual(expected, actual, SearchPredicate.DefaultComparer); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("asd")] // simple | ||
[DataRow("asd qwe")] // multi fragments | ||
[DataRow("class:asd method:qwe display_name:zxc -123")] // tags | ||
[DataRow("c:asd m:qwe d:zxc -123")] // aliased tags | ||
[DataRow("d:\"^asd \\\", asd$\"")] // quoted with escape | ||
[DataRow("at:asd\"asd\"asd,^asd,asd$")] // inner literal quote | ||
[DataRow("asd @0")] // custom prefix | ||
[DataRow("p:\"index 0\",\"index 1\" -p:\"asd\"")] // multiple quotes | ||
|
||
public void When_SearchPredicate_Parse(string input) | ||
{ | ||
var actual = SearchPredicate.ParseQuery(input); | ||
var predicates = input switch | ||
{ | ||
"asd" => new SearchPredicate[] { new("asd", "asd", Parts: new SearchPredicatePart[] { new("asd", "asd"), }), }, | ||
"asd qwe" => new SearchPredicate[] { | ||
new("asd", "asd", Parts: new SearchPredicatePart[] { new("asd", "asd"), }), | ||
new("qwe", "qwe", Parts: new SearchPredicatePart[] { new("qwe", "qwe"), }), | ||
}, | ||
"class:asd method:qwe display_name:zxc -123" => new SearchPredicate[] { | ||
new("class:asd", "asd", Tag: "class", Parts: new SearchPredicatePart[] { new("asd", "asd"), }), | ||
new("method:qwe", "qwe", Tag: "method", Parts: new SearchPredicatePart[] { new("qwe", "qwe"), }), | ||
new("display_name:zxc", "zxc", Tag: "display_name", Parts: new SearchPredicatePart[] { new("zxc", "zxc"), }), | ||
new("-123", "123", Exclusion: true, Parts: new SearchPredicatePart[] { new("123", "123"), }), | ||
}, | ||
"c:asd m:qwe d:zxc -123" => new SearchPredicate[] { | ||
new("c:asd", "asd", Tag: "class", Parts: new SearchPredicatePart[] { new("asd", "asd"), }), | ||
new("m:qwe", "qwe", Tag: "method", Parts: new SearchPredicatePart[] { new("qwe", "qwe"), }), | ||
new("d:zxc", "zxc", Tag: "display_name", Parts: new SearchPredicatePart[] { new("zxc", "zxc"), }), | ||
new("-123", "123", Exclusion: true, Parts: new SearchPredicatePart[] { new("123", "123"), }), | ||
}, | ||
"d:\"^asd \\\", asd$\"" => new SearchPredicate[] { | ||
new("d:\"^asd \\\", asd$\"", "\"^asd \\\", asd$\"", Tag: "display_name", Parts: new SearchPredicatePart[] { | ||
new("\"^asd \\\", asd$\"", "asd \", asd", MatchStart: true, MatchEnd: true), | ||
}), | ||
}, | ||
"at:asd\"asd\"asd,^asd,asd$" => new SearchPredicate[] { | ||
new("at:asd\"asd\"asd,^asd,asd$", "asd\"asd\"asd,^asd,asd$", Tag: "at", Parts: new SearchPredicatePart[] { | ||
new("asd\"asd\"asd", "asd\"asd\"asd"), | ||
new ("^asd", "asd", MatchStart: true), | ||
new ("asd$", "asd", MatchEnd: true), | ||
}), | ||
}, | ||
"asd @0" => new SearchPredicate[] { | ||
new("asd", "asd", Parts: new SearchPredicatePart[] { new ("asd", "asd"), }), | ||
new("@0", "0", Tag: "at", Parts: new SearchPredicatePart[] { new ("0", "0"), }), | ||
}, | ||
"p:\"index 0\",\"index 1\" -p:\"asd\"" => new SearchPredicate[] { | ||
new("p:\"index 0\",\"index 1\"", "\"index 0\",\"index 1\"", Tag: "params", Parts: new SearchPredicatePart[] { new("\"index 0\"", "index 0"), new("\"index 1\"", "index 1") }), | ||
new("-p:\"asd\"", "\"asd\"", Exclusion: true, Tag: "params", Parts: new SearchPredicatePart[] { new("\"asd\"", "asd") }) | ||
}, | ||
|
||
_ => throw new ArgumentOutOfRangeException(input), | ||
}; | ||
var expected = new SearchPredicateCollection(predicates!); | ||
|
||
Assert.That.AreEqual(expected, actual, SearchPredicate.DefaultQueryComparer); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
src/Uno.UI.RuntimeTests.Engine.Library/Extensions/StringExtensions.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,55 @@ | ||||||
using System; | ||||||
using System.Collections.Generic; | ||||||
using System.Linq; | ||||||
using System.Text; | ||||||
using System.Text.RegularExpressions; | ||||||
|
||||||
namespace Uno.UI.RuntimeTests.Extensions; | ||||||
|
||||||
internal static partial class StringExtensions | ||||||
{ | ||||||
/// <summary> | ||||||
/// Like <see cref="string.Split(char[])"/>, but allows exception to be made with a Regex pattern. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/// </summary> | ||||||
/// <param name="input"></param> | ||||||
/// <param name="separator"></param> | ||||||
/// <param name="ignoredPattern">segments matched by the regex will not be splited.</param> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/// <param name="skipEmptyEntries"></param> | ||||||
/// <returns></returns> | ||||||
public static string[] SplitWithIgnore(this string input, char separator, string ignoredPattern, bool skipEmptyEntries) | ||||||
{ | ||||||
var ignores = Regex.Matches(input, ignoredPattern); | ||||||
|
||||||
var shards = new List<string>(); | ||||||
for (int i = 0; i < input.Length; i++) | ||||||
{ | ||||||
var nextSpaceDelimiter = input.IndexOf(separator, i); | ||||||
|
||||||
// find the next space, if inside a quote | ||||||
while (nextSpaceDelimiter != -1 && ignores.FirstOrDefault(x => InRange(x, nextSpaceDelimiter)) is { } enclosingIgnore) | ||||||
{ | ||||||
nextSpaceDelimiter = enclosingIgnore.Index + enclosingIgnore.Length is { } afterIgnore && afterIgnore < input.Length | ||||||
? input.IndexOf(separator, afterIgnore) | ||||||
: -1; | ||||||
} | ||||||
|
||||||
if (nextSpaceDelimiter != -1) | ||||||
{ | ||||||
shards.Add(input.Substring(i, nextSpaceDelimiter - i)); | ||||||
i = nextSpaceDelimiter; | ||||||
|
||||||
// skip multiple continuous spaces | ||||||
while (skipEmptyEntries && i + 1 < input.Length && input[i + 1] == separator) i++; | ||||||
} | ||||||
else | ||||||
{ | ||||||
shards.Add(input.Substring(i)); | ||||||
break; | ||||||
} | ||||||
} | ||||||
|
||||||
return shards.ToArray(); | ||||||
|
||||||
bool InRange(Match x, int index) => x.Index <= index && index < (x.Index + x.Length); | ||||||
} | ||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.