-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gh-6] Completion improvements, testing improvements.
- Loading branch information
Showing
20 changed files
with
282 additions
and
162 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using MirrorSharp.Internal; | ||
using MirrorSharp.Internal.Commands; | ||
using MirrorSharp.Tests.Internal; | ||
using MirrorSharp.Tests.Internal.Results; | ||
using Xunit; | ||
|
||
namespace MirrorSharp.Tests { | ||
using static TestHelper; | ||
|
||
public class CompletionChoiceHandlerTests { | ||
[Fact] | ||
public async Task ExecuteAsync_AppliesSelected_WhenIndexIsProvided() { | ||
var session = SessionFromTextWithCursor("class C { void M(object o) { o| } }"); | ||
var completions = await TypeAndGetCompletionsAsync('.', session); | ||
var index = completions.List.Select((c, i) => new { c, i }).First(x => x.c.DisplayText.Contains("ToString")).i; | ||
|
||
await ExecuteHandlerAsync<CompletionChoiceHandler>(session, index); | ||
|
||
Assert.Equal( | ||
"class C { void M(object o) { o.ToString } }", | ||
session.SourceText.ToString() | ||
); | ||
Assert.Null(session.CurrentCompletionList); | ||
} | ||
|
||
[Fact] | ||
public async Task ExecuteAsync_CancelsCompletion_WhenXIsProvidedInsteadOfIndex() { | ||
var session = SessionFromTextWithCursor("class C { void M(object o) { o| } }"); | ||
await TypeAndGetCompletionsAsync('.', session); | ||
|
||
var result = await ExecuteHandlerAsync<CompletionChoiceHandler, ChangesResult>(session, 'X'); | ||
|
||
Assert.Null(result); | ||
Assert.Null(session.CurrentCompletionList); | ||
} | ||
|
||
private static async Task<TypeCharResult.ResultCompletions> TypeAndGetCompletionsAsync(char @char, WorkSession session) { | ||
return (await ExecuteHandlerAsync<TypeCharHandler, TypeCharResult>(session, @char)).Completions; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace MirrorSharp.Tests.Internal { | ||
public struct HandlerTestArgument { | ||
private readonly byte[] _data; | ||
|
||
private HandlerTestArgument(byte[] data) { | ||
_data = data; | ||
} | ||
|
||
public static implicit operator HandlerTestArgument(string value) { | ||
return Encoding.UTF8.GetBytes(value); | ||
} | ||
|
||
public static implicit operator HandlerTestArgument(char value) { | ||
return Encoding.UTF8.GetBytes(new[] { value }); | ||
} | ||
|
||
public static implicit operator HandlerTestArgument(int value) { | ||
return value.ToString(); | ||
} | ||
|
||
public static implicit operator HandlerTestArgument(byte[] data) { | ||
return new HandlerTestArgument(data); | ||
} | ||
|
||
public ArraySegment<byte> ToArraySegment() => new ArraySegment<byte>(_data ?? new byte[0]); | ||
} | ||
} |
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,17 @@ | ||
using System.Collections.Generic; | ||
|
||
// ReSharper disable ClassNeverInstantiated.Global | ||
// ReSharper disable CollectionNeverUpdated.Global | ||
// ReSharper disable UnusedAutoPropertyAccessor.Global | ||
|
||
namespace MirrorSharp.Tests.Internal.Results { | ||
public class ChangesResult { | ||
public IList<ResultChange> Changes { get; } = new List<ResultChange>(); | ||
|
||
public class ResultChange { | ||
public int Start { get; set; } | ||
public int Length { get; set; } | ||
public string Text { get; set; } | ||
} | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
...rSharp.Tests/Internal/SlowUpdateResult.cs → ...ests/Internal/Results/SlowUpdateResult.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
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,19 @@ | ||
using System.Collections.Generic; | ||
|
||
// ReSharper disable ClassNeverInstantiated.Global | ||
// ReSharper disable CollectionNeverUpdated.Global | ||
// ReSharper disable UnusedAutoPropertyAccessor.Global | ||
|
||
namespace MirrorSharp.Tests.Internal.Results { | ||
public class TypeCharResult { | ||
public ResultCompletions Completions { get; set; } | ||
|
||
public class ResultCompletions { | ||
public IList<ResultCompletion> List { get; } = new List<ResultCompletion>(); | ||
} | ||
|
||
public class ResultCompletion { | ||
public string DisplayText { get; set; } | ||
} | ||
} | ||
} |
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.IO; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MirrorSharp.Internal.Commands; | ||
using Newtonsoft.Json; | ||
|
||
namespace MirrorSharp.Tests.Internal { | ||
public class StubCommandResultSender : ICommandResultSender { | ||
private readonly StringBuilder _currentMessageBuilder = new StringBuilder(); | ||
|
||
public string LastMessageTypeName { get; private set; } | ||
public string LastMessageJson { get; private set; } | ||
|
||
public JsonWriter StartJsonMessage(string messageTypeName) { | ||
LastMessageTypeName = messageTypeName; | ||
_currentMessageBuilder.Clear(); | ||
return new JsonTextWriter(new StringWriter(_currentMessageBuilder)); | ||
} | ||
|
||
public Task SendJsonMessageAsync(CancellationToken cancellationToken) { | ||
LastMessageJson = "{ " + _currentMessageBuilder + " }"; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
Oops, something went wrong.