@jsprismarine/brigadier 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +57 -39
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/AmbiguityConsumer.js +0 -0
- package/dist/lib/AmbiguityConsumer.js.map +0 -0
- package/dist/lib/Command.js +0 -0
- package/dist/lib/Command.js.map +0 -0
- package/dist/lib/CommandDispatcher.js +45 -28
- package/dist/lib/CommandDispatcher.js.map +1 -1
- package/dist/lib/ImmutableStringReader.js +0 -0
- package/dist/lib/ImmutableStringReader.js.map +0 -0
- package/dist/lib/LiteralMessage.js +0 -0
- package/dist/lib/LiteralMessage.js.map +0 -0
- package/dist/lib/Message.js +0 -0
- package/dist/lib/Message.js.map +0 -0
- package/dist/lib/ParseResults.js +0 -0
- package/dist/lib/ParseResults.js.map +0 -0
- package/dist/lib/Predicate.js +0 -0
- package/dist/lib/Predicate.js.map +0 -0
- package/dist/lib/RedirectModifier.js +0 -0
- package/dist/lib/RedirectModifier.js.map +0 -0
- package/dist/lib/ResultConsumer.js +0 -0
- package/dist/lib/ResultConsumer.js.map +0 -0
- package/dist/lib/SingleRedirectModifier.js +0 -0
- package/dist/lib/SingleRedirectModifier.js.map +0 -0
- package/dist/lib/StringReader.js +0 -0
- package/dist/lib/StringReader.js.map +0 -0
- package/dist/lib/arguments/ArgumentType.js +1 -1
- package/dist/lib/arguments/ArgumentType.js.map +1 -1
- package/dist/lib/arguments/BoolArgumentType.js +0 -0
- package/dist/lib/arguments/BoolArgumentType.js.map +0 -0
- package/dist/lib/arguments/FloatArgumentType.js +0 -0
- package/dist/lib/arguments/FloatArgumentType.js.map +0 -0
- package/dist/lib/arguments/IntegerArgumentType.js +0 -0
- package/dist/lib/arguments/IntegerArgumentType.js.map +0 -0
- package/dist/lib/arguments/StringArgumentType.js +0 -0
- package/dist/lib/arguments/StringArgumentType.js.map +0 -0
- package/dist/lib/builder/ArgumentBuilder.js +0 -0
- package/dist/lib/builder/ArgumentBuilder.js.map +0 -0
- package/dist/lib/builder/LiteralArgumentBuilder.js +0 -0
- package/dist/lib/builder/LiteralArgumentBuilder.js.map +1 -1
- package/dist/lib/builder/RequiredArgumentBuilder.js +0 -0
- package/dist/lib/builder/RequiredArgumentBuilder.js.map +1 -1
- package/dist/lib/context/CommandContext.js +4 -4
- package/dist/lib/context/CommandContext.js.map +1 -1
- package/dist/lib/context/CommandContextBuilder.js +0 -0
- package/dist/lib/context/CommandContextBuilder.js.map +0 -0
- package/dist/lib/context/ParsedArgument.js +0 -0
- package/dist/lib/context/ParsedArgument.js.map +0 -0
- package/dist/lib/context/ParsedCommandNode.js +0 -0
- package/dist/lib/context/ParsedCommandNode.js.map +0 -0
- package/dist/lib/context/StringRange.js +0 -0
- package/dist/lib/context/StringRange.js.map +0 -0
- package/dist/lib/context/SuggestionContext.js +0 -0
- package/dist/lib/context/SuggestionContext.js.map +0 -0
- package/dist/lib/exceptions/BuiltInExceptionProvider.js +0 -0
- package/dist/lib/exceptions/BuiltInExceptionProvider.js.map +0 -0
- package/dist/lib/exceptions/BuiltInExceptions.js +0 -0
- package/dist/lib/exceptions/BuiltInExceptions.js.map +0 -0
- package/dist/lib/exceptions/CommandExceptionType.js +0 -0
- package/dist/lib/exceptions/CommandExceptionType.js.map +0 -0
- package/dist/lib/exceptions/CommandSyntaxException.js +0 -0
- package/dist/lib/exceptions/CommandSyntaxException.js.map +0 -0
- package/dist/lib/exceptions/DynamicCommandExceptionType.js +0 -0
- package/dist/lib/exceptions/DynamicCommandExceptionType.js.map +0 -0
- package/dist/lib/exceptions/SimpleCommandExceptionType.js +0 -0
- package/dist/lib/exceptions/SimpleCommandExceptionType.js.map +0 -0
- package/dist/lib/suggestion/IntegerSuggestion.js +0 -0
- package/dist/lib/suggestion/IntegerSuggestion.js.map +0 -0
- package/dist/lib/suggestion/Suggestion.js +1 -1
- package/dist/lib/suggestion/Suggestion.js.map +1 -1
- package/dist/lib/suggestion/SuggestionProvider.js +0 -0
- package/dist/lib/suggestion/SuggestionProvider.js.map +0 -0
- package/dist/lib/suggestion/Suggestions.js +1 -1
- package/dist/lib/suggestion/Suggestions.js.map +1 -1
- package/dist/lib/suggestion/SuggestionsBuilder.js +0 -0
- package/dist/lib/suggestion/SuggestionsBuilder.js.map +0 -0
- package/dist/lib/tree/ArgumentCommandNode.js +17 -16
- package/dist/lib/tree/ArgumentCommandNode.js.map +1 -1
- package/dist/lib/tree/CommandNode.js +14 -13
- package/dist/lib/tree/CommandNode.js.map +1 -1
- package/dist/lib/tree/LiteralCommandNode.js +0 -0
- package/dist/lib/tree/LiteralCommandNode.js.map +0 -0
- package/dist/lib/tree/RootCommandNode.js +0 -0
- package/dist/lib/tree/RootCommandNode.js.map +0 -0
- package/dist/lib/util/isEqual.js +0 -0
- package/dist/lib/util/isEqual.js.map +0 -0
- package/index.js +0 -0
- package/package.json +55 -48
- package/.prettierrc +0 -10
- package/.renovaterc +0 -3
- package/CHANGELOG.md +0 -30
- package/dist/index.d.ts +0 -23
- package/dist/lib/AmbiguityConsumer.d.ts +0 -4
- package/dist/lib/Command.d.ts +0 -4
- package/dist/lib/CommandDispatcher.d.ts +0 -29
- package/dist/lib/ImmutableStringReader.d.ts +0 -12
- package/dist/lib/LiteralMessage.d.ts +0 -7
- package/dist/lib/Message.d.ts +0 -3
- package/dist/lib/ParseResults.d.ts +0 -13
- package/dist/lib/Predicate.d.ts +0 -3
- package/dist/lib/Primitive.js +0 -2
- package/dist/lib/RedirectModifier.d.ts +0 -4
- package/dist/lib/ResultConsumer.d.ts +0 -4
- package/dist/lib/SingleRedirectModifier.d.ts +0 -4
- package/dist/lib/StringReader.d.ts +0 -27
- package/dist/lib/arguments/ArgumentType.d.ts +0 -21
- package/dist/lib/arguments/BoolArgumentType.d.ts +0 -13
- package/dist/lib/arguments/FloatArgumentType.d.ts +0 -16
- package/dist/lib/arguments/IntegerArgumentType.d.ts +0 -16
- package/dist/lib/arguments/StringArgumentType.d.ts +0 -21
- package/dist/lib/builder/ArgumentBuilder.d.ts +0 -28
- package/dist/lib/builder/LiteralArgumentBuilder.d.ts +0 -11
- package/dist/lib/builder/RequiredArgumentBuilder.d.ts +0 -18
- package/dist/lib/context/CommandContext.d.ts +0 -33
- package/dist/lib/context/CommandContextBuilder.d.ts +0 -38
- package/dist/lib/context/ParsedArgument.d.ts +0 -9
- package/dist/lib/context/ParsedCommandNode.d.ts +0 -11
- package/dist/lib/context/StringRange.d.ts +0 -16
- package/dist/lib/context/SuggestionContext.d.ts +0 -6
- package/dist/lib/exceptions/BuiltInExceptionProvider.d.ts +0 -23
- package/dist/lib/exceptions/BuiltInExceptions.d.ts +0 -43
- package/dist/lib/exceptions/CommandExceptionType.d.ts +0 -2
- package/dist/lib/exceptions/CommandSyntaxException.d.ts +0 -19
- package/dist/lib/exceptions/Dynamic2CommandExceptionType.js +0 -19
- package/dist/lib/exceptions/DynamicCommandExceptionType.d.ts +0 -10
- package/dist/lib/exceptions/SimpleCommandExceptionType.d.ts +0 -11
- package/dist/lib/suggestion/IntegerSuggestion.d.ts +0 -12
- package/dist/lib/suggestion/Suggestion.d.ts +0 -17
- package/dist/lib/suggestion/SuggestionProvider.d.ts +0 -6
- package/dist/lib/suggestion/Suggestions.d.ts +0 -16
- package/dist/lib/suggestion/SuggestionsBuilder.d.ts +0 -18
- package/dist/lib/tree/ArgumentCommandNode.d.ts +0 -31
- package/dist/lib/tree/CommandNode.d.ts +0 -45
- package/dist/lib/tree/LiteralCommandNode.d.ts +0 -27
- package/dist/lib/tree/RootCommandNode.d.ts +0 -21
- package/dist/lib/util/isEqual.d.ts +0 -1
- package/example/fill.js +0 -47
- package/example/fill.ts +0 -50
- package/src/index.ts +0 -50
- package/src/lib/AmbiguityConsumer.ts +0 -6
- package/src/lib/Command.ts +0 -5
- package/src/lib/CommandDispatcher.ts +0 -390
- package/src/lib/ImmutableStringReader.ts +0 -22
- package/src/lib/LiteralMessage.ts +0 -17
- package/src/lib/Message.ts +0 -3
- package/src/lib/ParseResults.ts +0 -32
- package/src/lib/Predicate.ts +0 -3
- package/src/lib/RedirectModifier.ts +0 -5
- package/src/lib/ResultConsumer.ts +0 -6
- package/src/lib/SingleRedirectModifier.ts +0 -6
- package/src/lib/StringReader.ts +0 -210
- package/src/lib/arguments/ArgumentType.ts +0 -27
- package/src/lib/arguments/BoolArgumentType.ts +0 -41
- package/src/lib/arguments/FloatArgumentType.ts +0 -75
- package/src/lib/arguments/IntegerArgumentType.ts +0 -75
- package/src/lib/arguments/StringArgumentType.ts +0 -83
- package/src/lib/builder/ArgumentBuilder.ts +0 -94
- package/src/lib/builder/LiteralArgumentBuilder.ts +0 -35
- package/src/lib/builder/RequiredArgumentBuilder.ts +0 -54
- package/src/lib/context/CommandContext.ts +0 -118
- package/src/lib/context/CommandContextBuilder.ts +0 -155
- package/src/lib/context/ParsedArgument.ts +0 -27
- package/src/lib/context/ParsedCommandNode.ts +0 -35
- package/src/lib/context/StringRange.ts +0 -57
- package/src/lib/context/SuggestionContext.ts +0 -12
- package/src/lib/exceptions/BuiltInExceptionProvider.ts +0 -43
- package/src/lib/exceptions/BuiltInExceptions.ts +0 -121
- package/src/lib/exceptions/CommandExceptionType.ts +0 -2
- package/src/lib/exceptions/CommandSyntaxException.ts +0 -77
- package/src/lib/exceptions/DynamicCommandExceptionType.ts +0 -22
- package/src/lib/exceptions/SimpleCommandExceptionType.ts +0 -26
- package/src/lib/suggestion/IntegerSuggestion.ts +0 -46
- package/src/lib/suggestion/Suggestion.ts +0 -87
- package/src/lib/suggestion/SuggestionProvider.ts +0 -7
- package/src/lib/suggestion/Suggestions.ts +0 -85
- package/src/lib/suggestion/SuggestionsBuilder.ts +0 -69
- package/src/lib/tree/ArgumentCommandNode.ts +0 -118
- package/src/lib/tree/CommandNode.ts +0 -200
- package/src/lib/tree/LiteralCommandNode.ts +0 -111
- package/src/lib/tree/RootCommandNode.ts +0 -62
- package/src/lib/util/isEqual.ts +0 -75
- package/test/CommandDispatcherTest.ts +0 -427
- package/test/CommandDispatcherUsagesTest.ts +0 -163
- package/test/CommandSuggestionsTest.ts +0 -283
- package/test/StringReaderTest.ts +0 -391
- package/test/arguments/BoolArgumentTypeTest.ts +0 -18
- package/test/arguments/FloatArgumentTypeTest.ts +0 -61
- package/test/arguments/IntegerArgumentTypeTest.ts +0 -63
- package/test/arguments/StringArgumentTypeTest.ts +0 -61
- package/test/benchmarks/ExecuteBenchmark.js +0 -33
- package/test/benchmarks/ParsingBenchmark.js +0 -96
- package/test/builder/ArgumentBuilderTest.ts +0 -61
- package/test/builder/LiteralArgumentBuilderTest.ts +0 -37
- package/test/builder/RequiredArgumentBuilderTest.ts +0 -40
- package/test/context/CommandContextTest.ts +0 -77
- package/test/context/ParsedArgumentTest.ts +0 -19
- package/test/exceptions/DynamicCommandSyntaxExceptionTypeTest.ts +0 -18
- package/test/exceptions/SimpleCommandSyntaxExceptionTypeTest.ts +0 -33
- package/test/suggestion/SuggestionBuilderTest.ts +0 -66
- package/test/suggestion/SuggestionTest.ts +0 -65
- package/test/suggestion/SuggestionsTest.ts +0 -24
- package/test/tree/AbstractCommandNodeTest.ts +0 -57
- package/test/tree/ArgumentCommandNodeTest.ts +0 -81
- package/test/tree/LiteralCommandNodeTest.ts +0 -112
- package/test/tree/RootCommandNodeTest.ts +0 -70
- package/test/utils/testEquality.ts +0 -10
- package/tsconfig.json +0 -40
- package/tsconfig.tsbuildinfo +0 -1578
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { assert, expect } from "chai"
|
|
2
|
-
import Command from "../src/lib/Command"
|
|
3
|
-
import CommandDispatcher from "../src/lib/CommandDispatcher"
|
|
4
|
-
import { literal } from "../src/lib/builder/LiteralArgumentBuilder"
|
|
5
|
-
import StringReader from "../src/lib/StringReader";
|
|
6
|
-
|
|
7
|
-
describe('CommandDispatcher Usage Test', () => {
|
|
8
|
-
|
|
9
|
-
let subject: CommandDispatcher<Object>;
|
|
10
|
-
const source: Object = {};
|
|
11
|
-
const command: Command<Object> = () => 0;
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
subject = new CommandDispatcher();
|
|
14
|
-
subject.register(
|
|
15
|
-
literal("a")
|
|
16
|
-
.then(
|
|
17
|
-
literal("1")
|
|
18
|
-
.then(literal("i").executes(command))
|
|
19
|
-
.then(literal("ii").executes(command))
|
|
20
|
-
)
|
|
21
|
-
.then(
|
|
22
|
-
literal("2")
|
|
23
|
-
.then(literal("i").executes(command))
|
|
24
|
-
.then(literal("ii").executes(command))
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
subject.register(literal("b").then(literal("1").executes(command)));
|
|
28
|
-
subject.register(literal("c").executes(command));
|
|
29
|
-
subject.register(literal("d").requires(s => false).executes(command));
|
|
30
|
-
subject.register(
|
|
31
|
-
literal("e")
|
|
32
|
-
.executes(command)
|
|
33
|
-
.then(
|
|
34
|
-
literal("1")
|
|
35
|
-
.executes(command)
|
|
36
|
-
.then(literal("i").executes(command))
|
|
37
|
-
.then(literal("ii").executes(command))
|
|
38
|
-
)
|
|
39
|
-
);
|
|
40
|
-
subject.register(
|
|
41
|
-
literal("f")
|
|
42
|
-
.then(
|
|
43
|
-
literal("1")
|
|
44
|
-
.then(literal("i").executes(command))
|
|
45
|
-
.then(literal("ii").executes(command).requires(s => false))
|
|
46
|
-
)
|
|
47
|
-
.then(
|
|
48
|
-
literal("2")
|
|
49
|
-
.then(literal("i").executes(command).requires(s => false))
|
|
50
|
-
.then(literal("ii").executes(command))
|
|
51
|
-
)
|
|
52
|
-
);
|
|
53
|
-
subject.register(
|
|
54
|
-
literal("g")
|
|
55
|
-
.executes(command)
|
|
56
|
-
.then(literal("1").then(literal("i").executes(command)))
|
|
57
|
-
);
|
|
58
|
-
subject.register(
|
|
59
|
-
literal("h")
|
|
60
|
-
.executes(command)
|
|
61
|
-
.then(literal("1").then(literal("i").executes(command)))
|
|
62
|
-
.then(literal("2").then(literal("i").then(literal("ii").executes(command))))
|
|
63
|
-
.then(literal("3").executes(command))
|
|
64
|
-
);
|
|
65
|
-
subject.register(
|
|
66
|
-
literal("i")
|
|
67
|
-
.executes(command)
|
|
68
|
-
.then(literal("1").executes(command))
|
|
69
|
-
.then(literal("2").executes(command))
|
|
70
|
-
);
|
|
71
|
-
subject.register(
|
|
72
|
-
literal("j")
|
|
73
|
-
.redirect(subject.getRoot())
|
|
74
|
-
);
|
|
75
|
-
subject.register(
|
|
76
|
-
literal("k")
|
|
77
|
-
.redirect(get("h"))
|
|
78
|
-
);
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
function get(command: string | StringReader) {
|
|
82
|
-
const t = subject.parse(command, source).getContext().getNodes();
|
|
83
|
-
return t[t.length - 1].getNode();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
it('testAllUsage_noCommands', () => {
|
|
87
|
-
subject = new CommandDispatcher();
|
|
88
|
-
const results = subject.getAllUsage(subject.getRoot(), source, true);
|
|
89
|
-
assert.equal([...results.entries()].length, 0);
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('testSmartUsage_noCommands', () => {
|
|
93
|
-
subject = new CommandDispatcher();
|
|
94
|
-
const results = subject.getSmartUsage(subject.getRoot(), source);
|
|
95
|
-
assert.equal([...results.entries()].length, 0);
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('testAllUsage_root', () => {
|
|
99
|
-
const results = subject.getAllUsage(subject.getRoot(), source, true);
|
|
100
|
-
expect(results).to.deep.equal([
|
|
101
|
-
"a 1 i",
|
|
102
|
-
"a 1 ii",
|
|
103
|
-
"a 2 i",
|
|
104
|
-
"a 2 ii",
|
|
105
|
-
"b 1",
|
|
106
|
-
"c",
|
|
107
|
-
"e",
|
|
108
|
-
"e 1",
|
|
109
|
-
"e 1 i",
|
|
110
|
-
"e 1 ii",
|
|
111
|
-
"f 1 i",
|
|
112
|
-
"f 2 ii",
|
|
113
|
-
"g",
|
|
114
|
-
"g 1 i",
|
|
115
|
-
"h",
|
|
116
|
-
"h 1 i",
|
|
117
|
-
"h 2 i ii",
|
|
118
|
-
"h 3",
|
|
119
|
-
"i",
|
|
120
|
-
"i 1",
|
|
121
|
-
"i 2",
|
|
122
|
-
"j ...",
|
|
123
|
-
"k -> h",
|
|
124
|
-
]);
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
it('testSmartUsage_root', () => {
|
|
128
|
-
const results = subject.getSmartUsage(subject.getRoot(), source);
|
|
129
|
-
expect(results).to.deep.equal(
|
|
130
|
-
new Map().set(get("a"), "a (1|2)")
|
|
131
|
-
.set(get("b"), "b 1")
|
|
132
|
-
.set(get("c"), "c")
|
|
133
|
-
.set(get("e"), "e [1]")
|
|
134
|
-
.set(get("f"), "f (1|2)")
|
|
135
|
-
.set(get("g"), "g [1]")
|
|
136
|
-
.set(get("h"), "h [1|2|3]")
|
|
137
|
-
.set(get("i"), "i [1|2]")
|
|
138
|
-
.set(get("j"), "j ...")
|
|
139
|
-
.set(get("k"), "k -> h")
|
|
140
|
-
);
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
it('testSmartUsage_h', () => {
|
|
144
|
-
const results = subject.getSmartUsage(get("h"), source);
|
|
145
|
-
expect(results).to.deep.equal(new Map()
|
|
146
|
-
.set(get("h 1"), "[1] i")
|
|
147
|
-
.set(get("h 2"), "[2] i ii")
|
|
148
|
-
.set(get("h 3"), "[3]")
|
|
149
|
-
);
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
it('testSmartUsage_offsetH', () => {
|
|
153
|
-
const offsetH = new StringReader("/|/|/h");
|
|
154
|
-
offsetH.setCursor(5);
|
|
155
|
-
|
|
156
|
-
const results = subject.getSmartUsage(get(offsetH), source);
|
|
157
|
-
expect(results).to.deep.equal(new Map()
|
|
158
|
-
.set(get("h 1"), "[1] i")
|
|
159
|
-
.set(get("h 2"), "[2] i ii")
|
|
160
|
-
.set(get("h 3"), "[3]")
|
|
161
|
-
);
|
|
162
|
-
})
|
|
163
|
-
})
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import { assert, expect } from "chai"
|
|
2
|
-
import StringRange from "../src/lib/context/StringRange"
|
|
3
|
-
import Suggestion from "../src/lib/suggestion/Suggestion"
|
|
4
|
-
import CommandDispatcher from "../src/lib/CommandDispatcher"
|
|
5
|
-
import { literal } from "../src/lib/builder/LiteralArgumentBuilder"
|
|
6
|
-
import { argument } from "../src/lib/builder/RequiredArgumentBuilder"
|
|
7
|
-
import { DefaultType } from "../src/lib/arguments/ArgumentType"
|
|
8
|
-
import StringReader from "../src/lib/StringReader";
|
|
9
|
-
|
|
10
|
-
const { integer, word } = DefaultType
|
|
11
|
-
|
|
12
|
-
describe("Command Suggestion Test", () => {
|
|
13
|
-
let subject: CommandDispatcher<Object>;
|
|
14
|
-
const source = {};
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
subject = new CommandDispatcher();
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
async function testSuggestions(contents: string, cursor: number, range: StringRange, ...suggestions: string[]) {
|
|
21
|
-
const result = await subject.getCompletionSuggestions(subject.parse(contents, source), cursor);
|
|
22
|
-
assert.deepEqual(result.getRange(), range);
|
|
23
|
-
|
|
24
|
-
const expected = [];
|
|
25
|
-
for (let suggestion of suggestions) {
|
|
26
|
-
expected.push(new Suggestion(range, suggestion));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
expect(result.getList()).to.have.deep.members(expected);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function inputWithOffset(input: string, offset: number): StringReader {
|
|
33
|
-
const result = new StringReader(input);
|
|
34
|
-
result.setCursor(offset);
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
it('getCompletionSuggestions_rootCommands', async () => {
|
|
39
|
-
subject.register(literal("foo"));
|
|
40
|
-
subject.register(literal("bar"));
|
|
41
|
-
subject.register(literal("baz"));
|
|
42
|
-
|
|
43
|
-
const result = await subject.getCompletionSuggestions(subject.parse("", source));
|
|
44
|
-
|
|
45
|
-
expect(result.getRange()).to.deep.equal(StringRange.at(0));
|
|
46
|
-
expect(result.getList()).to.have.deep.members([new Suggestion(StringRange.at(0), "bar"), new Suggestion(StringRange.at(0), "baz"), new Suggestion(StringRange.at(0), "foo")]);
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('getCompletionSuggestions_rootCommands_withInputOffset', async () => {
|
|
50
|
-
subject.register(literal("foo"));
|
|
51
|
-
subject.register(literal("bar"));
|
|
52
|
-
subject.register(literal("baz"));
|
|
53
|
-
|
|
54
|
-
const result = await subject.getCompletionSuggestions(subject.parse(inputWithOffset("OOO", 3), source));
|
|
55
|
-
|
|
56
|
-
expect(result.getRange()).to.deep.equal(StringRange.at(3));
|
|
57
|
-
expect(result.getList()).to.have.deep.members([new Suggestion(StringRange.at(3), "bar"), new Suggestion(StringRange.at(3), "baz"), new Suggestion(StringRange.at(3), "foo")]);
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('getCompletionSuggestions_rootCommands_partial', async () => {
|
|
61
|
-
subject.register(literal("foo"));
|
|
62
|
-
subject.register(literal("bar"));
|
|
63
|
-
subject.register(literal("baz"));
|
|
64
|
-
|
|
65
|
-
const result = await subject.getCompletionSuggestions(subject.parse("b", source));
|
|
66
|
-
|
|
67
|
-
expect(result.getRange()).to.deep.equal(StringRange.between(0, 1));
|
|
68
|
-
expect(result.getList()).to.have.deep.members([new Suggestion(StringRange.between(0, 1), "bar"), new Suggestion(StringRange.between(0, 1), "baz")]);
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('getCompletionSuggestions_rootCommands_partial_withInputOffset', async () => {
|
|
72
|
-
subject.register(literal("foo"));
|
|
73
|
-
subject.register(literal("bar"));
|
|
74
|
-
subject.register(literal("baz"));
|
|
75
|
-
|
|
76
|
-
const result = await subject.getCompletionSuggestions(subject.parse(inputWithOffset("Zb", 1), source));
|
|
77
|
-
|
|
78
|
-
expect(result.getRange()).to.deep.equal(StringRange.between(1, 2));
|
|
79
|
-
expect(result.getList()).to.have.deep.members([new Suggestion(StringRange.between(1, 2), "bar"), new Suggestion(StringRange.between(1, 2), "baz")]);
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('getCompletionSuggestions_subCommands', async () => {
|
|
83
|
-
subject.register(
|
|
84
|
-
literal("parent")
|
|
85
|
-
.then(literal("foo"))
|
|
86
|
-
.then(literal("bar"))
|
|
87
|
-
.then(literal("baz"))
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const result = await subject.getCompletionSuggestions(subject.parse("parent ", source));
|
|
91
|
-
|
|
92
|
-
expect(result.getRange()).to.deep.equal(StringRange.at(7));
|
|
93
|
-
expect(result.getList()).to.have.deep.members([new Suggestion(StringRange.at(7), "bar"), new Suggestion(StringRange.at(7), "baz"), new Suggestion(StringRange.at(7), "foo")]);
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('getCompletionSuggestions_movingCursor_subCommands', async () => {
|
|
97
|
-
subject.register(
|
|
98
|
-
literal("parent_one")
|
|
99
|
-
.then(literal("faz"))
|
|
100
|
-
.then(literal("fbz"))
|
|
101
|
-
.then(literal("gaz"))
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
subject.register(
|
|
105
|
-
literal("parent_two")
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
await testSuggestions("parent_one faz ", 0, StringRange.at(0), "parent_one", "parent_two");
|
|
109
|
-
await testSuggestions("parent_one faz ", 1, StringRange.between(0, 1), "parent_one", "parent_two");
|
|
110
|
-
await testSuggestions("parent_one faz ", 7, StringRange.between(0, 7), "parent_one", "parent_two");
|
|
111
|
-
await testSuggestions("parent_one faz ", 8, StringRange.between(0, 8), "parent_one");
|
|
112
|
-
await testSuggestions("parent_one faz ", 10, StringRange.at(0));
|
|
113
|
-
await testSuggestions("parent_one faz ", 11, StringRange.at(11), "faz", "fbz", "gaz");
|
|
114
|
-
await testSuggestions("parent_one faz ", 12, StringRange.between(11, 12), "faz", "fbz");
|
|
115
|
-
await testSuggestions("parent_one faz ", 13, StringRange.between(11, 13), "faz");
|
|
116
|
-
await testSuggestions("parent_one faz ", 14, StringRange.at(0));
|
|
117
|
-
await testSuggestions("parent_one faz ", 15, StringRange.at(0));
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('getCompletionSuggestions_subCommands_partial', async () => {
|
|
121
|
-
subject.register(
|
|
122
|
-
literal("parent")
|
|
123
|
-
.then(literal("foo"))
|
|
124
|
-
.then(literal("bar"))
|
|
125
|
-
.then(literal("baz"))
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
const parse = subject.parse("parent b", source);
|
|
129
|
-
const result = await subject.getCompletionSuggestions(parse);
|
|
130
|
-
|
|
131
|
-
expect(result.getRange()).to.deep.equal(StringRange.between(7, 8));
|
|
132
|
-
expect(result.getList()).to.have.deep.members([new Suggestion(StringRange.between(7, 8), "bar"), new Suggestion(StringRange.between(7, 8), "baz")]);
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
it('getCompletionSuggestions_subCommands_partial_withInputOffset', async () => {
|
|
136
|
-
subject.register(
|
|
137
|
-
literal("parent")
|
|
138
|
-
.then(literal("foo"))
|
|
139
|
-
.then(literal("bar"))
|
|
140
|
-
.then(literal("baz"))
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
const parse = subject.parse(inputWithOffset("junk parent b", 5), source);
|
|
144
|
-
const result = await subject.getCompletionSuggestions(parse);
|
|
145
|
-
|
|
146
|
-
expect(result.getRange()).to.deep.equal(StringRange.between(12, 13));
|
|
147
|
-
expect(result.getList()).to.have.deep.members([new Suggestion(StringRange.between(12, 13), "bar"), new Suggestion(StringRange.between(12, 13), "baz")]);
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
it('getCompletionSuggestions_redirect', async () => {
|
|
151
|
-
const actual = subject.register(literal("actual").then(literal("sub")));
|
|
152
|
-
subject.register(literal("redirect").redirect(actual));
|
|
153
|
-
|
|
154
|
-
const parse = subject.parse("redirect ", source);
|
|
155
|
-
const result = await subject.getCompletionSuggestions(parse);
|
|
156
|
-
|
|
157
|
-
expect(result.getRange()).to.deep.equal(StringRange.at(9));
|
|
158
|
-
expect(result.getList()).to.deep.equal([new Suggestion(StringRange.at(9), "sub")]);
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
it('getCompletionSuggestions_redirectPartial', async () => {
|
|
162
|
-
const actual = subject.register(literal("actual").then(literal("sub")));
|
|
163
|
-
subject.register(literal("redirect").redirect(actual));
|
|
164
|
-
|
|
165
|
-
const parse = subject.parse("redirect s", source);
|
|
166
|
-
const result = await subject.getCompletionSuggestions(parse);
|
|
167
|
-
|
|
168
|
-
expect(result.getRange()).to.deep.equal(StringRange.between(9, 10));
|
|
169
|
-
expect(result.getList()).to.deep.equal([new Suggestion(StringRange.between(9, 10), "sub")]);
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
it('getCompletionSuggestions_movingCursor_redirect', async () => {
|
|
173
|
-
const actualOne = subject.register(literal("actual_one")
|
|
174
|
-
.then(literal("faz"))
|
|
175
|
-
.then(literal("fbz"))
|
|
176
|
-
.then(literal("gaz"))
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
const actualTwo = subject.register(literal("actual_two"));
|
|
180
|
-
|
|
181
|
-
subject.register(literal("redirect_one").redirect(actualOne));
|
|
182
|
-
subject.register(literal("redirect_two").redirect(actualOne));
|
|
183
|
-
|
|
184
|
-
await testSuggestions("redirect_one faz ", 0, StringRange.at(0), "actual_one", "actual_two", "redirect_one", "redirect_two");
|
|
185
|
-
await testSuggestions("redirect_one faz ", 9, StringRange.between(0, 9), "redirect_one", "redirect_two");
|
|
186
|
-
await testSuggestions("redirect_one faz ", 10, StringRange.between(0, 10), "redirect_one");
|
|
187
|
-
await testSuggestions("redirect_one faz ", 12, StringRange.at(0));
|
|
188
|
-
await testSuggestions("redirect_one faz ", 13, StringRange.at(13), "faz", "fbz", "gaz");
|
|
189
|
-
await testSuggestions("redirect_one faz ", 14, StringRange.between(13, 14), "faz", "fbz");
|
|
190
|
-
await testSuggestions("redirect_one faz ", 15, StringRange.between(13, 15), "faz");
|
|
191
|
-
await testSuggestions("redirect_one faz ", 16, StringRange.at(0));
|
|
192
|
-
await testSuggestions("redirect_one faz ", 17, StringRange.at(0));
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
it('getCompletionSuggestions_redirectPartial_withInputOffset', async () => {
|
|
196
|
-
const actual = subject.register(literal("actual").then(literal("sub")));
|
|
197
|
-
subject.register(literal("redirect").redirect(actual));
|
|
198
|
-
|
|
199
|
-
const parse = subject.parse(inputWithOffset("/redirect s", 1), source);
|
|
200
|
-
const result = await subject.getCompletionSuggestions(parse);
|
|
201
|
-
|
|
202
|
-
expect(result.getRange()).to.deep.equal(StringRange.between(10, 11));
|
|
203
|
-
expect(result.getList()).to.deep.equal([new Suggestion(StringRange.between(10, 11), "sub")]);
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
it('getCompletionSuggestions_redirect_lots', async () => {
|
|
207
|
-
const loop = subject.register(literal("redirect"));
|
|
208
|
-
subject.register(
|
|
209
|
-
literal("redirect")
|
|
210
|
-
.then(
|
|
211
|
-
literal("loop")
|
|
212
|
-
.then(
|
|
213
|
-
argument("loop", integer())
|
|
214
|
-
.redirect(loop)
|
|
215
|
-
)
|
|
216
|
-
)
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
const result = await subject.getCompletionSuggestions(subject.parse("redirect loop 1 loop 02 loop 003 ", source));
|
|
220
|
-
|
|
221
|
-
expect(result.getRange()).to.deep.equal(StringRange.at(33));
|
|
222
|
-
expect(result.getList()).to.have.deep.members([new Suggestion(StringRange.at(33), "loop")]);
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
it('getCompletionSuggestions_execute_simulation', async () => {
|
|
226
|
-
const execute = subject.register(literal("execute"));
|
|
227
|
-
subject.register(
|
|
228
|
-
literal("execute")
|
|
229
|
-
.then(
|
|
230
|
-
literal("as")
|
|
231
|
-
.then(
|
|
232
|
-
argument("name", word())
|
|
233
|
-
.redirect(execute)
|
|
234
|
-
)
|
|
235
|
-
)
|
|
236
|
-
.then(
|
|
237
|
-
literal("store")
|
|
238
|
-
.then(
|
|
239
|
-
argument("name", word())
|
|
240
|
-
.redirect(execute)
|
|
241
|
-
)
|
|
242
|
-
)
|
|
243
|
-
.then(
|
|
244
|
-
literal("run")
|
|
245
|
-
.executes(() => 0)
|
|
246
|
-
)
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
const parse = subject.parse("execute as Dinnerbone as", source);
|
|
250
|
-
const result = await subject.getCompletionSuggestions(parse);
|
|
251
|
-
|
|
252
|
-
assert.equal(result.isEmpty(), true);
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
it('getCompletionSuggestions_execute_simulation_partial', async () => {
|
|
256
|
-
const execute = subject.register(literal("execute"));
|
|
257
|
-
subject.register(
|
|
258
|
-
literal("execute")
|
|
259
|
-
.then(
|
|
260
|
-
literal("as")
|
|
261
|
-
.then(literal("bar").redirect(execute))
|
|
262
|
-
.then(literal("baz").redirect(execute))
|
|
263
|
-
)
|
|
264
|
-
.then(
|
|
265
|
-
literal("store")
|
|
266
|
-
.then(
|
|
267
|
-
argument("name", word())
|
|
268
|
-
.redirect(execute)
|
|
269
|
-
)
|
|
270
|
-
)
|
|
271
|
-
.then(
|
|
272
|
-
literal("run")
|
|
273
|
-
.executes(() => 0)
|
|
274
|
-
)
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
const parse = subject.parse("execute as bar as ", source);
|
|
278
|
-
const result = await subject.getCompletionSuggestions(parse);
|
|
279
|
-
|
|
280
|
-
expect(result.getRange()).to.deep.equal(StringRange.at(18));
|
|
281
|
-
expect(result.getList()).to.have.deep.members([new Suggestion(StringRange.at(18), "bar"), new Suggestion(StringRange.at(18), "baz")]);
|
|
282
|
-
})
|
|
283
|
-
})
|