diff --git a/Editor.Tests/Commands/AutoClosingTests.cs b/Editor.Tests/Commands/AutoClosingTests.cs
index 22149bc..4864f94 100644
--- a/Editor.Tests/Commands/AutoClosingTests.cs
+++ b/Editor.Tests/Commands/AutoClosingTests.cs
@@ -29,7 +29,7 @@ public Task TestComment (string sourceText, string expectedText, string typeChar
return this.TestCommands (
sourceText,
expectedText,
- (s) => s.Type (typeChars),
+ EditorAction.Type (typeChars),
caretMarkerChar: '|',
initialize: (ITextView tv) => {
tv.Options.SetOptionValue (XmlOptions.AutoInsertClosingTag, true);
diff --git a/Editor.Tests/Completion/CommitTests.cs b/Editor.Tests/Completion/CommitTests.cs
index 6976802..7684c5a 100644
--- a/Editor.Tests/Completion/CommitTests.cs
+++ b/Editor.Tests/Completion/CommitTests.cs
@@ -1,12 +1,9 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-using System;
-using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Text.Editor;
-using Microsoft.VisualStudio.Text.Editor.Commanding;
using MonoDevelop.Xml.Editor.Tests.Extensions;
@@ -28,10 +25,7 @@ public Task SingleClosingTag ()
$
",
- (s) => {
- s.Type ("
$
",
- (s) => {
- s.Type ("
$
",
- (s) => {
- s.InvokeCompletion ();
- s.Type ("
$
",
- (s) => {
- s.InvokeCompletion ();
- s.Type (" this.TestCommands (
@"$",
@"$",
- (s) => {
- s.InvokeCompletion ();
- s.Type ("
$",
- (s) => {
- s.InvokeCompletion ();
- s.Type ("
$
",
- (s) => {
- s.Type ("
$
",
- (s) => {
- s.Type (" { Action a = (s) => s.Type (t); return a; });
- return this.TestCommands (before, after, actions, initialize: (ITextView tv) => {
- tv.Options.SetOptionValue ("BraceCompletion/Enabled", true);
- return Task.CompletedTask;
- });
+ return this.TestCommands (
+ before,
+ after,
+ EditorAction.Type(typeChars),
+ initialize: (ITextView tv) => {
+ tv.Options.SetOptionValue ("BraceCompletion/Enabled", true);
+ return Task.CompletedTask;
+ }
+ );
}
[Test]
[TestCase ("", "$")]
- [TestCase ("", "$")]
+ [TestCase (" TestTypeCommands ("$", after, typeChars);
[Test]
[TestCase (" T\n", " TestTypeCommands ("
public static bool EnableDebugTrace { get; set; }
- public static void Type (this IEditorCommandHandlerService commandService, string text)
- {
- foreach (var c in text) {
- switch (c) {
- case '\n':
- Enter (commandService);
- break;
- default:
- if (EnableDebugTrace) {
- LogTrace ($"Typing '{c}'");
- }
- commandService.CheckAndExecute ((v, b) => new TypeCharCommandArgs (v, b, c));
- break;
- }
- }
- }
-
- public static void Enter (this IEditorCommandHandlerService commandService)
- {
- if (EnableDebugTrace) {
- LogTrace ("Invoking return key");
- }
- commandService.CheckAndExecute ((v, b) => new ReturnKeyCommandArgs (v, b));
- }
-
- public static void InvokeCompletion (this IEditorCommandHandlerService commandService)
- {
- if (EnableDebugTrace) {
- LogTrace ("Invoking completion");
- }
- commandService.CheckAndExecute ((v, b) => new InvokeCompletionListCommandArgs (v, b));
- }
-
public static void CheckAndExecute (
this IEditorCommandHandlerService commandService,
Func argsFactory) where T : EditorCommandArgs
@@ -84,7 +51,7 @@ public static void CheckAndExecute (
// failures on GitHub Actions CI.
//
// Note that polling IAsyncCompletionSessionOperations.IsStarted does not help.
- if (IsGithubActions && !session.Properties.TryGetProperty (HasWaitedForCompletionToInitializeKey, out bool hasWaited)) {
+ if (IsGitHubActions && !session.Properties.TryGetProperty (HasWaitedForCompletionToInitializeKey, out bool hasWaited)) {
session.Properties.AddProperty (HasWaitedForCompletionToInitializeKey, true);
Thread.Sleep (500);
}
@@ -102,7 +69,7 @@ public static void CheckAndExecute (
static readonly object HasWaitedForCompletionToInitializeKey = new();
- static readonly bool IsGithubActions = Environment.GetEnvironmentVariable("GITHUB_ACTIONS") != null;
+ static readonly bool IsGitHubActions = Environment.GetEnvironmentVariable("GITHUB_ACTIONS") != null;
static void LogTrace(string message) => Console.WriteLine ($"{TraceID}: {message}");
diff --git a/Editor.Tests/Extensions/EditorAction.cs b/Editor.Tests/Extensions/EditorAction.cs
new file mode 100644
index 0000000..81939d3
--- /dev/null
+++ b/Editor.Tests/Extensions/EditorAction.cs
@@ -0,0 +1,52 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Collections.Generic;
+
+using Microsoft.VisualStudio.Text.Editor.Commanding;
+using Microsoft.VisualStudio.Text.Editor.Commanding.Commands;
+
+namespace MonoDevelop.Xml.Editor.Tests.Extensions
+{
+ public static class EditorAction
+ {
+ public static IEnumerable> Type (string text)
+ {
+ foreach (var c in text) {
+ switch (c) {
+ case '\n':
+
+ yield return Enter;
+ break;
+ default:
+ if (EnableDebugTrace) {
+ LogTrace ($"Typing '{c}'");
+ }
+ yield return (commandService) => commandService.CheckAndExecute ((v, b) => new TypeCharCommandArgs (v, b, c));
+ break;
+ }
+ }
+ }
+
+ public static void Enter (IEditorCommandHandlerService commandService)
+ {
+ if (EnableDebugTrace) {
+ LogTrace ("Invoking return key");
+ }
+ commandService.CheckAndExecute ((v, b) => new ReturnKeyCommandArgs (v, b));
+ }
+
+ public static void InvokeCompletion (IEditorCommandHandlerService commandService)
+ {
+ if (EnableDebugTrace) {
+ LogTrace ("Invoking completion");
+ }
+ commandService.CheckAndExecute ((v, b) => new InvokeCompletionListCommandArgs (v, b));
+ }
+
+ const string TraceID = "EditorAction.Trace";
+ static bool EnableDebugTrace => CommandServiceExtensions.EnableDebugTrace;
+ static void LogTrace (string message) => Console.WriteLine ($"{TraceID}: {message}");
+ }
+}
diff --git a/Editor.Tests/Extensions/EditorCommandExtensions.cs b/Editor.Tests/Extensions/EditorCommandExtensions.cs
index d0376a2..2dd0cd0 100644
--- a/Editor.Tests/Extensions/EditorCommandExtensions.cs
+++ b/Editor.Tests/Extensions/EditorCommandExtensions.cs
@@ -77,6 +77,10 @@ public static async Task TestCommands (
foreach (var c in commands) {
c (commandService);
+
+ // yield to let things catch up
+ // and so we don't block the UI thread between the commands
+ await Task.Delay (20);
}
Assert.AreEqual (afterDocumentText, textView.TextBuffer.CurrentSnapshot.GetText ());