public async Task getCompletionSuggestions_execute_simulation_partial() { var execute = _subject.Register(r => r.Literal("execute")); _subject.Register(r => r.Literal("execute") .Then( r.Literal("as") .Then(r.Literal("bar").Redirect(execute)) .Then(r.Literal("baz").Redirect(execute)) ) .Then( r.Literal("store") .Then( r.Argument("name", Arguments.Word()) .Redirect(execute) ) ) .Then( r.Literal("run").Executes(e => 0) ) ); var parse = _subject.Parse("execute as bar as ", _source); var result = await _subject.GetCompletionSuggestions(parse); result.Range.Should().BeEquivalentTo(StringRange.At(18)); result.List.Should().BeEquivalentTo(new List <Suggestion.Suggestion> { new Suggestion.Suggestion(StringRange.At(18), "bar"), new Suggestion.Suggestion(StringRange.At(18), "baz") }); }
public void merge_single() { var suggestions = new Suggestions(StringRange.At(5), new List <Suggestion.Suggestion> { new Suggestion.Suggestion(StringRange.At(5), "ar") }); var merged = Suggestions.Merge("foo b", new List <Suggestions> { suggestions }); merged.Should().BeEquivalentTo(suggestions); }
public async Task getCompletionSuggestions_rootCommands_withInputOffset() { _subject.Register(r => r.Literal("foo")); _subject.Register(r => r.Literal("bar")); _subject.Register(r => r.Literal("baz")); var result = await _subject.GetCompletionSuggestions(_subject.Parse(InputWithOffset("OOO", 3), _source)); result.Range.Should().BeEquivalentTo(StringRange.At(3)); result.List.Should().BeEquivalentTo(new List <Suggestion.Suggestion> { new Suggestion.Suggestion(StringRange.At(3), "bar"), new Suggestion.Suggestion(StringRange.At(3), "baz"), new Suggestion.Suggestion(StringRange.At(3), "foo") }); }
public async Task getCompletionSuggestions_redirect() { var actual = _subject.Register(r => r.Literal("actual").Then(r.Literal("sub"))); _subject.Register(r => r.Literal("redirect").Redirect(actual)); var parse = _subject.Parse("redirect ", _source); var result = await _subject.GetCompletionSuggestions(parse); result.Range.Should().BeEquivalentTo(StringRange.At(9)); result.List.Should().BeEquivalentTo(new List <Suggestion.Suggestion> { new Suggestion.Suggestion(StringRange.At(9), "sub") }); }
public void merge_multiple() { var a = new Suggestions(StringRange.At(5), new List <Suggestion.Suggestion> { new Suggestion.Suggestion(StringRange.At(5), "ar"), new Suggestion.Suggestion(StringRange.At(5), "az"), new Suggestion.Suggestion(StringRange.At(5), "Az") }); var b = new Suggestions(StringRange.Between(4, 5), new List <Suggestion.Suggestion> { new Suggestion.Suggestion(StringRange.Between(4, 5), "foo"), new Suggestion.Suggestion(StringRange.Between(4, 5), "qux"), new Suggestion.Suggestion(StringRange.Between(4, 5), "apple"), new Suggestion.Suggestion(StringRange.Between(4, 5), "Bar") }); var merged = Suggestions.Merge("foo b", new List <Suggestions> { a, b }); merged.List.Should().BeEquivalentTo(new List <Suggestion.Suggestion> { new Suggestion.Suggestion(StringRange.Between(4, 5), "apple"), new Suggestion.Suggestion(StringRange.Between(4, 5), "bar"), new Suggestion.Suggestion(StringRange.Between(4, 5), "Bar"), new Suggestion.Suggestion(StringRange.Between(4, 5), "baz"), new Suggestion.Suggestion(StringRange.Between(4, 5), "bAz"), new Suggestion.Suggestion(StringRange.Between(4, 5), "foo"), new Suggestion.Suggestion(StringRange.Between(4, 5), "qux") }); }
public async Task getCompletionSuggestions_SubCommands() { _subject.Register(r => r.Literal("parent") .Then(r.Literal("foo")) .Then(r.Literal("bar")) .Then(r.Literal("baz")) ); var result = await _subject.GetCompletionSuggestions(_subject.Parse("parent ", _source)); result.Range.Should().BeEquivalentTo(StringRange.At(7)); result.List.Should().BeEquivalentTo(new List <Suggestion.Suggestion> { new Suggestion.Suggestion(StringRange.At(7), "bar"), new Suggestion.Suggestion(StringRange.At(7), "baz"), new Suggestion.Suggestion(StringRange.At(7), "foo") }); }
public async Task TestSuggestions() { var empty = await _node.ListSuggestions(_contextBuilder.Build(""), new SuggestionsBuilder("", 0)); empty.List.Should().BeEquivalentTo(new List <Suggestion.Suggestion> { new Suggestion.Suggestion(StringRange.At(0), "foo") }); var foo = await _node.ListSuggestions(_contextBuilder.Build("foo"), new SuggestionsBuilder("foo", 0)); foo.IsEmpty().Should().Be(true); var food = await _node.ListSuggestions(_contextBuilder.Build("food"), new SuggestionsBuilder("food", 0)); food.IsEmpty().Should().Be(true); var b = await _node.ListSuggestions(_contextBuilder.Build("b"), new SuggestionsBuilder("b", 0)); b.IsEmpty().Should().Be(true); }
public async Task getCompletionSuggestions_redirect_lots() { var loop = _subject.Register(r => r.Literal("redirect")); _subject.Register(r => r.Literal("redirect") .Then( r.Literal("loop") .Then( r.Argument("loop", Arguments.Integer()) .Redirect(loop) ) ) ); var result = await _subject.GetCompletionSuggestions(_subject.Parse("redirect loop 1 loop 02 loop 003 ", _source)); result.Range.Should().BeEquivalentTo(StringRange.At(33)); result.List.Should().BeEquivalentTo(new List <Suggestion.Suggestion> { new Suggestion.Suggestion(StringRange.At(33), "loop") }); }
public async Task getCompletionSuggestions_movingCursor_redirect() { var actualOne = _subject.Register(r => r.Literal("actual_one") .Then(r.Literal("faz")) .Then(r.Literal("fbz")) .Then(r.Literal("gaz")) ); _subject.Register(r => r.Literal("actual_two")); _subject.Register(r => r.Literal("redirect_one").Redirect(actualOne)); _subject.Register(r => r.Literal("redirect_two").Redirect(actualOne)); await TestSuggestions("redirect_one faz ", 0, StringRange.At(0), "actual_one", "actual_two", "redirect_one", "redirect_two"); await TestSuggestions("redirect_one faz ", 9, StringRange.Between(0, 9), "redirect_one", "redirect_two"); await TestSuggestions("redirect_one faz ", 10, StringRange.Between(0, 10), "redirect_one"); await TestSuggestions("redirect_one faz ", 12, StringRange.At(0)); await TestSuggestions("redirect_one faz ", 13, StringRange.At(13), "faz", "fbz", "gaz"); await TestSuggestions("redirect_one faz ", 14, StringRange.Between(13, 14), "faz", "fbz"); await TestSuggestions("redirect_one faz ", 15, StringRange.Between(13, 15), "faz"); await TestSuggestions("redirect_one faz ", 16, StringRange.At(0)); await TestSuggestions("redirect_one faz ", 17, StringRange.At(0)); }
public async Task getCompletionSuggestions_movingCursor_SubCommands() { _subject.Register(r => r.Literal("parent_one") .Then(r.Literal("faz")) .Then(r.Literal("fbz")) .Then(r.Literal("gaz")) ); _subject.Register(r => r.Literal("parent_two") ); await TestSuggestions("parent_one faz ", 0, StringRange.At(0), "parent_one", "parent_two"); await TestSuggestions("parent_one faz ", 1, StringRange.Between(0, 1), "parent_one", "parent_two"); await TestSuggestions("parent_one faz ", 7, StringRange.Between(0, 7), "parent_one", "parent_two"); await TestSuggestions("parent_one faz ", 8, StringRange.Between(0, 8), "parent_one"); await TestSuggestions("parent_one faz ", 10, StringRange.At(0)); await TestSuggestions("parent_one faz ", 11, StringRange.At(11), "faz", "fbz", "gaz"); await TestSuggestions("parent_one faz ", 12, StringRange.Between(11, 12), "faz", "fbz"); await TestSuggestions("parent_one faz ", 13, StringRange.Between(11, 13), "faz"); await TestSuggestions("parent_one faz ", 14, StringRange.At(0)); await TestSuggestions("parent_one faz ", 15, StringRange.At(0)); }
public void apply_insertion_middle() { var suggestion = new Suggestion.Suggestion(StringRange.At(6), "small "); suggestion.Apply("Hello world!").Should().BeEquivalentTo("Hello small world!"); }
public void expand_both() { var suggestion = new Suggestion.Suggestion(StringRange.At(11), "minecraft:"); suggestion.Expand("give Steve fish_block", StringRange.Between(5, 21)).Should().BeEquivalentTo(new Suggestion.Suggestion(StringRange.Between(5, 21), "Steve minecraft:fish_block")); }
public void expand_right() { var suggestion = new Suggestion.Suggestion(StringRange.At(0), "minecraft:"); suggestion.Expand("fish", StringRange.Between(0, 4)).Should().BeEquivalentTo(new Suggestion.Suggestion(StringRange.Between(0, 4), "minecraft:fish")); }
public void expand_left() { var suggestion = new Suggestion.Suggestion(StringRange.At(1), "oo"); suggestion.Expand("f", StringRange.Between(0, 1)).Should().BeEquivalentTo(new Suggestion.Suggestion(StringRange.Between(0, 1), "foo")); }
public void expand_unchanged() { var suggestion = new Suggestion.Suggestion(StringRange.At(1), "oo"); suggestion.Expand("f", StringRange.At(1)).Should().BeEquivalentTo(suggestion); }
public void apply_insertion_end() { var suggestion = new Suggestion.Suggestion(StringRange.At(5), " world!"); suggestion.Apply("Hello").Should().BeEquivalentTo("Hello world!"); }
public void apply_insertion_start() { var suggestion = new Suggestion.Suggestion(StringRange.At(0), "And so I said: "); suggestion.Apply("Hello world!").Should().BeEquivalentTo("And so I said: Hello world!"); }