From f57bcb4231fb620a9b13b5d9cc262d44435bc1fd Mon Sep 17 00:00:00 2001 From: mauricel Date: Thu, 25 Mar 2021 16:22:58 +0000 Subject: [PATCH] #13 - Add tests - suggest takes cursor positioning into account --- CliFx.Tests/SuggestDirectiveSpecs.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CliFx.Tests/SuggestDirectiveSpecs.cs b/CliFx.Tests/SuggestDirectiveSpecs.cs index 8d29474e..160fa817 100644 --- a/CliFx.Tests/SuggestDirectiveSpecs.cs +++ b/CliFx.Tests/SuggestDirectiveSpecs.cs @@ -93,14 +93,16 @@ private string FormatExpectedOutput(string [] s) [Theory] [InlineData("supply all commands if nothing supplied", - "clifx.exe", new[] { "cmd", "cmd02" })] + "clifx.exe", 0, new[] { "cmd", "cmd02" })] [InlineData("supply all commands that match partially", - "clifx.exe c", new[] { "cmd", "cmd02" })] + "clifx.exe c", 0, new[] { "cmd", "cmd02" })] [InlineData("supply command options if match found, regardles of other partial matches (no options defined)", - "clifx.exe cmd", new string[] { })] + "clifx.exe cmd", 0, new string[] { })] [InlineData("supply nothing if no partial match applies", - "clifx.exe cmd2", new string[] { })] - public async Task Suggest_directive_accepts_command_line_by_environment_variable(string usecase, string variableContents, string[] expected) + "clifx.exe cmd2", 0, new string[] { })] + [InlineData("supply all commands that match partially, allowing for cursor position", + "clifx.exe cmd", -2, new[] { "cmd", "cmd02" })] + public async Task Suggest_directive_suggests_commands_by_environment_variables(string usecase, string variableContents, int cursorOffset, string[] expected) { // Arrange var application = TestApplicationFactory(_cmdCommandCs, _cmd2CommandCs) @@ -108,7 +110,7 @@ public async Task Suggest_directive_accepts_command_line_by_environment_variable // Act var exitCode = await application.RunAsync( - new[] { "[suggest]", "--envvar", "CLIFX-{GUID}", "--cursor", variableContents.Length.ToString() }, + new[] { "[suggest]", "--envvar", "CLIFX-{GUID}", "--cursor", (variableContents.Length + cursorOffset).ToString() }, new Dictionary() { ["CLIFX-{GUID}"] = variableContents