private void ReplaceWithAllCompletions(string text, int cursorIndex, IEnumerable <string> textAsTokens, int?expectedCompletionTokenIndex)
        {
            var calls = new List <Tuple <List <string>, int> >();

            var             console        = new SimulatedConsoleOutput();
            ITokenCompleter tokenCompleter = new TestTokenCompleter((tokens, tokenIndex) =>
            {
                calls.Add(Tuple.Create(tokens.ToList(), tokenIndex));
                return(Enumerable.Empty <string>());
            });

            var input = CreateInputWithText(console, text, tokenCompleter);

            input.MoveCursorToStart();
            input.MoveCursorForward(cursorIndex).Should().BeTrue();

            input.ReplaceCurrentTokenWithAllCompletions();

            calls.Should().HaveCount(expectedCompletionTokenIndex.HasValue ? 1 : 0);

            if (expectedCompletionTokenIndex.HasValue)
            {
                calls[0].Item1.Should().Equal(textAsTokens.ToArray());
                calls[0].Item2.Should().Be(expectedCompletionTokenIndex.Value);
            }
        }
        public void Completion()
        {
            var completions    = new[] { "Hello there", "Hello, world!" };
            var tokenCompleter = new TestTokenCompleter(completions);

            Process(
                tokenCompleter,
                "hello".AsKeys(),
                ConsoleKey.Home.AsInfo(),
                ConsoleKey.Tab.WithShift())
            .Should().Be("\"Hello, world!\"");

            Process(
                tokenCompleter,
                "hello".AsKeys(),
                ConsoleKey.Home.AsInfo(),
                ConsoleKey.Tab.AsInfo())
            .Should().Be("\"Hello there\"");

            Process(
                tokenCompleter,
                "hello".AsKeys(),
                ConsoleKey.Oem2.WithAlt().WithShift())
            .Should().Be("hello");

            Process(
                tokenCompleter,
                "hello".AsKeys(),
                ConsoleKey.D8.WithAlt().WithShift())
            .Should().Be("\"Hello there\" \"Hello, world!\" ");
        }
        public void DisplayAllCompletions()
        {
            const string s       = "So";
            var          console = new SimulatedConsoleOutput(width: 10);
            const string prompt  = "Prompt>";

            var             completions    = new[] { "Some", "somebody", "Something", "soy" };
            ITokenCompleter tokenCompleter = new TestTokenCompleter(completions);

            var input = CreateInputWithText(console, s, tokenCompleter);

            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);
        }
Beispiel #4
0
        public void UntokenizableString()
        {
            const string text = "\"s\"x\"";

            ITokenCompleter tokenCompleter = new TestTokenCompleter((tokens, index) => Enumerable.Empty <string>());
            var             set            = TokenCompletionSet.Create(text, 0, tokenCompleter);

            set.InputText.Should().Be(text);
            set.Completions.Should().BeEmpty();
            set.Count.Should().Be(0);
            set.Empty.Should().BeTrue();
        }
        public void ReplaceWithAllCompletionsButNoCompletions()
        {
            var console        = new SimulatedConsoleOutput();
            var tokenCompleter = new TestTokenCompleter(Enumerable.Empty <string>());
            var input          = CreateInput(console, tokenCompleter);

            input.ReplaceCurrentTokenWithAllCompletions();
            input.Contents.Should().BeEmpty();
            GetContents(console).Should().BeEmpty();
            console.CursorTop.Should().Be(0);
            console.CursorLeft.Should().Be(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);
        }
        public void ReplaceWithPreviousCompletionEncountersEmptyString()
        {
            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, true, false, "szy");
            ValidateCompletion(input, null, true, true, StringUtilities.QuoteIfNeeded(string.Empty));
            ValidateCompletion(input, null, true, true, "S");
        }
        public void DisplayAllCompletionsWithNoCompletions()
        {
            const string s       = "Hello world something";
            var          console = new SimulatedConsoleOutput(width: 10);

            ITokenCompleter tokenCompleter = new TestTokenCompleter(Enumerable.Empty <string>());

            var input = CreateInputWithText(console, s, tokenCompleter);
            var previousConsoleContents = GetContents(console);

            input.DisplayAllCompletions();

            input.Contents.Should().Be(s);
            GetContents(console).Should().Be(previousConsoleContents);
        }
Beispiel #9
0
        public void SimpleStringWithCompletions()
        {
            const string text = "a b";

            var             completions    = new[] { "abc", "aZx" };
            ITokenCompleter tokenCompleter = new TestTokenCompleter((tokens, index) => completions);

            var set = TokenCompletionSet.Create(text, 0, tokenCompleter);

            set.InputText.Should().Be(text);
            set.Completions.Should().HaveCount(2);
            set.Count.Should().Be(2);
            set.Empty.Should().BeFalse();
            set[0].Should().Be("abc");
            set[1].Should().Be("aZx");
        }
        public void ReplaceWithNextCompletion()
        {
            const string text = "S";

            string[] completions = { "S", "Sa", "sc", "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, "Sa");

            ValidateCompletion(input, null, false, false, "S");
            ValidateCompletion(input, null, false, true, "Sa");
            ValidateCompletion(input, null, false, true, "sc");
            ValidateCompletion(input, null, false, true, "szy");
            ValidateCompletion(input, null, false, true, "S");
        }
        public void ReplaceWithAllCompletionsAtEnd()
        {
            var console        = new SimulatedConsoleOutput();
            var completions    = new[] { "abcd", "aXYZ", "aw | i" };
            var tokenCompleter = new TestTokenCompleter(completions);
            var input          = CreateInput(console, tokenCompleter);

            input.Insert("a");
            input.MoveCursorToEnd();

            var completionsAsText = string.Join(" ", completions.Select(c => StringUtilities.QuoteIfNeeded(c, '\"'))) + " ";

            input.ReplaceCurrentTokenWithAllCompletions();

            input.Contents.Should().Be(completionsAsText);
            GetContents(console).Should().Be(completionsAsText);
            console.CursorTop.Should().Be(0);
            console.CursorLeft.Should().Be(completionsAsText.Length);
        }