blob: 8ad4b35afa3f6448081f636c7f5754f8c476082a [file] [log] [blame]
Václav Kubernát4108e0d2018-10-29 13:32:22 +01001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
4 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8
Václav Kubernát26b56082020-02-03 18:28:56 +01009#include "trompeloeil_doctest.hpp"
Václav Kubernát43908fb2020-01-02 19:05:51 +010010#include "datastoreaccess_mock.hpp"
Václav Kubernát4108e0d2018-10-29 13:32:22 +010011#include "parser.hpp"
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010012#include "pretty_printers.hpp"
Václav Kubernát4108e0d2018-10-29 13:32:22 +010013#include "static_schema.hpp"
14
15TEST_CASE("path_completion")
16{
17 auto schema = std::make_shared<StaticSchema>();
18 schema->addModule("example");
19 schema->addModule("second");
Václav Kubernátefcac932020-01-10 15:26:32 +010020 schema->addContainer("/", "example:ano");
21 schema->addContainer("/", "example:anoda");
22 schema->addList("/example:ano", "example:listInCont", {"number"});
23 schema->addContainer("/", "second:amelie");
24 schema->addContainer("/", "example:bota");
25 schema->addContainer("/example:ano", "example:a2");
26 schema->addContainer("/example:bota", "example:b2");
27 schema->addContainer("/example:ano/example:a2", "example:a3");
28 schema->addContainer("/example:bota/example:b2", "example:b3");
29 schema->addList("/", "example:list", {"number"});
Václav Kubernát3a99f002020-03-31 02:27:41 +020030 schema->addLeaf("/example:list", "example:number", yang::Int32{});
Václav Kubernátefcac932020-01-10 15:26:32 +010031 schema->addContainer("/example:list", "example:contInList");
Václav Kubernát7707cae2020-01-16 12:04:53 +010032 schema->addList("/", "example:ovoce", {"name"});
Václav Kubernát3a99f002020-03-31 02:27:41 +020033 schema->addLeaf("/example:ovoce", "example:name", yang::String{});
Václav Kubernát7707cae2020-01-16 12:04:53 +010034 schema->addList("/", "example:ovocezelenina", {"name"});
Václav Kubernát3a99f002020-03-31 02:27:41 +020035 schema->addLeaf("/example:ovocezelenina", "example:name", yang::String{});
Václav Kubernátefcac932020-01-10 15:26:32 +010036 schema->addList("/", "example:twoKeyList", {"number", "name"});
Václav Kubernát3a99f002020-03-31 02:27:41 +020037 schema->addLeaf("/example:twoKeyList", "example:name", yang::String{});
38 schema->addLeaf("/example:twoKeyList", "example:number", yang::Int32{});
39 schema->addLeaf("/", "example:leafInt", yang::Int32{});
Václav Kubernátabf52802020-05-19 01:31:17 +020040 schema->addLeaf("/", "example:readonly", yang::Int32{}, yang::AccessType::ReadOnly);
Václav Kubernát743d9eb2020-05-18 13:42:36 +020041 schema->addLeafList("/", "example:addresses", yang::String{});
Václav Kubernáte7248b22020-06-26 15:38:59 +020042 schema->addRpc("/", "second:fire");
43 schema->addLeaf("/second:fire", "second:whom", yang::String{});
Václav Kubernátce108db2021-01-25 10:05:40 +010044 schema->addContainer("/", "example:system");
45 schema->addContainer("/example:system", "example:thing");
46 schema->addContainer("/", "example:system-state");
Jan Kundrátbb7aa852023-08-30 11:51:43 +020047 schema->addLeaf("/example:anoda", "example:iid", yang::InstanceIdentifier{});
Václav Kubernát43908fb2020-01-02 19:05:51 +010048 auto mockDatastore = std::make_shared<MockDatastoreAccess>();
49
50 // The parser will use DataQuery for key value completion, but I'm not testing that here, so I don't return anything.
51 ALLOW_CALL(*mockDatastore, listInstances("/example:list"))
52 .RETURN(std::vector<ListInstance>{});
53 ALLOW_CALL(*mockDatastore, listInstances("/example:twoKeyList"))
54 .RETURN(std::vector<ListInstance>{});
55
56 // DataQuery gets the schema from DatastoreAccess once
57 auto expectation = NAMED_REQUIRE_CALL(*mockDatastore, schema())
58 .RETURN(schema);
59 auto dataQuery = std::make_shared<DataQuery>(*mockDatastore);
60 expectation.reset();
Václav Kubernát28cf3362020-06-29 17:52:51 +020061 Parser parser(schema, WritableOps::No, dataQuery);
Václav Kubernát4108e0d2018-10-29 13:32:22 +010062 std::string input;
63 std::ostringstream errorStream;
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010064
65 std::set<std::string> expectedCompletions;
66 // GCC complains here with -Wmaybe-uninitialized if I don't assign
67 // something here. I suspect it's because of nested SECTIONs. -1 is an
68 // invalid value (as in, I'll never expect expectedContextLength to be -1),
69 // so let's go with that.
70 int expectedContextLength = -1;
Václav Kubernát4108e0d2018-10-29 13:32:22 +010071
Václav Kubernát329c6c32019-02-06 16:41:53 +010072 SECTION("node name completion")
Václav Kubernát4108e0d2018-10-29 13:32:22 +010073 {
Václav Kubernát329c6c32019-02-06 16:41:53 +010074 SECTION("ls ")
75 {
76 input = "ls ";
Václav Kubernátce108db2021-01-25 10:05:40 +010077 expectedCompletions = {"example:addresses/", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list/", "example:ovoce/", "example:readonly ", "example:ovocezelenina/", "example:twoKeyList/", "second:amelie/", "second:fire/", "example:system/", "example:system-state/"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010078 expectedContextLength = 0;
Václav Kubernát329c6c32019-02-06 16:41:53 +010079 }
80
81 SECTION("ls e")
82 {
83 input = "ls e";
Václav Kubernátce108db2021-01-25 10:05:40 +010084 expectedCompletions = {"example:addresses/", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list/", "example:ovoce/", "example:readonly ", "example:ovocezelenina/", "example:twoKeyList/", "example:system/", "example:system-state/"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010085 expectedContextLength = 1;
Václav Kubernát329c6c32019-02-06 16:41:53 +010086 }
87
88 SECTION("ls example:ano")
89 {
90 input = "ls example:ano";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +010091 expectedCompletions = {"example:ano/", "example:anoda/"};
92 expectedContextLength = 11;
Václav Kubernát329c6c32019-02-06 16:41:53 +010093 }
94
Václav Kubernáte2d629f2020-04-28 11:01:54 +020095 SECTION("ls example:ano/a")
Václav Kubernát329c6c32019-02-06 16:41:53 +010096 {
Václav Kubernáte2d629f2020-04-28 11:01:54 +020097 input = "ls example:ano/a";
98 expectedCompletions = {"a2/"};
99 expectedContextLength = 1;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100100 }
101
102 SECTION("ls x")
103 {
104 input = "ls x";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100105 expectedCompletions = {};
106 expectedContextLength = 1;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100107 }
108
109 SECTION("ls /")
110 {
111 input = "ls /";
Václav Kubernátce108db2021-01-25 10:05:40 +0100112 expectedCompletions = {"example:addresses/", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list/", "example:ovoce/", "example:readonly ", "example:ovocezelenina/", "example:twoKeyList/", "second:amelie/", "second:fire/", "example:system/", "example:system-state/"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100113 expectedContextLength = 0;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100114 }
115
116 SECTION("ls /e")
117 {
118 input = "ls /e";
Václav Kubernátce108db2021-01-25 10:05:40 +0100119 expectedCompletions = {"example:addresses/", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list/", "example:ovoce/", "example:readonly ", "example:ovocezelenina/", "example:twoKeyList/", "example:system/", "example:system-state/"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100120 expectedContextLength = 1;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100121 }
122
Václav Kubernáte69133a2019-11-01 19:01:34 +0100123 SECTION("ls example:bota")
124 {
125 input = "ls example:bota";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100126 expectedCompletions = {"example:bota/"};
127 expectedContextLength = 12;
Václav Kubernáte69133a2019-11-01 19:01:34 +0100128 }
129
130 SECTION("ls /example:bota")
131 {
132 input = "ls /example:bota";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100133 expectedCompletions = {"example:bota/"};
134 expectedContextLength = 12;
Václav Kubernáte69133a2019-11-01 19:01:34 +0100135 }
136
Václav Kubernát329c6c32019-02-06 16:41:53 +0100137 SECTION("ls /s")
138 {
139 input = "ls /s";
Václav Kubernáte7248b22020-06-26 15:38:59 +0200140 expectedCompletions = {"second:amelie/", "second:fire/"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100141 expectedContextLength = 1;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100142 }
143
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200144 SECTION("ls /example:list")
145 {
146 input = "ls /example:list";
147 expectedCompletions = {"example:list/"};
148 expectedContextLength = 12;
149 }
150
Václav Kubernát26be33a2020-02-13 13:30:14 +0100151 SECTION("ls /example:list/")
152 {
153 input = "ls /example:list/";
Václav Kubernáte2d629f2020-04-28 11:01:54 +0200154 expectedCompletions = {"contInList/", "number "};
Václav Kubernát26be33a2020-02-13 13:30:14 +0100155 expectedContextLength = 0;
156 }
157
Václav Kubernát329c6c32019-02-06 16:41:53 +0100158 SECTION("ls /example:list[number=3]/")
159 {
160 input = "ls /example:list[number=3]/";
Václav Kubernáte2d629f2020-04-28 11:01:54 +0200161 expectedCompletions = {"contInList/", "number "};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100162 expectedContextLength = 0;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100163 }
164
165 SECTION("ls /example:list[number=3]/c")
166 {
Václav Kubernáte2d629f2020-04-28 11:01:54 +0200167 input = "ls /example:list[number=3]/c";
168 expectedCompletions = {"contInList/"};
169 expectedContextLength = 1;
170 }
171
172 SECTION("ls /example:list[number=3]/n")
173 {
174 input = "ls /example:list[number=3]/n";
175 expectedCompletions = {"number "};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100176 expectedContextLength = 1;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100177 }
178
179 SECTION("ls /example:list[number=3]/a")
180 {
181 input = "ls /example:list[number=3]/a";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100182 expectedCompletions = {};
183 expectedContextLength = 1;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100184 }
Václav Kubernát26be33a2020-02-13 13:30:14 +0100185
Václav Kubernáte2d629f2020-04-28 11:01:54 +0200186 SECTION("ls /example:list/contInList/")
Václav Kubernát26be33a2020-02-13 13:30:14 +0100187 {
Václav Kubernáte2d629f2020-04-28 11:01:54 +0200188 input = "ls /example:list/contInList/";
Václav Kubernát26be33a2020-02-13 13:30:14 +0100189 expectedCompletions = {};
190 expectedContextLength = 0;
191 }
Václav Kubernátce108db2021-01-25 10:05:40 +0100192
193 SECTION("ls /example:system-")
194 {
195 input = "ls /example:system-";
196 expectedCompletions = {"example:system-state/"};
197 expectedContextLength = 15;
198 }
Jan Kundrátbb7aa852023-08-30 11:51:43 +0200199
200 SECTION("set example:anoda/iid ")
201 {
202 input = "set example:anoda/iid ";
203 expectedCompletions = {"/"};
204 expectedContextLength = 0;
205 }
206
207 SECTION("set example:anoda/iid /")
208 {
209 input = "set example:anoda/iid /";
210 expectedCompletions = {
211 "example:addresses",
212 "example:ano/",
213 "example:anoda/",
214 "example:bota/",
215 "example:leafInt ",
216 "example:list",
217 "example:ovoce",
218 "example:ovocezelenina",
219 "example:readonly ",
220 "example:system-state/",
221 "example:system/",
222 "example:twoKeyList",
223 "second:amelie/",
224 "second:fire/",
225 };
226 expectedContextLength = 0;
227 }
228
229 SECTION("set example:anoda/iid /example:read")
230 {
231 input = "set example:anoda/iid /example:read";
232 expectedCompletions = {"example:readonly "};
233 expectedContextLength = 12;
234 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100235 }
236
Václav Kubernát7eb47152020-11-12 16:57:03 +0100237 SECTION("get completion")
238 {
239 SECTION("get /example:ano/l")
240 {
241 input = "get /example:ano/l";
242 expectedCompletions = {"listInCont"};
243 expectedContextLength = 1;
244 }
Václav Kubernát85ba7382020-11-18 18:11:18 +0100245
246 SECTION("get /example:list/")
247 {
248 input = "get /example:list/";
249 expectedCompletions = {};
250 // The expectedContextLength is 13, because the completion isn't actually generated after the slash.
251 expectedContextLength = 13;
252 }
Václav Kubernáte066fe22022-04-06 00:32:26 +0200253
254 SECTION("get -")
255 {
256 input = "get -";
257 expectedCompletions = {"-datastore "};
258 expectedContextLength = 0;
259 }
260
261 SECTION("get --datastore ")
262 {
263 input = "get --datastore ";
264 expectedCompletions = {"operational", "running", "startup"};
265 expectedContextLength = 0;
266 }
267
268 SECTION("get --datastore running /second")
269 {
270 input = "get --datastore running /second";
271 expectedCompletions = {"second:amelie/"};
272 expectedContextLength = 6;
273 }
Václav Kubernát7eb47152020-11-12 16:57:03 +0100274 }
275
Václav Kubernát3200b862020-12-03 02:34:55 +0100276 SECTION("describe completion")
277 {
278 SECTION("path with list at the end")
279 {
280 input = "describe /example:list/";
281 expectedCompletions = {"contInList/", "number "};
282 expectedContextLength = 0;
283 }
284 }
285
Václav Kubernát329c6c32019-02-06 16:41:53 +0100286 SECTION("list keys completion")
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100287 {
Václav Kubernát329c6c32019-02-06 16:41:53 +0100288 SECTION("cd example:lis")
289 {
290 input = "cd example:lis";
Václav Kubernátcb3af402020-02-12 16:49:17 +0100291 expectedCompletions = {"example:list"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100292 expectedContextLength = 11;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100293 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100294
Václav Kubernát51853b22019-04-16 21:53:44 +0200295 SECTION("set example:list")
296 {
297 input = "set example:list";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100298 expectedCompletions = {"example:list["};
299 expectedContextLength = 12;
Václav Kubernát4c325482019-04-11 17:51:55 +0200300 }
301
302 SECTION("cd example:list")
303 {
304 input = "cd example:list";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100305 expectedCompletions = {"example:list["};
306 expectedContextLength = 12;
Václav Kubernát51853b22019-04-16 21:53:44 +0200307 }
308
Václav Kubernát329c6c32019-02-06 16:41:53 +0100309 SECTION("cd example:list[")
310 {
311 input = "cd example:list[";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100312 expectedCompletions = {"number="};
313 expectedContextLength = 0;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100314 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100315
Václav Kubernát329c6c32019-02-06 16:41:53 +0100316 SECTION("cd example:list[numb")
317 {
318 input = "cd example:list[numb";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100319 expectedCompletions = {"number="};
320 expectedContextLength = 4;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100321 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100322
Václav Kubernát329c6c32019-02-06 16:41:53 +0100323 SECTION("cd example:list[number")
324 {
325 input = "cd example:list[number";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100326 expectedCompletions = {"number="};
327 expectedContextLength = 6;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100328 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100329
Václav Kubernát117f7b52020-01-23 16:10:55 +0100330 SECTION("cd example:list[number=")
331 {
332 input = "cd example:list[number=";
Václav Kubernát43908fb2020-01-02 19:05:51 +0100333 expectedCompletions = {};
334 expectedContextLength = 0;
Václav Kubernát117f7b52020-01-23 16:10:55 +0100335 }
336
Václav Kubernát329c6c32019-02-06 16:41:53 +0100337 SECTION("cd example:list[number=12")
338 {
339 input = "cd example:list[number=12";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100340 expectedCompletions = {"]/"};
341 expectedContextLength = 0;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100342 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100343
Václav Kubernát329c6c32019-02-06 16:41:53 +0100344 SECTION("cd example:list[number=12]")
345 {
346 input = "cd example:list[number=12]";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100347 expectedCompletions = {"]/"};
348 expectedContextLength = 1;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100349 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100350
Václav Kubernát329c6c32019-02-06 16:41:53 +0100351 SECTION("cd example:twoKeyList[")
352 {
353 input = "cd example:twoKeyList[";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100354 expectedCompletions = {"name=", "number="};
355 expectedContextLength = 0;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100356 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100357
Václav Kubernát4c325482019-04-11 17:51:55 +0200358 SECTION("cd example:twoKeyList[name=\"AHOJ\"")
359 {
360 input = "cd example:twoKeyList[name=\"AHOJ\"";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100361 expectedCompletions = {"]["};
362 expectedContextLength = 0;
Václav Kubernát4c325482019-04-11 17:51:55 +0200363 }
364
365 SECTION("cd example:twoKeyList[name=\"AHOJ\"]")
366 {
367 input = "cd example:twoKeyList[name=\"AHOJ\"]";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100368 expectedCompletions = {"]["};
369 expectedContextLength = 1;
Václav Kubernát4c325482019-04-11 17:51:55 +0200370 }
371
Václav Kubernát329c6c32019-02-06 16:41:53 +0100372 SECTION("cd example:twoKeyList[name=\"AHOJ\"][")
373 {
374 input = "cd example:twoKeyList[name=\"AHOJ\"][";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100375 expectedCompletions = {"number="};
376 expectedContextLength = 0;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100377 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100378
Václav Kubernát329c6c32019-02-06 16:41:53 +0100379 SECTION("cd example:twoKeyList[number=42][")
380 {
381 input = "cd example:twoKeyList[number=42][";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100382 expectedCompletions = {"name="};
383 expectedContextLength = 0;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100384 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100385
Václav Kubernát329c6c32019-02-06 16:41:53 +0100386 SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123")
387 {
388 input = "cd example:twoKeyList[name=\"AHOJ\"][number=123";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100389 expectedCompletions = {"]/"};
390 expectedContextLength = 0;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100391 }
392
393 SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123]")
394 {
395 input = "cd example:twoKeyList[name=\"AHOJ\"][number=123]";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100396 expectedCompletions = {"]/"};
397 expectedContextLength = 1;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100398 }
Václav Kubernát4c325482019-04-11 17:51:55 +0200399
400 SECTION("cd example:ovoce")
401 {
402 input = "cd example:ovoce";
Václav Kubernátcb3af402020-02-12 16:49:17 +0100403 expectedCompletions = {"example:ovoce", "example:ovocezelenina"};
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100404 expectedContextLength = 13;
Václav Kubernát4c325482019-04-11 17:51:55 +0200405 }
Václav Kubernátcb3af402020-02-12 16:49:17 +0100406
407 SECTION("cd example:ovoceze")
408 {
409 input = "cd example:ovoceze";
410 expectedCompletions = {"example:ovocezelenina"};
411 expectedContextLength = 15;
412 }
413
414 SECTION("cd example:ovocezelenina")
415 {
416 input = "cd example:ovocezelenina";
417 expectedCompletions = {"example:ovocezelenina["};
418 expectedContextLength = 21;
419 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100420 }
421
Václav Kubernátabf52802020-05-19 01:31:17 +0200422 SECTION("no readonly data leafs in set")
423 {
424 input = "set example:read";
425 expectedContextLength = 12;
426 }
427
Václav Kubernát8028f942019-09-25 16:03:23 +0200428 SECTION("clear completions when no longer inputting path")
429 {
430 input = "set example:leafInt ";
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100431 expectedCompletions = {};
432 expectedContextLength = 0;
Václav Kubernát8028f942019-09-25 16:03:23 +0200433 }
434
Václav Kubernátaa4250a2020-07-22 00:02:23 +0200435 SECTION("rpc input nodes NOT completed for prepare command")
Václav Kubernáte7248b22020-06-26 15:38:59 +0200436 {
Václav Kubernátaa4250a2020-07-22 00:02:23 +0200437 input = "prepare example:fire/";
Václav Kubernáte7248b22020-06-26 15:38:59 +0200438 expectedCompletions = {};
439 expectedContextLength = 13;
440 }
441
442 SECTION("rpc input nodes completed for set command")
443 {
444 parser.changeNode({{}, {{module_{"second"}, rpcNode_{"fire"}}}});
445 input = "set ";
446 expectedCompletions = {"whom "};
447 expectedContextLength = 0;
448 }
449
450 SECTION("completion for other stuff while inside an rpc")
451 {
452 parser.changeNode({{}, {{module_{"second"}, rpcNode_{"fire"}}}});
453 input = "set ../";
Václav Kubernátce108db2021-01-25 10:05:40 +0100454 expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list", "example:ovoce", "example:ovocezelenina", "example:twoKeyList", "second:amelie/", "second:fire/", "example:system/", "example:system-state/"};
Václav Kubernáte7248b22020-06-26 15:38:59 +0200455 expectedContextLength = 0;
456 }
457
Václav Kubernát31029682020-10-29 08:23:04 +0100458 SECTION("rpc nodes not completed for the get command")
459 {
460 input = "get ";
Václav Kubernátce108db2021-01-25 10:05:40 +0100461 expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list", "example:ovoce", "example:ovocezelenina", "example:readonly ", "example:twoKeyList", "second:amelie/", "example:system/", "example:system-state/"};
Václav Kubernát31029682020-10-29 08:23:04 +0100462 expectedContextLength = 0;
463 }
464
Václav Kubernát0d47e5e2020-11-17 12:27:05 +0100465 SECTION("leafs not completed for cd")
466 {
467 input = "cd ";
Václav Kubernátce108db2021-01-25 10:05:40 +0100468 expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/","example:list", "example:ovoce", "example:ovocezelenina", "example:twoKeyList", "second:amelie/", "example:system/", "example:system-state/"};
Václav Kubernát0d47e5e2020-11-17 12:27:05 +0100469 expectedContextLength = 0;
470 }
471
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100472 REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength}));
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100473}