public void DisplayAllCompletions() { const string s = "So"; var console = new SimulatedConsoleOutput(width: 10); const string prompt = "Prompt>"; var completions = new[] { "Some", "somebody", "Something", "soy" }; ConsoleCompletionHandler completionHandler = (tokens, tokenIndex) => completions; var input = CreateInputWithText(console, s, completionHandler); input.Prompt = prompt; input.MoveCursorBackward(1).Should().BeTrue(); input.DisplayAllCompletions(); input.Contents.Should().Be(s); GetContents(console).Replace('\0', ' ').TrimEnd().Should().Be( "So " + "Some " + "somebody " + "Something " + "soy " + prompt + s); console.CursorTop.Should().Be(5); console.CursorLeft.Should().Be(prompt.Length + s.Length - 1); }
private void ReplaceWithAllCompletions(string text, int cursorIndex, IEnumerable <string> textAsTokens, int?expectedCompletionTokenIndex) { var calls = new List <Tuple <List <string>, int> >(); var console = new SimulatedConsoleOutput(); ConsoleCompletionHandler completionHandler = (tokens, tokenIndex) => { calls.Add(Tuple.Create(tokens.ToList(), tokenIndex)); return(Enumerable.Empty <string>()); }; var input = CreateInputWithText(console, text, completionHandler); input.MoveCursorToStart(); input.MoveCursorForward(cursorIndex).Should().BeTrue(); input.ReplaceCurrentTokenWithAllCompletions(); calls.Should().HaveCount(expectedCompletionTokenIndex.HasValue ? 1 : 0); if (expectedCompletionTokenIndex.HasValue) { calls[0].Item1.Should().ContainInOrder(textAsTokens.ToArray()); calls[0].Item2.Should().Be(expectedCompletionTokenIndex.Value); } }
public void DisplayInColumnsWithEmptyList() { var console = new SimulatedConsoleOutput(); var input = CreateInput(console); input.DisplayInColumns(new string[] { }); GetContents(console).Should().BeEmpty(); }
private static ConsoleReader CreateReader(IEnumerable <ConsoleKeyInfo> keyStream, ConsoleCompletionHandler completionHandler = null) { var consoleOutput = new SimulatedConsoleOutput(); var consoleInput = new SimulatedConsoleInput(keyStream); var input = new ConsoleLineInput(consoleOutput, new ConsoleInputBuffer(), new ConsoleHistory(), completionHandler); return(new ConsoleReader(input, consoleInput, consoleOutput, null)); }
private static ConsoleReader CreateReader(IEnumerable <ConsoleKeyInfo> keyStream = null, ConsoleCompletionHandler completionHandler = null) { var consoleOutput = new SimulatedConsoleOutput(); var consoleInput = new SimulatedConsoleInput(keyStream ?? Enumerable.Empty <ConsoleKeyInfo>()); var input = Substitute.For <IConsoleLineInput>(); return(new ConsoleReader(input, consoleInput, consoleOutput, null)); }
public void ReplaceCharAtEnd() { const string s = "Something"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.Invoking(i => i.Replace('X')).Should().Throw <ArgumentOutOfRangeException>(); }
public void InsertStringLongerThanConsoleOutputBuffer() { const string s = "0123456789"; var console = new SimulatedConsoleOutput(width: 4, height: 2); var input = CreateInput(console); input.Invoking(i => i.Insert(s)).Should().Throw <NotImplementedException>(); }
public void TransformWithBogusFunction() { const string s = "Something"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.MoveCursorToStart(); input.Invoking(i => i.TransformCurrentWord(null)).Should().Throw <ArgumentNullException>(); }
public void ReplaceCharAtEnd() { const string s = "Something"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); Action replacement = () => input.Replace('X'); replacement.ShouldThrow <ArgumentOutOfRangeException>(); }
private static ConsoleReader CreateReader(IEnumerable <ConsoleKeyInfo> keyStream, ITokenCompleter tokenCompleter = null) { var consoleOutput = new SimulatedConsoleOutput(); var consoleInput = new SimulatedConsoleInput(keyStream); var input = new ConsoleLineInput(consoleOutput, new ConsoleInputBuffer(), new ConsoleHistory()) { TokenCompleter = tokenCompleter }; return(new ConsoleReader(input, consoleInput, consoleOutput, null)); }
public void InsertStringAcrossLines() { const string s = "012345"; var console = new SimulatedConsoleOutput(width: 4); var input = CreateInput(console); input.Insert(s); input.MoveCursorToEnd(); input.Contents.Should().Be(s); GetContents(console).Should().Be(s); console.CursorTop.Should().Be(1); console.CursorLeft.Should().Be(s.Length - console.BufferWidth); input.MoveCursorBackward(s.Length).Should().BeTrue(); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(0); input.MoveCursorForward(s.Length).Should().BeTrue(); console.CursorTop.Should().Be(1); console.CursorLeft.Should().Be(s.Length - console.BufferWidth); input.MoveCursorToStart(); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(0); for (var index = 0; index < s.Length; ++index) { input.MoveCursorForward(1).Should().BeTrue(); var stringIndex = index + 1; console.CursorTop.Should().Be(stringIndex / console.BufferWidth); console.CursorLeft.Should().Be(stringIndex % console.BufferWidth); } for (var index = 0; index < s.Length; ++index) { input.MoveCursorBackward(1).Should().BeTrue(); var stringIndex = s.Length - (index + 1); console.CursorTop.Should().Be(stringIndex / console.BufferWidth); console.CursorLeft.Should().Be(stringIndex % console.BufferWidth); } input.MoveCursorForward(3).Should().BeTrue(); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(3); input.MoveCursorForward(3).Should().BeTrue(); input.AtEnd.Should().BeTrue(); console.CursorTop.Should().Be(1); console.CursorLeft.Should().Be(2); }
public void DisplayInColumns() { var console = new SimulatedConsoleOutput(width: 12); var input = CreateInput(console); input.DisplayInColumns(new[] { "abcd", "ef", "ghi", "j", "klmn" }); GetContents(console).Replace('\0', ' ').TrimEnd().Should().Be( "abcd j " + "ef klmn " + "ghi"); }
public void DeleteFromEnd() { const string s = "something"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.Delete(); GetContents(console).Should().Be(s); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(s.Length); }
public void DisplayInColumnsWithTextWiderThanConsole() { var console = new SimulatedConsoleOutput(width: 8); var input = CreateInput(console); input.DisplayInColumns(new[] { "Shorter", "LongEnough", "x" }); GetContents(console).Replace('\0', ' ').TrimEnd().Should().Be( "Shorter " + "LongEnou" + "gh " + "x"); }
public void MoveBackOneWordWithOnlyWhitespace() { const string s = " "; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.MoveCursorBackwardOneWord(); input.Contents.Should().Be(s); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(0); }
public void ReplaceWithAllCompletionsButNoCompletions() { var console = new SimulatedConsoleOutput(); ConsoleCompletionHandler completionHandler = (tokens, tokenIndex) => Enumerable.Empty <string>(); var input = CreateInput(console, completionHandler); input.ReplaceCurrentTokenWithAllCompletions(); input.Contents.Should().BeEmpty(); GetContents(console).Should().BeEmpty(); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(0); }
public void Backspace() { const string s = "something"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.DeletePrecedingChar(); input.Contents.Should().Be("somethin"); GetContents(console).TrimEnd().Should().Be("somethin"); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(s.Length - 1); }
public void ReplaceWithNextCompletionWithNoCompletionHandler() { const string s = "Something"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.ReplaceCurrentTokenWithNextCompletion(false); input.Contents.Should().Be(s); GetContents(console).Should().Be(s); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(s.Length); }
public void PasteWhenBufferIsNull() { const string s = "Something"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.Paste(); input.Contents.Should().Be(s); GetContents(console).Should().Be(s); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(s.Length); }
public void ClearBufferOnlyFromEnd() { const string s = "Hello world"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.ClearLine(true); input.Contents.Should().BeEmpty(); GetContents(console).Should().Be(s); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(s.Length); }
public void DeleteBackOneWordThroughWhitespace() { const string s = " "; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.DeleteBackwardThroughLastWord(); input.Contents.Should().BeEmpty(); GetContents(console).TrimEnd().Should().BeEmpty(); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(0); }
public void ReplaceWithPreviousCompletionEncountersEmptyString() { const string text = "S"; string[] completions = { "S", string.Empty, "szy" }; var console = new SimulatedConsoleOutput(); ConsoleCompletionHandler completionHandler = (tokens, index) => completions; var input = CreateInputWithText(console, text, completionHandler); ValidateCompletion(input, 1, true, false, "szy"); ValidateCompletion(input, null, true, true, StringUtilities.QuoteIfNeeded(string.Empty)); ValidateCompletion(input, null, true, true, "S"); }
public void ReplaceWithPreviousCompletionWithNoCompletions() { const string s = "Something"; var console = new SimulatedConsoleOutput(); ConsoleCompletionHandler completionHandler = (tokens, index) => Enumerable.Empty <string>(); var input = CreateInputWithText(console, s, completionHandler); input.ReplaceCurrentTokenWithPreviousCompletion(false); input.Contents.Should().Be(s); GetContents(console).Should().Be(s); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(s.Length); }
public void ReplaceWithNextCompletionWithNoCompletions() { const string s = "Something"; var console = new SimulatedConsoleOutput(); var tokenCompleter = new TestTokenCompleter(Enumerable.Empty <string>()); var input = CreateInputWithText(console, s, tokenCompleter); input.ReplaceCurrentTokenWithNextCompletion(false); input.Contents.Should().Be(s); GetContents(console).Should().Be(s); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(s.Length); }
public void ReplaceWithNextCompletionEncountersEmptyString() { const string text = "S"; string[] completions = { "S", string.Empty, "szy" }; var console = new SimulatedConsoleOutput(); var tokenCompleter = new TestTokenCompleter(completions); var input = CreateInputWithText(console, text, tokenCompleter); ValidateCompletion(input, 1, false, false, "S"); ValidateCompletion(input, null, false, true, StringUtilities.QuoteIfNeeded(string.Empty)); ValidateCompletion(input, null, false, true, "szy"); }
public void CutFromEndToEnd() { const string s = "Something"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.CutToEnd(); input.PasteBuffer.Should().BeEmpty(); input.Contents.Should().Be(s); GetContents(console).Should().Be(s); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(s.Length); }
public void MoveForwardOneChar() { const string s = "something"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.MoveCursorBackward(1).Should().BeTrue(); input.MoveCursorForward(1).Should().BeTrue(); input.Contents.Should().Be(s); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(s.Length); input.MoveCursorForward(1).Should().BeFalse(); }
public void InsertStringIntoEmptyBuffer() { var console = new SimulatedConsoleOutput(); var input = CreateInput(console); input.Contents.Should().BeEmpty(); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(0); input.Insert("cd"); input.Contents.Should().Be("cd"); GetContents(console).Should().Be("cd"); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(0); }
public void ClearLineAndBufferFromMiddle() { const string s = "Hello world"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.MoveCursorBackwardOneWord(); input.ClearLine(false); input.Contents.Should().BeEmpty(); GetContents(console).TrimEnd().Should().BeEmpty(); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(0); }
public void BackspaceFromBeginning() { const string s = "something"; var console = new SimulatedConsoleOutput(); var input = CreateInputWithText(console, s); input.MoveCursorToStart(); input.DeletePrecedingChar(); input.Contents.Should().Be(s); GetContents(console).Should().Be(s); console.CursorTop.Should().Be(0); console.CursorLeft.Should().Be(0); }
private static ConsoleReader CreateReader(IEnumerable<ConsoleKeyInfo> keyStream, ConsoleCompletionHandler completionHandler = null) { var consoleOutput = new SimulatedConsoleOutput(); var consoleInput = new SimulatedConsoleInput(keyStream); var input = new ConsoleLineInput(consoleOutput, new ConsoleInputBuffer(), new ConsoleHistory(), completionHandler); return new ConsoleReader(input, consoleInput, consoleOutput, null); }