Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        public void DisplayInColumnsWithEmptyList()
        {
            var console = new SimulatedConsoleOutput();
            var input   = CreateInput(console);

            input.DisplayInColumns(new string[] { });
            GetContents(console).Should().BeEmpty();
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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>();
        }
Exemplo n.º 7
0
        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>();
        }
Exemplo n.º 8
0
        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>();
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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");
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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");
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
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");
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        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");
        }
Exemplo n.º 26
0
        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);
        }
Exemplo n.º 27
0
        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();
        }
Exemplo n.º 28
0
        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);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
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);
        }
Exemplo n.º 31
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);
 }