blob: 53194c0a509b178cb99d231bbc7d7897609271f4 [file] [log] [blame]
Václav Kubernát07204242018-06-04 18:12:09 +02001/*
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"
Jan Kundrát76b3ddc2019-07-03 10:31:27 +020010#include <boost/core/demangle.hpp>
Václav Kubernát24df80e2018-06-06 15:18:03 +020011#include "ast_commands.hpp"
Václav Kubernát3a99f002020-03-31 02:27:41 +020012#include "leaf_data_helpers.hpp"
Václav Kubernát07204242018-06-04 18:12:09 +020013#include "parser.hpp"
Václav Kubernáted824d02020-06-09 15:48:30 +020014#include "pretty_printers.hpp"
Václav Kubernátbddbb172018-06-13 16:27:39 +020015#include "static_schema.hpp"
Václav Kubernát509ce652019-05-29 19:46:44 +020016#include "utils.hpp"
Václav Kubernát07204242018-06-04 18:12:09 +020017
18TEST_CASE("leaf editing")
19{
Václav Kubernátbddbb172018-06-13 16:27:39 +020020 auto schema = std::make_shared<StaticSchema>();
Václav Kubernát744f57f2018-06-29 22:46:26 +020021 schema->addModule("mod");
Václav Kubernáteeb38842019-03-20 19:46:05 +010022 schema->addModule("pizza-module");
Václav Kubernátefcac932020-01-10 15:26:32 +010023 schema->addContainer("/", "mod:contA");
Václav Kubernát3a99f002020-03-31 02:27:41 +020024 schema->addLeaf("/", "mod:leafString", yang::String{});
25 schema->addLeaf("/", "mod:leafDecimal", yang::Decimal{});
26 schema->addLeaf("/", "mod:leafBool", yang::Bool{});
27 schema->addLeaf("/", "mod:leafInt8", yang::Int8{});
28 schema->addLeaf("/", "mod:leafInt16", yang::Int16{});
29 schema->addLeaf("/", "mod:leafInt32", yang::Int32{});
30 schema->addLeaf("/", "mod:leafInt64", yang::Int64{});
31 schema->addLeaf("/", "mod:leafUint8", yang::Uint8{});
32 schema->addLeaf("/", "mod:leafUint16", yang::Uint16{});
33 schema->addLeaf("/", "mod:leafUint32", yang::Uint32{});
34 schema->addLeaf("/", "mod:leafUint64", yang::Uint64{});
35 schema->addLeaf("/", "mod:leafBinary", yang::Binary{});
Václav Kubernát222ecff2020-05-14 23:14:35 +020036 schema->addIdentity(std::nullopt, identityRef_{"mod", "food"});
37 schema->addIdentity(std::nullopt, identityRef_{"mod", "vehicle"});
38 schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "pizza"});
39 schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "spaghetti"});
40 schema->addIdentity(identityRef_{"mod", "pizza"}, identityRef_{"pizza-module", "hawaii"});
Václav Kubernát3a99f002020-03-31 02:27:41 +020041 schema->addLeaf("/", "mod:foodIdentRef", yang::IdentityRef{schema->validIdentities("mod", "food")});
42 schema->addLeaf("/", "mod:pizzaIdentRef", yang::IdentityRef{schema->validIdentities("mod", "pizza")});
43 schema->addLeaf("/mod:contA", "mod:identInCont", yang::IdentityRef{schema->validIdentities("mod", "pizza")});
44 schema->addLeaf("/", "mod:leafEnum", createEnum({"lol", "data", "coze"}));
45 schema->addLeaf("/mod:contA", "mod:leafInCont", yang::String{});
Václav Kubernátefcac932020-01-10 15:26:32 +010046 schema->addList("/", "mod:list", {"number"});
Václav Kubernát3a99f002020-03-31 02:27:41 +020047 schema->addLeaf("/mod:list", "mod:number", yang::Int32{});
48 schema->addLeaf("/mod:list", "mod:leafInList", yang::String{});
Václav Kubernát13b23d72020-04-16 21:49:51 +020049 schema->addLeaf("/", "mod:refToString", yang::LeafRef{"/mod:leafString", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafString"))});
50 schema->addLeaf("/", "mod:refToInt8", yang::LeafRef{"/mod:leafInt8", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafInt8"))});
51 schema->addLeaf("/", "mod:refToLeafInCont", yang::LeafRef{"/mod:contA/identInCont", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:contA/mod:identInCont"))});
52 schema->addLeaf("/", "mod:intOrString", yang::Union{{yang::TypeInfo{yang::Int32{}}, yang::TypeInfo{yang::String{}}}});
53 schema->addLeaf("/", "mod:twoInts", yang::Union{{yang::TypeInfo{yang::Uint8{}}, yang::TypeInfo{yang::Int16{}}}});
Václav Kubernát2984f442020-02-20 17:43:35 +010054 schema->addLeaf("/", "mod:unionStringEnumLeafref", yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +020055 yang::LeafDataType{yang::String{}},
56 yang::LeafDataType{createEnum({"foo", "bar"})},
57 yang::LeafDataType{yang::LeafRef{"/mod:leafEnum", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafEnum"))}}
Václav Kubernát2984f442020-02-20 17:43:35 +010058 }});
59
60 schema->addList("/", "mod:portSettings", {"port"});
61 schema->addLeaf("/mod:portSettings", "mod:port", createEnum({"eth0", "eth1", "eth2"}));
62 schema->addList("/", "mod:portMapping", {"port"});
63 schema->addLeaf("/mod:portMapping", "mod:port", createEnum({"utf1", "utf2", "utf3"}));
Václav Kubernát13b23d72020-04-16 21:49:51 +020064 schema->addLeaf("/", "mod:activeMappedPort", yang::LeafRef{"/mod:portMapping/mod:port", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:portMapping/mod:port"))});
Václav Kubernát2984f442020-02-20 17:43:35 +010065 schema->addLeaf("/", "mod:activePort", yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +020066 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
67 yang::TypeInfo{yang::LeafRef{"/mod:portSettings/mod:port", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:portSettings/mod:port"))}},
68 yang::TypeInfo{yang::LeafRef{"/mod:activeMappedPort", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:activeMappedPort"))}},
Jan Kundrát379bb572020-05-07 03:23:13 +020069 yang::TypeInfo{yang::Empty{}},
Václav Kubernát2984f442020-02-20 17:43:35 +010070 }});
Jan Kundrát379bb572020-05-07 03:23:13 +020071 schema->addLeaf("/", "mod:dummy", yang::Empty{});
Václav Kubernátabf52802020-05-19 01:31:17 +020072 schema->addLeaf("/", "mod:readonly", yang::Int32{}, yang::AccessType::ReadOnly);
Václav Kubernát2984f442020-02-20 17:43:35 +010073
Václav Kubernát07204242018-06-04 18:12:09 +020074 Parser parser(schema);
75 std::string input;
76 std::ostringstream errorStream;
77
78 SECTION("valid input")
79 {
80 set_ expected;
81
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010082 SECTION("set mod:leafString \"some_data\"")
Václav Kubernát07204242018-06-04 18:12:09 +020083 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010084 input = "set mod:leafString \'some_data\'";
Václav Kubernátfaacd022020-07-08 16:44:38 +020085 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafString"));
Václav Kubernátebca2552018-06-08 19:06:02 +020086 expected.m_data = std::string("some_data");
Václav Kubernát07204242018-06-04 18:12:09 +020087 }
88
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010089 SECTION("set mod:contA/leafInCont 'more_data'")
Václav Kubernát07204242018-06-04 18:12:09 +020090 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010091 input = "set mod:contA/leafInCont 'more_data'";
Václav Kubernátfaacd022020-07-08 16:44:38 +020092 expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA"));
93 expected.m_path.m_nodes.emplace_back(leaf_("leafInCont"));
Václav Kubernátebca2552018-06-08 19:06:02 +020094 expected.m_data = std::string("more_data");
95 }
96
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010097 SECTION("set mod:contA/leafInCont \"data with' a quote\"")
Václav Kubernátc18ffac2020-01-10 16:06:06 +010098 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +010099 input = "set mod:contA/leafInCont \"data with' a quote\"";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200100 expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA"));
101 expected.m_path.m_nodes.emplace_back(leaf_("leafInCont"));
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100102 expected.m_data = std::string("data with' a quote");
103 }
104
105 SECTION("set mod:contA/leafInCont 'data with\" a quote'")
106 {
107 input = "set mod:contA/leafInCont 'data with\" a quote'";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200108 expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA"));
109 expected.m_path.m_nodes.emplace_back(leaf_("leafInCont"));
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100110 expected.m_data = std::string("data with\" a quote");
111 }
112
113 SECTION("set mod:contA/leafInCont 'more d\tata'") // spaces in string
114 {
115 input = "set mod:contA/leafInCont 'more d\tata'";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200116 expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA"));
117 expected.m_path.m_nodes.emplace_back(leaf_("leafInCont"));
Václav Kubernátc18ffac2020-01-10 16:06:06 +0100118 expected.m_data = std::string("more d\tata");
119 }
120
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100121 SECTION("set mod:list[number=1]/leafInList \"another_data\"")
Václav Kubernátebca2552018-06-08 19:06:02 +0200122 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100123 input = "set mod:list[number=1]/leafInList \"another_data\"";
Václav Kubernátc15fe822020-06-04 11:28:39 +0200124 auto keys = ListInstance {
Václav Kubernát7707cae2020-01-16 12:04:53 +0100125 {"number", int32_t{1}}};
Václav Kubernátfaacd022020-07-08 16:44:38 +0200126 expected.m_path.m_nodes.emplace_back(module_{"mod"}, listElement_("list", keys));
127 expected.m_path.m_nodes.emplace_back(leaf_("leafInList"));
Václav Kubernátebca2552018-06-08 19:06:02 +0200128 expected.m_data = std::string("another_data");
129 }
130
131 SECTION("data types")
132 {
133 SECTION("string")
134 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100135 input = "set mod:leafString \"somedata\"";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200136 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafString"));
Václav Kubernátebca2552018-06-08 19:06:02 +0200137 expected.m_data = std::string("somedata");
138 }
139
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200140 SECTION("int8")
Václav Kubernátebca2552018-06-08 19:06:02 +0200141 {
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200142 input = "set mod:leafInt8 2";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200143 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt8"));
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200144 expected.m_data = int8_t{2};
145 }
146
147 SECTION("negative int8")
148 {
149 input = "set mod:leafInt8 -10";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200150 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt8"));
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200151 expected.m_data = int8_t{-10};
152 }
153
154 SECTION("uint8")
155 {
156 input = "set mod:leafUint8 2";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200157 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint8"));
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200158 expected.m_data = uint8_t{2};
159 }
160
161 SECTION("int16")
162 {
163 input = "set mod:leafInt16 30000";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200164 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt16"));
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200165 expected.m_data = int16_t{30'000};
166 }
167
168 SECTION("uint16")
169 {
170 input = "set mod:leafUint16 30000";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200171 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint16"));
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200172 expected.m_data = uint16_t{30'000};
173 }
174
175 SECTION("int32")
176 {
177 input = "set mod:leafInt32 30000";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200178 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt32"));
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200179 expected.m_data = int32_t{30'000};
180 }
181
182 SECTION("uint32")
183 {
184 input = "set mod:leafUint32 30000";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200185 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint32"));
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200186 expected.m_data = uint32_t{30'000};
187 }
188
189 SECTION("int32")
190 {
191 input = "set mod:leafInt32 30000";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200192 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt32"));
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200193 expected.m_data = int32_t{30'000};
194 }
195
196 SECTION("uint64")
197 {
198 input = "set mod:leafUint64 30000";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200199 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint64"));
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200200 expected.m_data = uint64_t{30'000};
Václav Kubernátebca2552018-06-08 19:06:02 +0200201 }
202
203 SECTION("decimal")
204 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200205 input = "set mod:leafDecimal 3.14159";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200206 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafDecimal"));
Václav Kubernátebca2552018-06-08 19:06:02 +0200207 expected.m_data = 3.14159;
208 }
209
210 SECTION("enum")
211 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200212 input = "set mod:leafEnum coze";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200213 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafEnum"));
Václav Kubernátebca2552018-06-08 19:06:02 +0200214 expected.m_data = enum_("coze");
215 }
216
217 SECTION("bool")
218 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200219 input = "set mod:leafBool true";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200220 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafBool"));
Václav Kubernátebca2552018-06-08 19:06:02 +0200221 expected.m_data = true;
222 }
Václav Kubernátab538992019-03-06 15:30:50 +0100223
Václav Kubernát2984f442020-02-20 17:43:35 +0100224 SECTION("union")
225 {
226 SECTION("int")
227 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200228 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("intOrString"));
Václav Kubernát2984f442020-02-20 17:43:35 +0100229 input = "set mod:intOrString 90";
230 expected.m_data = int32_t{90};
231 }
232 SECTION("string")
233 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200234 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("intOrString"));
Václav Kubernát2984f442020-02-20 17:43:35 +0100235 input = "set mod:intOrString \"test\"";
236 expected.m_data = std::string{"test"};
237 }
238
239 SECTION("union with two integral types")
240 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200241 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("twoInts"));
Václav Kubernát2984f442020-02-20 17:43:35 +0100242 SECTION("uint8")
243 {
244 input = "set mod:twoInts 100";
245 expected.m_data = uint8_t{100};
246 }
247 SECTION("int16")
248 {
249 input = "set mod:twoInts 6666";
250 expected.m_data = int16_t{6666};
251 }
252 }
253
254 SECTION("union with enum and leafref to enum")
255 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200256 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("unionStringEnumLeafref"));
Václav Kubernát2984f442020-02-20 17:43:35 +0100257 SECTION("string")
258 {
259 input = "set mod:unionStringEnumLeafref \"AHOJ\"";
260 expected.m_data = std::string{"AHOJ"};
261 }
262 SECTION("enum")
263 {
264 input = "set mod:unionStringEnumLeafref bar";
265 expected.m_data = enum_("bar");
266 }
267 SECTION("enum leafref")
268 {
269 input = "set mod:unionStringEnumLeafref coze";
270 expected.m_data = enum_("coze");
271 }
272 }
273
274 SECTION("activePort")
275 {
Václav Kubernátfaacd022020-07-08 16:44:38 +0200276 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("activePort"));
Václav Kubernát2984f442020-02-20 17:43:35 +0100277 input = "set mod:activePort ";
278 SECTION("1. anonymous enum")
279 {
280 SECTION("wlan0")
281 {
282 input += "wlan0";
283 expected.m_data = enum_("wlan0");
284 }
285 SECTION("wlan1")
286 {
287 input += "wlan1";
288 expected.m_data = enum_("wlan1");
289 }
290 }
291 SECTION("2. leafref to enum")
292 {
293 SECTION("eth0")
294 {
295 input += "eth0";
296 expected.m_data = enum_("eth0");
297 }
298 SECTION("eth1")
299 {
300 input += "eth1";
301 expected.m_data = enum_("eth1");
302 }
303 SECTION("eth2")
304 {
305 input += "eth2";
306 expected.m_data = enum_("eth2");
307 }
308 }
309 SECTION("3. leafref to leafref")
310 {
311 SECTION("utf1")
312 {
313 input += "utf1";
314 expected.m_data = enum_("utf1");
315 }
316 SECTION("utf2")
317 {
318 input += "utf2";
319 expected.m_data = enum_("utf2");
320 }
321 SECTION("utf3")
322 {
323 input += "utf3";
324 expected.m_data = enum_("utf3");
325 }
326 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200327 SECTION("4. empty")
328 {
329 expected.m_data = empty_{};
330 }
Václav Kubernát2984f442020-02-20 17:43:35 +0100331 }
332 }
333
Václav Kubernátab538992019-03-06 15:30:50 +0100334 SECTION("binary")
335 {
336 SECTION("zero ending '='")
337 {
338 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++";
339 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++"};
340 }
341
342 SECTION("one ending '='")
343 {
344 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++=";
345 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++="};
346 }
347
348 SECTION("two ending '='")
349 {
350 input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++==";
351 expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++=="};
352 }
Václav Kubernátfaacd022020-07-08 16:44:38 +0200353 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafBinary"));
Václav Kubernátab538992019-03-06 15:30:50 +0100354 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100355
356 SECTION("identityRef")
357 {
358 SECTION("foodIdentRef")
359 {
360 input = "set mod:foodIdentRef ";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200361 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("foodIdentRef"));
Václav Kubernáteeb38842019-03-20 19:46:05 +0100362
363 SECTION("food")
364 {
365 input += "food";
366 expected.m_data = identityRef_("food");
367 }
368 SECTION("mod:food")
369 {
370 input += "mod:food";
371 expected.m_data = identityRef_("mod", "food");
372 }
373 SECTION("pizza")
374 {
375 input += "pizza";
376 expected.m_data = identityRef_("pizza");
377 }
378 SECTION("mod:pizza")
379 {
380 input += "mod:pizza";
381 expected.m_data = identityRef_("mod", "pizza");
382 }
383 SECTION("pizza-module:hawaii")
384 {
385 input += "pizza-module:hawaii";
386 expected.m_data = identityRef_("pizza-module", "hawaii");
387 }
388 }
389 SECTION("pizzaIdentRef")
390 {
391 input = "set mod:pizzaIdentRef ";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200392 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("pizzaIdentRef"));
Václav Kubernáteeb38842019-03-20 19:46:05 +0100393 SECTION("pizza")
394 {
395 input += "pizza";
396 expected.m_data = identityRef_("pizza");
397 }
398 SECTION("mod:pizza")
399 {
400 input += "mod:pizza";
401 expected.m_data = identityRef_("mod", "pizza");
402 }
403 SECTION("pizza-module:hawaii")
404 {
405 input += "pizza-module:hawaii";
406 expected.m_data = identityRef_("pizza-module", "hawaii");
407 }
408 }
409 SECTION("mod:contA/identInCont")
410 {
411 input = "set mod:contA/identInCont ";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200412 expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA"));
413 expected.m_path.m_nodes.emplace_back(leaf_("identInCont"));
Václav Kubernáteeb38842019-03-20 19:46:05 +0100414 SECTION("pizza")
415 {
416 input += "pizza";
417 expected.m_data = identityRef_("pizza");
418 }
419 SECTION("mod:pizza")
420 {
421 input += "mod:pizza";
422 expected.m_data = identityRef_("mod", "pizza");
423 }
424 SECTION("pizza-module:hawaii")
425 {
426 input += "pizza-module:hawaii";
427 expected.m_data = identityRef_("pizza-module", "hawaii");
428 }
429 }
430 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200431 SECTION("leafRef")
432 {
433 SECTION("refToString")
434 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100435 input = "set mod:refToString \"blabal\"";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200436 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("refToString"));
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200437 expected.m_data = std::string("blabal");
438 }
439
440 SECTION("refToInt8")
441 {
442 input = "set mod:refToInt8 42";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200443 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("refToInt8"));
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200444 expected.m_data = int8_t{42};
445 }
Václav Kubernát2d7b05c2020-04-05 14:02:37 +0200446
447 SECTION("refToLeafInCont")
448 {
449 input = "set mod:refToLeafInCont pizza";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200450 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("refToLeafInCont"));
Václav Kubernát2d7b05c2020-04-05 14:02:37 +0200451 expected.m_data = identityRef_{"pizza"};
452 }
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200453 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200454 SECTION("empty")
455 {
456 input = "set mod:dummy ";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200457 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("dummy"));
Jan Kundrát379bb572020-05-07 03:23:13 +0200458 expected.m_data = empty_{};
459 }
Václav Kubernát07204242018-06-04 18:12:09 +0200460 }
461
462 command_ command = parser.parseCommand(input, errorStream);
463 REQUIRE(command.type() == typeid(set_));
464 REQUIRE(boost::get<set_>(command) == expected);
465 }
466
467 SECTION("invalid input")
468 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100469 std::string expectedError;
Václav Kubernát07204242018-06-04 18:12:09 +0200470 SECTION("missing space between a command and its arguments")
471 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100472 SECTION("setmod:leafString some_data")
Václav Kubernát07204242018-06-04 18:12:09 +0200473 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100474 input = "setmod:leafString 'some_data'";
Václav Kubernát07204242018-06-04 18:12:09 +0200475 }
476 }
477
478 SECTION("missing space between arguments")
479 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100480 SECTION("set mod:leafString'lol'")
Václav Kubernát07204242018-06-04 18:12:09 +0200481 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100482 input = "set mod:leafString'lol'";
Václav Kubernát07204242018-06-04 18:12:09 +0200483 }
484 }
485
486 SECTION("non-leaf identifiers")
487 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100488 SECTION("set mod:nonexistent 'blabla'")
Václav Kubernát07204242018-06-04 18:12:09 +0200489 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100490 input = "set mod:nonexistent 'blabla'";
Václav Kubernát07204242018-06-04 18:12:09 +0200491 }
492
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100493 SECTION("set mod:contA 'abde'")
Václav Kubernát07204242018-06-04 18:12:09 +0200494 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100495 input = "set mod:contA 'abde'";
Václav Kubernát07204242018-06-04 18:12:09 +0200496 }
497 }
498
Václav Kubernátebca2552018-06-08 19:06:02 +0200499 SECTION("wrong types")
500 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100501 expectedError = "leaf data type mismatch";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100502 SECTION("set mod:leafBool 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200503 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100504 input = "set mod:leafBool 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200505 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100506 SECTION("set mod:leafUint8 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200507 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100508 input = "set mod:leafUint8 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200509 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100510 SECTION("set mod:leafUint8 -5")
Václav Kubernátebca2552018-06-08 19:06:02 +0200511 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100512 input = "set mod:leafUint8 -5";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200513 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100514 SECTION("set mod:leafInt8 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200515 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100516 input = "set mod:leafInt8 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200517 }
Václav Kubernát777704d2020-01-15 18:48:06 +0100518 SECTION("set mod:leafInt8 130")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200519 {
Václav Kubernát777704d2020-01-15 18:48:06 +0100520 input = "set mod:leafInt8 130";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200521 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100522 SECTION("set mod:leafUint16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200523 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100524 input = "set mod:leafUint16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200525 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100526 SECTION("set mod:leafInt16 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200527 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100528 input = "set mod:leafInt16 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200529 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100530 SECTION("set mod:leafUint32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200531 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100532 input = "set mod:leafUint32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200533 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100534 SECTION("set mod:leafInt32 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200535 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100536 input = "set mod:leafInt32 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200537 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100538 SECTION("set mod:leafUint64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200539 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100540 input = "set mod:leafUint64 'blabla'";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200541 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100542 SECTION("set mod:leafInt64 'blabla'")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200543 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100544 input = "set mod:leafInt64 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200545 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100546 SECTION("set mod:leafEnum 'blabla'")
Václav Kubernátebca2552018-06-08 19:06:02 +0200547 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100548 input = "set mod:leafEnum 'blabla'";
Václav Kubernátebca2552018-06-08 19:06:02 +0200549 }
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100550 SECTION("set mod:refToInt8 'blabla'")
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200551 {
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100552 input = "set mod:refToInt8 'blabla'";
Václav Kubernát6a8d1d92019-04-24 20:30:36 +0200553 }
Václav Kubernátebca2552018-06-08 19:06:02 +0200554 }
555
Václav Kubernátab538992019-03-06 15:30:50 +0100556 SECTION("wrong base64 strings")
557 {
558 SECTION("invalid character")
Václav Kubernát777704d2020-01-15 18:48:06 +0100559 input = "set mod:leafBinary dbahj-";
Václav Kubernátab538992019-03-06 15:30:50 +0100560 SECTION("equal sign in the middle")
Václav Kubernát777704d2020-01-15 18:48:06 +0100561 input = "set mod:leafBinary db=ahj";
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100562 SECTION("enclosing in quotes")
563 input = "set mod:leafBinary 'dbahj'";
Václav Kubernátab538992019-03-06 15:30:50 +0100564 }
565
Václav Kubernáteeb38842019-03-20 19:46:05 +0100566 SECTION("non-existing identity")
567 {
568 input = "set mod:foodIdentRef identityBLABLA";
569 }
570
Václav Kubernátf365ecf2020-06-09 16:22:43 +0200571 SECTION("identity with non-existing module")
572 {
573 expectedError = "Invalid module name";
574 input = "set mod:foodIdentRef xd:haha";
575 }
576
Václav Kubernáteeb38842019-03-20 19:46:05 +0100577 SECTION("setting identities with wrong bases")
578 {
579 SECTION("set mod:foodIdentRef mod:vehicle")
580 {
581 input = "set mod:foodIdentRef mod:vehicle";
582 }
583 SECTION("set mod:pizzaIdentRef mod:food")
584 {
585 input = "set mod:pizzaIdentRef mod:food";
586 }
587 }
588 SECTION("setting different module identities without prefix")
589 {
590 input = "set mod:pizzaIdentRef hawaii";
591 }
592 SECTION("identity prefix without name")
593 {
594 input = "set mod:contA/identInCont pizza-module:";
595 }
596
Václav Kubernát2984f442020-02-20 17:43:35 +0100597 SECTION("set a union path to a wrong type")
598 {
599 input = "set mod:intOrString true";
600 }
601
Jan Kundrát379bb572020-05-07 03:23:13 +0200602 SECTION("no space for empty data")
603 {
604 input = "set mod:dummy";
605 }
606
Václav Kubernát0d42c512020-05-20 21:18:39 +0200607 SECTION("empty path")
608 {
609 input = "set ";
610 }
611
Václav Kubernátabf52802020-05-19 01:31:17 +0200612 SECTION("setting readonly data")
613 {
614 input = "set mod:readonly 123";
615 }
616
Jan Kundrátc381e632019-03-14 13:39:11 +0100617 REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException);
Václav Kubernát777704d2020-01-15 18:48:06 +0100618 REQUIRE(errorStream.str().find(expectedError) != std::string::npos);
Václav Kubernát07204242018-06-04 18:12:09 +0200619 }
Jan Kundrátb7206ad2020-06-18 21:08:14 +0200620
621 SECTION("deleting a leaf")
622 {
623 delete_ expected;
624 input = "delete mod:leafString";
Václav Kubernátfaacd022020-07-08 16:44:38 +0200625 expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafString"));
Jan Kundrátb7206ad2020-06-18 21:08:14 +0200626
627 command_ command = parser.parseCommand(input, errorStream);
628 REQUIRE(command.type() == typeid(delete_));
629 REQUIRE(boost::get<delete_>(command) == expected);
630 }
Václav Kubernát07204242018-06-04 18:12:09 +0200631}