public async Task ReadLine_SelectAllAndType_ReplacesEverything() { var console = ConsoleStub.NewConsole(); console.StubInput($"The quick brown fox jumped over the lazy dog{Control}{A}bonk{Enter}"); var prompt = new Prompt(console: console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("bonk", result.Text); }
[InlineData(1)] //triggered different assert failures public async Task FuzzedSelectionAndCompletionAndUndoRedo(int?seed) { seed ??= Guid.NewGuid().GetHashCode(); var r = new Random(seed.Value); var directions = new[] { Home, End, LeftArrow, RightArrow, UpArrow, DownArrow }; var keySet = ( from ctrl in new[] { false, true } from shift in new[] { false, true } from key in directions select key.ToKeyInfo('\0', shift: shift, control: ctrl) ) .Concat(new[] { A.ToKeyInfo('a'), Enter.ToKeyInfo('\0', shift: true), Delete.ToKeyInfo('\0'), Spacebar.ToKeyInfo('\0', control: true), //completion trigger Z.ToKeyInfo('\0', control: true), //undo Y.ToKeyInfo('\0', control: true), //redo }) .ToArray(); var randomKeys = Enumerable.Range(1, 10_000) .Select(_ => keySet[r.Next(keySet.Length)]) .Concat(Enumerable.Repeat(Enter.ToKeyInfo('\0'), 4)) // hit enter a few times to submit the prompt .ToList(); var console = ConsoleStub.NewConsole(); console.StubInput(randomKeys); var prompt = new Prompt( persistentHistoryFilepath: Path.GetTempFileName(), callbacks: new TestPromptCallbacks { CompletionCallback = new CompletionTestData(null).CompletionHandlerAsync }, console: console); try { var result = await prompt.ReadLineAsync(); Assert.NotNull(result); } catch (Exception ex) { throw new InvalidOperationException("Fuzzing failed for seed: " + seed, ex); } }
public void make_coffee() { ConsoleStub.Clear(); var coffee = new Coffee(); coffee.PrepareRecipe(); var allConsole = ConsoleStub.GetAllConsole(); allConsole.ShouldContain("Boiling water"); allConsole.ShouldContain("Dripping Coffee through filter"); allConsole.ShouldContain("Pouring into cup"); allConsole.ShouldContain("Adding Sugar and Milk"); }
public async Task ReadLine_FullyTypeCompletion_CanOpenAgain() { var console = ConsoleStub.NewConsole(); console.StubInput($"Aardvark {Control}{Spacebar}{Enter}{Enter}"); var prompt = ConfigurePrompt(console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal($"Aardvark Aardvark", result.Text); }
public async Task ReadLine_EmptyPrompt_AutoOpens() { var console = ConsoleStub.NewConsole(); console.StubInput($"{Control}{Spacebar}{Enter}{Enter}"); var prompt = ConfigurePrompt(console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal($"Aardvark", result.Text); }
public async Task ReadLine_UpArrow_DoesNotCycleThroughHistory_WhenInMultilineStatement() { var console = ConsoleStub.NewConsole(); var prompt = new Prompt(console: console); console.StubInput($"a{Enter}"); await prompt.ReadLineAsync(); console.StubInput($"{Shift}{Enter}{UpArrow}{UpArrow}{UpArrow}{UpArrow}{UpArrow}b{Enter}"); var result = await prompt.ReadLineAsync(); Assert.Equal($"b{Environment.NewLine}", result.Text); }
public async Task ReadLine_OpenWindowAtBeginningOfPrompt_Opens() { var console = ConsoleStub.NewConsole(); console.StubInput($"a{LeftArrow} {LeftArrow}a{Enter}{Enter}"); var prompt = ConfigurePrompt(console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal($"Ant a", result.Text); }
public async Task ReadLine_UnsubmittedText_IsNotLostWhenChangingHistory() { var console = ConsoleStub.NewConsole(); var prompt = new Prompt(console: console); console.StubInput($"Hello World{Enter}"); await prompt.ReadLineAsync(); console.StubInput($"this prompt is my persistent storage{UpArrow}{DownArrow}{Enter}"); var result = await prompt.ReadLineAsync(); Assert.Equal("this prompt is my persistent storage", result.Text); }
public async Task ReadLine_CompletionWithNoMatches_DoesNotAutoComplete() { var console = ConsoleStub.NewConsole(); console.StubInput($"A{Enter} Q{Enter}"); // first {Enter} selects an autocompletion, second {Enter} submits because there are no completions. var prompt = ConfigurePrompt(console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal($"Ant Q", result.Text); }
public async Task ReadLine_SingleCompletion() { var console = ConsoleStub.NewConsole(); console.StubInput($"Aa{Enter}{Enter}"); var prompt = ConfigurePrompt(console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("Aardvark", result.Text); }
public async Task ReadLine_MultilineCompletion() { var console = ConsoleStub.NewConsole(); console.StubInput($"Aa{Enter}{Shift}{Enter}Z{Control}{Spacebar}{Enter}{Enter}"); var prompt = ConfigurePrompt(console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal($"Aardvark{NewLine}Zebra", result.Text); }
public async Task ReadLine_CompletionMenu_AutoOpens() { var console = ConsoleStub.NewConsole(); console.StubInput($"A{Enter}{Shift}{Enter}Z{Enter}{Enter}"); Prompt prompt = ConfigurePrompt(console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal($"Ant{NewLine}Zebra", result.Text); }
public void make_Tea() { ConsoleStub.Clear(); var coffee = new Tea(); coffee.PrepareRecipe(); var allConsole = ConsoleStub.GetAllConsole(); allConsole.ShouldContain("Boiling water"); allConsole.ShouldContain("Steeping the tea"); allConsole.ShouldContain("Pouring into cup"); allConsole.ShouldContain("Adding Lemon"); }
public void RunAsync_Exception() { // arrange ConsoleStub.Create("1"); // act var result = RunAsync <Startup>(x => { throw new Exception(); }); // assert result.Should().Be(1); }
public async Task ReadLine_Delete_SmartHomeSelection() { var console = ConsoleStub.NewConsole(); var prompt = new Prompt(console: console); console.StubInput( $" abcd{Home}{Home}", //get caret at location 0 $"{Shift}{Home}{Delete}{Enter}" //select first 4 spaces and delete them ); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("abcd", result.Text); }
public async Task ReadLine_HorizontalSelectWordAndType_ReplacesWord() { var console = ConsoleStub.NewConsole(); console.StubInput( $"The quick brown fox jumped over the lazy dog{Control | Shift}{LeftArrow}giraffe", $"{Control}{LeftArrow}{Control}{LeftArrow}{Control | Shift}{RightArrow}enigmatic {Enter}"); var prompt = new Prompt(console: console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("The quick brown fox jumped over the enigmatic giraffe", result.Text); }
public async Task ReadLineAsync_CompletesCJKText_Completes() { var console = ConsoleStub.NewConsole(); console.StubInput($"书{Enter}{Enter}"); var prompt = new Prompt(console: console, callbacks: new TestPromptCallbacks { CompletionCallback = new CompletionTestData("书桌上有").CompletionHandlerAsync }); var result = await prompt.ReadLineAsync(); Assert.Equal("书桌上有", result.Text); }
public async Task ReadLine_MultipleCompletion() { var console = ConsoleStub.NewConsole(); // complete 3 animals. For the third animal, start completing Alligator, but then backspace, navigate the completion menu and complete as Albatross instead. console.StubInput($"Aa{Enter} Z{Tab} Alli{Backspace}{Backspace}{DownArrow}{UpArrow}{DownArrow}{Enter}{Enter}"); var prompt = ConfigurePrompt(console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("Aardvark Zebra Albatross", result.Text); }
public void test_light_on() { ConsoleStub.Clear(); var controller = new SimpleRemoteControl(); var light = new Light(); var lightOnCommand = new LightOnCommand(light); controller.SetCommand(lightOnCommand); controller.ButtonWasPressed(); var allConsole = ConsoleStub.GetAllConsole(); allConsole.ShouldContain("light is on"); }
public async Task ReadLine_Delete_DownSelection() { var console = ConsoleStub.NewConsole(); var prompt = new Prompt(console: console); console.StubInput( $"abcd{Shift}{Enter}", $"efgh", $"{Control}{Home}{RightArrow}{RightArrow}{Shift}{DownArrow}{Delete}{Enter}" ); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("abgh", result.Text); }
public async Task ReadLine_Delete_RightSelection() { //right select all + delete var console = ConsoleStub.NewConsole(); var prompt = new Prompt(console: console); console.StubInput( $"abcd", $"{Home}{Shift}{End}{Delete}{Enter}" ); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("", result.Text); //right select 'b' + delete console.StubInput( $"abcd", $"{Home}{RightArrow}{Shift}{RightArrow}{Delete}{Enter}" ); result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("acd", result.Text); //right select 'bc' + delete console.StubInput( $"abcd", $"{Home}{RightArrow}{Shift}{RightArrow}{Shift}{RightArrow}{Delete}{Enter}" ); result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("ad", result.Text); //right select 'bcd' + delete console.StubInput( $"abcd", $"{Home}{RightArrow}{Shift}{End}{Delete}{Enter}" ); result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("a", result.Text); }
public async Task ReadLine_UndoRedoAndCaretPosition() { for (int i = 1; i <= 4; i++) { var console = ConsoleStub.NewConsole(); var inputs = new List <FormattableString>(); inputs.Add($"abcd"); inputs.AddRange(Enumerable.Repeat <FormattableString>($"{Control}{Z}", i)); inputs.Add($"|"); inputs.Add($"{Enter}"); console.StubInput(inputs.ToArray()); var prompt = new Prompt(console: console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("abcd"[..(4 - i)] + "|", result.Text);
public async Task ReadLine_WriteWordNotInCompletionList_TriggerCompletionList_ShouldNotWriteSpace() { var console = ConsoleStub.NewConsole(); console.StubInput( $"abc", $"{Escape}", //close completion list $"{Control}{Spacebar}", //trigger new one $"{Escape}", //close completion list $"{Enter}"); var prompt = ConfigurePrompt(console, completions: new[] { "aaa" }); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("abc", result.Text); }
public async Task ReadLine_TextOperationsWithUndo_AreUndone() { var console = ConsoleStub.NewConsole(); console.StubInput( $"It's a small world, after all", $"{Control}{LeftArrow}{Control}{LeftArrow}{Control}{LeftArrow}{Control}{LeftArrow}", $"{Control | Shift}{RightArrow}{Delete}", $"{Control}{Z}{Enter}" ); var prompt = new Prompt(console: console); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal("It's a small world, after all", result.Text); }
public async Task ReadLine_HistoryWithTextOnPrompt_FiltersHistory() { var console = ConsoleStub.NewConsole(); var prompt = new Prompt(console: console); console.StubInput($"one{Enter}"); await prompt.ReadLineAsync(); console.StubInput($"two{Enter}"); await prompt.ReadLineAsync(); console.StubInput($"o{UpArrow}{Enter}"); var result = await prompt.ReadLineAsync(); Assert.Equal("one", result.Text); }
public async Task WeakerFilteringMatch() { var console = ConsoleStub.NewConsole(); var prompt = new Prompt(console: console); console.StubInput($"Console.WriteLine(){Enter}"); await prompt.ReadLineAsync(); console.StubInput($"Console.ReadLine(){Enter}"); await prompt.ReadLineAsync(); console.StubInput($"write{UpArrow}{Enter}"); var result = await prompt.ReadLineAsync(); Assert.Equal($"Console.WriteLine()", result.Text); }
public async Task SkipExactMatches() { var console = ConsoleStub.NewConsole(); var prompt = new Prompt(console: console); console.StubInput($"a{Enter}"); await prompt.ReadLineAsync(); console.StubInput($"b{Enter}"); await prompt.ReadLineAsync(); console.StubInput($"b{UpArrow}{Enter}"); var result = await prompt.ReadLineAsync(); Assert.Equal($"a", result.Text); }
public async Task ReadLine_CJKCharacters_SyntaxHighlight() { var format1 = new ConsoleFormat(Foreground: Red); var format2 = new ConsoleFormat(Foreground: Blue); var format3 = new ConsoleFormat(Foreground: Green); var console = ConsoleStub.NewConsole(width: 20); console.StubInput($"苹果 o 蓝莓 o avocado o{Enter}"); var prompt = new Prompt( callbacks: new TestPromptCallbacks { HighlightCallback = new SyntaxHighlighterTestData(new Dictionary <string, AnsiColor> { { "苹果", format1.Foreground !.Value },
public async Task ReadLine_WriteWord_WriteDot_RightSelectDotAndLastLetter_TriggerSelection_ShouldNotOpenCompletionList() { var console = ConsoleStub.NewConsole(); console.StubInput( $"aaa.", $"{LeftArrow}{LeftArrow}{Shift}{RightArrow}{Shift}{RightArrow}", //right select 'a.' $"{Control}{Spacebar}", //try to show completion list (should not open) $"{Enter}"); //submit prompt var prompt = ConfigurePrompt( console, completions: new[] { "aaa", "bbb" }); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal($"aaa.", result.Text); }
public async Task ReadLine_CommitCompletionItemByCharacter_ShouldInsertCompletion_And_InsertPressedCharacter() { foreach (var commitChar in new[] { ' ', '.', '(' }) { var console = ConsoleStub.NewConsole(); console.StubInput( $"ab", $"{commitChar}", //should insert completion $"{Escape}", //to be sure that following Enter won't insert completion $"{Enter}"); //submit prompt var prompt = ConfigurePrompt( console, completions: new[] { "abcd" }, configuration: new PromptConfiguration( keyBindings: new KeyBindings( commitCompletion: new KeyPressPatterns( new(Enter), new(Tab), new(' '), new('.'), new('('))) )); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal($"abcd{commitChar}", result.Text); } foreach (var commitKey in new[] { Tab, Enter }) { var console = ConsoleStub.NewConsole(); console.StubInput( $"ab", $"{commitKey}", //should insert completion $"{Escape}", //to be sure that following Enter won't insert completion $"{Enter}"); //submit prompt var prompt = ConfigurePrompt( console, completions: new[] { "abcd" }, configuration: new PromptConfiguration( keyBindings: new KeyBindings( commitCompletion: new KeyPressPatterns( new(Enter), new(Tab), new(' '), new('.'), new('('))) )); var result = await prompt.ReadLineAsync(); Assert.True(result.IsSuccess); Assert.Equal($"abcd", result.Text); } }