-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
160 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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) | ||
{ | ||
} | ||
} | ||
} |
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
91 changes: 91 additions & 0 deletions
91
src/Uno.UI.RuntimeTests.Engine.Library/UI/UnitTestsControl.Filtering.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,91 @@ | ||
#if !UNO_RUNTIMETESTS_DISABLE_UI | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using static System.StringComparison; | ||
|
||
namespace Uno.UI.RuntimeTests; | ||
|
||
partial class UnitTestsControl | ||
{ | ||
private static IEnumerable<MethodInfo> FilterTests(UnitTestClassInfo testClassInfo, string? query) | ||
{ | ||
var tests = testClassInfo.Tests?.AsEnumerable() ?? Array.Empty<MethodInfo>(); | ||
foreach (var filter in SearchPredicate.ParseQuery(query)) | ||
{ | ||
// chain filters with AND logic | ||
tests = tests.Where(x => | ||
filter.Exclusion ^ // use xor to flip the result based on Exclusion | ||
filter.Tag?.ToLowerInvariant() switch | ||
{ | ||
"class" => MatchClassName(x, filter.Text), | ||
"displayname" => MatchDisplayName(x, filter.Text), | ||
"method" => MatchMethodName(x, filter.Text), | ||
|
||
_ => MatchClassName(x, filter.Text) || MatchMethodName(x, filter.Text), | ||
} | ||
); | ||
} | ||
|
||
bool MatchClassName(MethodInfo x, string value) => x.DeclaringType?.Name.Contains(value, InvariantCultureIgnoreCase) ?? false; | ||
bool MatchMethodName(MethodInfo x, string value) => x.Name.Contains(value, InvariantCultureIgnoreCase); | ||
bool MatchDisplayName(MethodInfo x, string value) => | ||
// fixme: since we are returning MethodInfo for match, there is no way to specify | ||
// which of the [DataRow] or which row within [DynamicData] without refactoring. | ||
// fixme: support [DynamicData] | ||
x.GetCustomAttributes<DataRowAttribute>().Any(y => y.DisplayName.Contains(value, InvariantCultureIgnoreCase)); | ||
|
||
return tests; | ||
} | ||
|
||
public record SearchPredicate(string Raw, string Text, bool Exclusion, string? Tag = null) | ||
{ | ||
private static readonly IReadOnlyDictionary<string, string> TagAliases = | ||
new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase) | ||
{ | ||
["c"] = "class", | ||
["m"] = "method", | ||
["d"] = "displayname", | ||
}; | ||
|
||
public static SearchPredicate[] ParseQuery(string? query) | ||
{ | ||
if (string.IsNullOrWhiteSpace(query)) return Array.Empty<SearchPredicate>(); | ||
|
||
return query!.Split(' ', StringSplitOptions.RemoveEmptyEntries) | ||
.Select(Parse) | ||
.OfType<SearchPredicate>() // trim null | ||
.Where(x => x.Text.Length > 0) // ignore empty tag query eg: "c:" | ||
.ToArray(); | ||
} | ||
|
||
public static SearchPredicate? Parse(string criteria) | ||
{ | ||
if (string.IsNullOrWhiteSpace(criteria)) return null; | ||
|
||
var raw = criteria.Trim(); | ||
var text = raw; | ||
if (text.StartsWith('-') is var exclusion && exclusion) | ||
{ | ||
text = text.Substring(1); | ||
} | ||
var tag = default(string?); | ||
if (text.Split(':', 2) is { Length: 2 } tagParts) | ||
{ | ||
tag = TagAliases.TryGetValue(tagParts[0], out var alias) ? alias : tagParts[0]; | ||
text = tagParts[1]; | ||
} | ||
|
||
return new(raw, text, exclusion, tag); | ||
} | ||
} | ||
} | ||
|
||
#endif |
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