2016-12-19 10:32:33 +03:00
|
|
|
|
using System.Linq;
|
2016-10-25 11:42:01 +03:00
|
|
|
|
using System.Threading.Tasks;
|
2017-01-03 04:19:34 +03:00
|
|
|
|
using MirrorSharp.Internal;
|
2017-01-03 02:24:15 +03:00
|
|
|
|
using MirrorSharp.Testing;
|
2017-01-03 04:19:34 +03:00
|
|
|
|
using MirrorSharp.Testing.Internal.Results;
|
2016-09-26 10:42:42 +03:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace MirrorSharp.Tests {
|
2017-01-03 02:24:15 +03:00
|
|
|
|
using static CommandIds;
|
2016-10-05 09:53:02 +03:00
|
|
|
|
|
|
|
|
|
public class MoveCursorHandlerTests {
|
2016-09-26 10:42:42 +03:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("1", 1)]
|
|
|
|
|
[InlineData("79", 79)]
|
|
|
|
|
[InlineData("1234567890", 1234567890)]
|
|
|
|
|
public async void ExecuteAsync_UpdatesSessionCursorPosition(string dataString, int expectedPosition) {
|
2017-01-03 02:33:48 +03:00
|
|
|
|
var driver = MirrorSharpTestDriver.New();
|
|
|
|
|
await driver.SendAsync(MoveCursor, dataString);
|
|
|
|
|
Assert.Equal(expectedPosition, driver.Session.CursorPosition);
|
2016-09-26 10:42:42 +03:00
|
|
|
|
}
|
2016-10-25 11:42:01 +03:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ExecuteAsync_ProducesEmptySignatureHelp_IfCursorIsMovedOutsideOfSignatureSpan() {
|
2017-05-13 15:57:31 +03:00
|
|
|
|
var driver = MirrorSharpTestDriver.New().SetTextWithCursor(@"
|
2016-10-25 11:42:01 +03:00
|
|
|
|
class C {
|
|
|
|
|
void M() {}
|
|
|
|
|
void T() { M| }
|
|
|
|
|
}
|
|
|
|
|
");
|
2017-01-03 02:33:48 +03:00
|
|
|
|
var signatures = await driver.SendAsync<SignaturesResult>(TypeChar, '(');
|
|
|
|
|
var result = await driver.SendAsync<SignaturesResult>(MoveCursor, signatures.Span.Start - 1);
|
2016-10-25 11:42:01 +03:00
|
|
|
|
Assert.Equal(0, result.Signatures.Count);
|
|
|
|
|
}
|
2016-12-19 10:32:33 +03:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task ExecuteAsync_ProducesSignatureHelpWithNewSelectedParameter_IfCursorIsMovedMovedBetweenParameters() {
|
2017-05-13 15:57:31 +03:00
|
|
|
|
var driver = MirrorSharpTestDriver.New().SetTextWithCursor(@"
|
2016-12-19 10:32:33 +03:00
|
|
|
|
class C {
|
|
|
|
|
void M(int a, int b, int c) {}
|
|
|
|
|
void T() { M(1| }
|
|
|
|
|
}
|
|
|
|
|
");
|
2017-01-03 04:19:34 +03:00
|
|
|
|
await driver.SendTypeCharsAsync(",2,");
|
2016-12-19 10:32:33 +03:00
|
|
|
|
|
2017-01-03 02:33:48 +03:00
|
|
|
|
var result = await driver.SendAsync<SignaturesResult>(MoveCursor, driver.Session.CursorPosition - 1);
|
2016-12-19 10:32:33 +03:00
|
|
|
|
var signature = result.Signatures.Single();
|
|
|
|
|
Assert.Equal("void C.M(int a, *int b*, int c)", signature.ToString());
|
|
|
|
|
}
|
2016-09-26 10:42:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|