public async Task Should_return_valid_completion_for_empty_line() { // Arrange AutoCompleteInput input = GetAutoCompleteInstance(); // Act string text = await input.ReadLineAsync(Tab); // Assert text.Should().Be("World"); // Act text = await input.ReadLineAsync(Tab, Tab); // Assert text.Should().Be("Angel"); // Act text = await input.ReadLineAsync(Tab, Tab, Tab); // Assert text.Should().Be("Hello"); // Act text = await input.ReadLineAsync(Tab, Tab, Tab, Tab); // Assert text.Should().Be("World"); // Act text = await input.ReadLineAsync(Tab, Tab, Tab, Tab, ShiftTab); // Assert text.Should().Be("Hello"); }
public async Task Nothing_should_happen_when_no_completions_available() { // Arrange AutoCompleteInput input = GetAutoCompleteInstance(); // Act string text = await input.ReadLineAsync('X'.ToConsoleKeyInfo(), Tab); // Assert text.Should().Be("X"); }
public async Task Should_return_valid_completion_for_W_Tab() { // Arrange AutoCompleteInput input = GetAutoCompleteInstance(); // Act string text = await input.ReadLineAsync('W'.ToConsoleKeyInfo(), Tab); // Assert text.Should().Be("World"); }
public async Task Up_arrow_then_escape_should_return_empty() { // Arrange AutoCompleteInput input = GetAutoCompleteInstance(); // Act string text = await input.ReadLineAsync(UpArrow, Escape, DownArrow, Enter); // Assert text.Should().BeEmpty(); }
public void Down_arrow_should_return_empty() { // Arrange AutoCompleteInput input = GetAutoCompleteInstance(); // Act string text = input.ReadLine(DownArrow, Enter); // Assert text.Should().BeEmpty(); }
public void Should_add_single_item_to_empty_history() { // Arrange AutoCompleteInput input = new AutoCompleteInput(new SystemConsole()); InputHistoryProvider history = input.History; history.IsEnabled = true; // Act history.AddEntries("mkdir"); // Assert history.GetEntries().Should().Equal(new string[] { "mkdir" }); }
public void Should_add_collection_to_history() { // Arrange AutoCompleteInput input = new AutoCompleteInput(new SystemConsole()); InputHistoryProvider history = input.History; history.IsEnabled = true; // Act history.AddEntries(_history); // Assert history.GetEntries().Should().Equal(_history); }
private AutoCompleteInput GetAutoCompleteInstance() { // Arrange AutoCompleteInput instance = new AutoCompleteInput(_console) { AutoCompletionHandler = new TestAutoCompleteHandler() }; // History should be disabled by default. instance.History.IsEnabled.Should().BeFalse(); instance.History.IsEnabled = true; instance.History.IsEnabled.Should().BeTrue(); instance.History.AddEntries(_history); return(instance); }
public void Nothing_should_happen_without_auto_complete_handler() { // Arrange AutoCompleteInput input = new AutoCompleteInput(_console); // Act string text = input.ReadLine(Tab, Enter); // Assert text.Should().BeEmpty(); // Act text = input.ReadLine(Tab, Tab, Tab); // Assert text.Should().BeEmpty(); }
public async Task Up_then_down_arrow_should_return_last_history_entry() { // Arrange AutoCompleteInput input = GetAutoCompleteInstance(); // Act string text = await input.ReadLineAsync(UpArrow, DownArrow, Enter); // Assert text.Should().Be("clear"); // Act text = await input.ReadLineAsync(UpArrow, DownArrow, DownArrow, DownArrow, Enter); // Assert text.Should().Be("clear"); }
public async Task Up_arrow_should_return_valid_entry() { // Arrange AutoCompleteInput input = GetAutoCompleteInstance(); // Act string text = await input.ReadLineAsync(UpArrow, UpArrow, UpArrow); // Assert text.Should().Be("dotnet run"); // Act text = await input.ReadLineAsync(UpArrow, UpArrow, UpArrow, UpArrow, UpArrow, Enter); // Assert text.Should().Be("dotnet run"); }
public void Duplicated_custom_shortcut_should_throw_exception() { // Arrange Action act = () => { AutoCompleteInput input = new AutoCompleteInput(_console, new HashSet <ShortcutDefinition> { new ShortcutDefinition(ConsoleKey.A, ConsoleModifiers.Control, () => { }), new ShortcutDefinition(ConsoleKey.Delete, () => { }), }) { AutoCompletionHandler = new TestAutoCompleteHandler() }; }; // Assert act.Should().Throw <TypinException>(); }
public async Task Should_clear_history() { // Arrange AutoCompleteInput input = GetAutoCompleteInstance(); // Act string text = await input.ReadLineAsync(UpArrow, UpArrow, UpArrow, Enter); // Assert text.Should().Be("dotnet run"); // Act input.History.Clear(); text = await input.ReadLineAsync(UpArrow, UpArrow, UpArrow, UpArrow, UpArrow, Enter); // Assert text.Should().BeEmpty(); }
public void Should_clear_history() { // Arrange AutoCompleteInput input = new AutoCompleteInput(new SystemConsole()); InputHistoryProvider history = input.History; history.IsEnabled = true; // Act history.AddEntries(_history); // Assert history.GetEntries().Count.Should().Be(3); // Act history.Clear(); // Assert history.GetEntries().Count.Should().Be(0); }
public void Should_add_single_item_to_history() { // Arrange AutoCompleteInput input = new AutoCompleteInput(new SystemConsole()); InputHistoryProvider history = input.History; history.IsEnabled = true; // Act history.AddEntries(_history); // Assert history.GetEntries().Should().Equal(_history); // Act history.AddEntries("mkdir"); // Assert history.GetEntries().Should().ContainInOrder(_history); history.GetEntries().Last().Should().Be("mkdir"); }
public void Should_add_after_history_clearing() { // Arrange AutoCompleteInput input = new AutoCompleteInput(new SystemConsole()); InputHistoryProvider history = input.History; history.IsEnabled = true; // Act history.AddEntries(_history); history.Clear(); // Assert history.GetEntries().Count.Should().Be(0); // Act history.AddEntries("mkdir"); // Assert history.GetEntries().Should().Equal(new string[] { "mkdir" }); }
public AutoCompleteSuggestions AutoComplete(AutoCompleteInput input) { //TODO: waiting for Exposure of Completion API https://github.com/dotnet/roslyn/issues/3538 // var workspace = new AdhocWorkspace(); // string projName = "Console"; // var projectId = ProjectId.CreateNewId(); // var versionStamp = VersionStamp.Create(); // var projectInfo = ProjectInfo.Create(projectId, versionStamp, projName, projName, input.Language== Language.CSharp? LanguageNames.CSharp: LanguageNames.VisualBasic); // var newProject = workspace.AddProject(projectInfo); // var sourceText = SourceText.From(input.Code); // var newDocument = workspace.AddDocument(newProject.Id, "Main." + (input.Language == Language.CSharp ? ".cs" : ".vb"), sourceText); // var completionService = newDocument.GetLanguageService<ICompletionService>(); // foreach (var symbol in symbols.Where(s => s.Name.IsValidCompletionFor(wordToComplete))) // { // if (request.WantSnippet) // { // foreach (var completion in MakeSnippetedResponses(request, symbol)) // { // _completions.Add(completion); // } // } // else // { // _completions.Add(MakeAutoCompleteResponse(request, symbol)); // } // } //} //return _completions // .OrderByDescending(c => c.CompletionText.IsValidCompletionStartsWithExactCase(wordToComplete)) // .ThenByDescending(c => c.CompletionText.IsValidCompletionStartsWithIgnoreCase(wordToComplete)) // .ThenByDescending(c => c.CompletionText.IsCamelCaseMatch(wordToComplete)) // .ThenByDescending(c => c.CompletionText.IsSubsequenceMatch(wordToComplete)) // .ThenBy(c => c.CompletionText); throw new NotImplementedException(); }
public void Should_return_valid_completion_for_Tab_and_ShiftTab() { // Arrange AutoCompleteInput input = GetAutoCompleteInstance(); // Act string text = input.ReadLine(ShiftTab); // Assert text.Should().Be("Hello"); // Act text = input.ReadLine(Tab); // Assert text.Should().Be("World"); // Act text = input.ReadLine(Tab, ShiftTab); // Assert text.Should().Be("Hello"); }
public void Custom_shortcut_should_work() { bool test = false; // Arrange AutoCompleteInput input = new AutoCompleteInput(_console, new HashSet <ShortcutDefinition> { new ShortcutDefinition(ConsoleKey.A, ConsoleModifiers.Control, () => { test = true; }), new ShortcutDefinition(ConsoleKey.B, ConsoleModifiers.Control, () => { test = true; }), new ShortcutDefinition(ConsoleKey.B, () => { test = true; }), }) { AutoCompletionHandler = new TestAutoCompleteHandler() }; // History should be disabled by default. test.Should().BeFalse(); // Act string text = input.ReadLine(CtrlA); // Assert test.Should().BeTrue(); }