public void GetCompletions_NoMatches_ReturnsEmpty() { HttpState httpState = SetupHttpState(); IEnumerable <string> result = ServerPathCompletion.GetCompletions(httpState, "child1/abc"); Assert.Empty(result); }
public void GetCompletions_EmptyDirectory_ReturnsEmpty() { HttpState httpState = SetupHttpState(); IEnumerable <string> result = ServerPathCompletion.GetCompletions(httpState, "child1/grandchild1/g"); Assert.Empty(result); }
public void GetCompletions_AbsoluteUri_ReturnsNull() { HttpState httpState = SetupHttpState(); IEnumerable <string> result = ServerPathCompletion.GetCompletions(httpState, "https://github.com/"); Assert.Null(result); }
public void GetCompletions_NullStructure_ReturnsNull() { HttpState httpState = SetupHttpState(); httpState.ApiDefinition = null; IEnumerable <string> result = ServerPathCompletion.GetCompletions(httpState, "c"); Assert.Null(result); }
public void GetCompletions_OnlyRoot_ProperResults() { HttpState httpState = SetupHttpState(); IEnumerable <string> result = ServerPathCompletion.GetCompletions(httpState, "ch"); Assert.Equal(2, result.Count()); Assert.Contains("child1", result, StringComparer.OrdinalIgnoreCase); Assert.Contains("child2", result, StringComparer.OrdinalIgnoreCase); }
public IEnumerable <string> Suggest(IShellState shellState, HttpState programState, ICoreParseResult parseResult) { parseResult = parseResult ?? throw new ArgumentNullException(nameof(parseResult)); shellState = shellState ?? throw new ArgumentNullException(nameof(shellState)); if (parseResult.SelectedSection == 0 && (string.IsNullOrEmpty(parseResult.Sections[parseResult.SelectedSection]) || Name.StartsWith(parseResult.Sections[0].Substring(0, parseResult.CaretPositionWithinSelectedSection), StringComparison.OrdinalIgnoreCase))) { return(new[] { Name }); } else if (parseResult.ContainsAtLeast(minimumLength: 2, Name)) { if (shellState.CommandDispatcher is ICommandDispatcher <HttpState, ICoreParseResult> dispatcher && parseResult.Slice(1) is ICoreParseResult continuationParseResult) { HashSet <string> suggestions = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (ICommand <HttpState, ICoreParseResult> command in dispatcher.Commands) { IEnumerable <string> commandSuggestions = command.Suggest(shellState, programState, continuationParseResult); if (commandSuggestions != null) { suggestions.UnionWith(commandSuggestions); } } if (continuationParseResult.SelectedSection == 0) { string normalizedCompletionText = continuationParseResult.Sections[0].Substring(0, continuationParseResult.CaretPositionWithinSelectedSection); IEnumerable <string> completions = ServerPathCompletion.GetCompletions(programState, normalizedCompletionText); if (completions != null) { suggestions.UnionWith(completions); } } return(suggestions.OrderBy(x => x, StringComparer.OrdinalIgnoreCase).ToList()); } } return(null); }
protected override IEnumerable <string> GetArgumentSuggestionsForText(IShellState shellState, HttpState programState, ICoreParseResult parseResult, DefaultCommandInput <ICoreParseResult> commandInput, string normalCompletionString) { return(ServerPathCompletion.GetCompletions(programState, normalCompletionString)); }