Skip to content

Commit

Permalink
Tyrrrz#13 - Add tests - suggest takes cursor positioning into account…
Browse files Browse the repository at this point in the history
…. Tidy up.
  • Loading branch information
mauricel committed Mar 31, 2021
1 parent f7c79e0 commit f34bc00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
35 changes: 8 additions & 27 deletions CliFx.Tests/SuggestDirectiveSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,24 @@ 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)
.Build();

// 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<string, string>()
{
["CLIFX-{GUID}"] = variableContents
Expand Down Expand Up @@ -142,26 +144,5 @@ public async Task Suggest_directive_suggests_commands_by_command_line_only(strin
exitCode.Should().Be(0);
stdOut.Should().Be(FormatExpectedOutput(expected), usecase);
}

//[Theory]
//[InlineData("happy case", "clifx.exe c", "")]
//public async Task Suggest_directive_generates_suggestions(string because, string commandline, string expectedResult)
//{
// // Arrange
// var application = TestApplicationFactory(_cmdCommandCs)
// .Build();

// // Act
// var exitCode = await application.RunAsync(
// new[] { "[suggest]", commandline }
// );

// var stdOut = FakeConsole.ReadOutputString();

// // Assert
// exitCode.Should().Be(0);

// stdOut.Should().Be(expectedResult + "\r\n", because);
//}
}
}
2 changes: 1 addition & 1 deletion CliFx/SuggestionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private string ExtractCommandText(CommandInput input)

if (commandCacheVariable == null)
{
// ignore cursor position as we don't know what the original user input string is
// ignore cursor position as we don't know what the original user input string really is
return string.Join(" ", input.OriginalCommandLine.Where(arg => !IsDirective(arg)));
}

Expand Down

0 comments on commit f34bc00

Please sign in to comment.