blob: 9419051c5c3e9ea8b7b37052af4d86e93ff45dc9 [file] [log] [blame]
Václav Kubernát0d4db442018-07-18 17:18:43 +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át47a3f672019-11-08 15:42:43 +01009#include <experimental/iterator>
Václav Kubernát3a99f002020-03-31 02:27:41 +020010#include "leaf_data_helpers.hpp"
Václav Kubernát1e09bd62020-02-17 15:13:38 +010011#include "pretty_printers.hpp"
Václav Kubernát26b56082020-02-03 18:28:56 +010012#include "trompeloeil_doctest.hpp"
Václav Kubernát0d4db442018-07-18 17:18:43 +020013#include "yang_schema.hpp"
14
Václav Kubernát4f77a252019-02-19 16:51:30 +010015const char* second_schema = R"(
16module second-schema {
17 namespace "http://example.com/nevim";
18 prefix second;
19
20 import example-schema {
21 prefix "example";
22 }
23
Václav Kubernáteeb38842019-03-20 19:46:05 +010024 identity pineapple {
25 base "example:fruit";
26 }
27
Václav Kubernát4f77a252019-02-19 16:51:30 +010028 augment /example:a {
29 container augmentedContainer {
30 }
31 }
32
33 container bla {
34 container bla2 {
35 }
36 }
37}
38)";
39
Václav Kubernát82d74632020-05-11 15:59:53 +020040const char* included_submodule = R"(
41submodule sub-module {
42 yang-version 1.1;
43
44 belongs-to example-schema {
45 prefix sub;
46 }
47
48 leaf subLeaf {
49 type string;
50 }
51}
52)";
53
Václav Kubernát4f77a252019-02-19 16:51:30 +010054const char* example_schema = R"(
Václav Kubernát0d4db442018-07-18 17:18:43 +020055module example-schema {
Václav Kubernát6a713d62018-10-03 18:47:34 +020056 yang-version 1.1;
Václav Kubernát0d4db442018-07-18 17:18:43 +020057 namespace "http://example.com/example-sports";
58 prefix coze;
59
Václav Kubernát82d74632020-05-11 15:59:53 +020060 include sub-module;
61
Václav Kubernáteeb38842019-03-20 19:46:05 +010062 identity drink {
63 }
64
65 identity voda {
66 base "drink";
67 }
68
69 identity food {
70 }
71
72 identity fruit {
73 base "food";
74 }
75
76 identity pizza {
77 base "food";
78 }
79
80 identity hawaii {
81 base "pizza";
82 }
83
Václav Kubernát0d4db442018-07-18 17:18:43 +020084 container a {
85 container a2 {
86 container a3 {
87 presence true;
88 }
89 }
90
91 leaf leafa {
92 type string;
93 }
94 }
95
96 container b {
97 container b2 {
98 presence true;
99 container b3 {
100 }
101 }
102 }
103
104 leaf leafString {
105 type string;
106 }
107
108 leaf leafDecimal {
109 type decimal64 {
110 fraction-digits 5;
111 }
112 }
113
114 leaf leafBool {
115 type boolean;
116 }
117
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200118 leaf leafInt8 {
119 type int8;
120 }
121
122 leaf leafUint8 {
123 type uint8;
124 }
125
126 leaf leafInt16 {
127 type int16;
128 }
129
130 leaf leafUint16 {
131 type uint16;
132 }
133
134 leaf leafInt32 {
Václav Kubernát1e09bd62020-02-17 15:13:38 +0100135 description "A 32-bit integer leaf.";
Václav Kubernát0d4db442018-07-18 17:18:43 +0200136 type int32;
137 }
138
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200139 leaf leafUint32 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200140 type uint32;
141 }
142
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200143 leaf leafInt64 {
144 type int64;
145 }
146
147 leaf leafUint64 {
148 type uint64;
Václav Kubernátb1a75c62020-04-21 15:20:16 +0200149 default 9001;
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200150 }
151
Václav Kubernát0d4db442018-07-18 17:18:43 +0200152 leaf leafEnum {
153 type enumeration {
154 enum lol;
155 enum data;
156 enum coze;
157 }
158 }
159
Václav Kubernát6a713d62018-10-03 18:47:34 +0200160 typedef enumTypedef {
161 type enumeration {
162 enum lol;
163 enum data;
164 enum coze;
165 }
Václav Kubernátb1a75c62020-04-21 15:20:16 +0200166 default data;
Václav Kubernát6a713d62018-10-03 18:47:34 +0200167 }
168
169 typedef enumTypedefRestricted {
170 type enumTypedef {
171 enum lol;
172 enum data;
173 }
174 }
175
176 leaf leafEnumTypedef {
177 type enumTypedef;
178 }
179
180 leaf leafEnumTypedefRestricted {
181 type enumTypedef {
182 enum data;
183 enum coze;
184 }
185 }
186
187 leaf leafEnumTypedefRestricted2 {
188 type enumTypedefRestricted;
189 }
190
Václav Kubernáteeb38842019-03-20 19:46:05 +0100191 leaf foodIdentLeaf {
192 type identityref {
193 base "food";
194 }
195 }
196
197 leaf pizzaIdentLeaf {
198 type identityref {
199 base "pizza";
200 }
201 }
202
203 leaf foodDrinkIdentLeaf {
204 type identityref {
205 base "food";
206 base "drink";
207 }
208 }
209
Václav Kubernát0d4db442018-07-18 17:18:43 +0200210 list _list {
211 key number;
212
213 leaf number {
214 type int32;
215 }
216
217 container contInList {
218 presence true;
219 }
220 }
221
222 list twoKeyList {
223 key "name number";
224
225 leaf number {
226 type int32;
227 }
228
229 leaf name {
230 type string;
231 }
232 }
Václav Kubernát7d82da72019-04-11 15:16:38 +0200233
234 grouping arithmeticFlags {
235 leaf carry {
236 type boolean;
237 }
238 leaf zero {
239 type boolean;
240 }
241 }
242
243 grouping flags {
244 leaf direction {
245 type boolean;
246 }
247 leaf interrupt {
248 type boolean;
249 }
250
251 uses arithmeticFlags;
252 }
253
254 uses flags;
Václav Kubernát280df4a2019-11-01 14:46:34 +0100255
256 choice interface {
257 case caseLoopback {
258 container loopback {
259 leaf ip {
260 type string;
261 }
262 }
263 }
264
265 case caseEthernet {
266 container ethernet {
267 leaf ip {
268 type string;
269 }
270 }
271 }
272 }
273
Václav Kubernáta38d4172019-11-04 12:36:39 +0100274 feature bigPizzas;
275
276 leaf pizzaSize {
277 type enumeration {
278 enum large {
279 if-feature "bigPizzas";
280 }
281 enum medium;
282 enum small;
283 }
284 }
285
Václav Kubernát1e09bd62020-02-17 15:13:38 +0100286 leaf length {
287 type int32;
288 units "m";
289 }
290
291 leaf wavelength {
292 type decimal64 {
293 fraction-digits 10;
294 }
295 units "nm";
296 }
297
298 typedef seconds {
299 type int32;
300 units "s";
301 }
302
303 leaf duration {
304 type seconds;
305 }
306
307 leaf another-duration {
308 type seconds;
309 units "vt";
310 }
311
Václav Kubernátbd5e3c22020-02-19 15:22:00 +0100312 leaf activeNumber {
313 type leafref {
314 path "/_list/number";
315 }
316 }
317
Václav Kubernátfa81c8c2020-02-13 17:22:46 +0100318 rpc myRpc {}
319
Václav Kubernát2984f442020-02-20 17:43:35 +0100320 leaf numberOrString {
321 type union {
322 type int32;
323 type string;
324 }
325 description "Can be an int32 or a string.";
326 }
327
328 list portSettings {
329 key "port";
330 leaf port {
331 type enumeration {
332 enum eth0;
333 enum eth1;
334 enum eth2;
335 }
336 }
337 }
338
339 feature weirdPortNames;
340
341 list portMapping {
342 key "port";
343 leaf port {
344 type enumeration {
345 enum WEIRD {
346 if-feature "weirdPortNames";
347 }
348 enum utf2;
349 enum utf3;
350 }
351 }
352 }
353
354 leaf activeMappedPort {
355 type leafref {
356 path "../portMapping/port";
357 }
358 }
359
360 leaf activePort {
361 type union {
362 type enumeration {
363 enum wlan0;
364 enum wlan1;
365 }
366 type leafref {
367 path "../portSettings/port";
368 }
369 type leafref {
370 path "../activeMappedPort";
371 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200372 type empty;
Václav Kubernát2984f442020-02-20 17:43:35 +0100373 }
374 }
375
Jan Kundrát379bb572020-05-07 03:23:13 +0200376 leaf dummyLeaf {
377 type empty;
378 }
379
Václav Kubernát0599e9f2020-04-21 09:51:33 +0200380 leaf clockSpeed {
381 type int64;
382 config false;
383 }
384
385 container systemStats {
386 config false;
387 leaf upTime {
388 type uint64;
389 }
390 }
391
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +0200392 leaf obsoleteLeaf {
393 type int32;
394 status obsolete;
395 }
396
397 leaf deprecatedLeaf {
398 type int32;
399 status deprecated;
400 }
401
402 typedef deprecatedType {
403 type int32;
404 status deprecated;
405 }
406
407 leaf obsoleteLeafWithDeprecatedType {
408 type deprecatedType;
409 status obsolete;
410 }
411
412 typedef obsoleteType {
413 type int32;
414 status obsolete;
415 }
416
417 leaf obsoleteLeafWithObsoleteType {
418 type deprecatedType;
419 status obsolete;
420 }
421
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200422 leaf-list addresses {
423 type string;
424 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200425})";
426
Václav Kubernát47a3f672019-11-08 15:42:43 +0100427namespace std {
428std::ostream& operator<<(std::ostream& s, const std::set<std::string> set)
429{
430 s << std::endl << "{";
431 std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", "));
432 s << "}" << std::endl;
433 return s;
434}
435}
436
Václav Kubernát0d4db442018-07-18 17:18:43 +0200437TEST_CASE("yangschema")
438{
Václav Kubernát82d74632020-05-11 15:59:53 +0200439 using namespace std::string_literals;
Václav Kubernát4f77a252019-02-19 16:51:30 +0100440 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200441 YangSchema ys;
Václav Kubernát82d74632020-05-11 15:59:53 +0200442 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) {
443 if (modName != "example-schema"sv) {
444 throw std::logic_error("unrecognized module "s + modName);
445 }
446 if (subModule == nullptr) {
447 return example_schema;
448 }
449 if (subModule == "sub-module"sv) {
450 return included_submodule;
451 }
452
453 throw std::logic_error("unrecognized submodule "s + subModule);
Václav Kubernát4f77a252019-02-19 16:51:30 +0100454 });
455 ys.addSchemaString(second_schema);
456
Václav Kubernátefcac932020-01-10 15:26:32 +0100457 schemaPath_ path{Scope::Absolute, {}};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200458 ModuleNodePair node;
459
460 SECTION("positive")
461 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200462 SECTION("isModule")
463 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100464 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200465 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100466
Václav Kubernát0d4db442018-07-18 17:18:43 +0200467 SECTION("listHasKey")
468 {
469 std::string key;
470
471 SECTION("_list")
472 {
Václav Kubernát912b9492020-05-29 02:03:40 +0200473 path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"_list"}});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200474 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200475 {
476 key = "number";
477 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200478 }
479
480 SECTION("twoKeyList")
481 {
Václav Kubernát912b9492020-05-29 02:03:40 +0200482 path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"twoKeyList"}});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200483 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200484 {
485 key = "number";
486 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200487 SECTION("name")
Václav Kubernát912b9492020-05-29 02:03:40 +0200488 {
489 key = "name";
490 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200491 }
492
Václav Kubernát912b9492020-05-29 02:03:40 +0200493 REQUIRE(ys.listHasKey(path, key));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200494 }
495 SECTION("listKeys")
496 {
497 std::set<std::string> set;
498
499 SECTION("_list")
500 {
Václav Kubernát912b9492020-05-29 02:03:40 +0200501 path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"_list"}});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200502 set = {"number"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200503 }
504
505 SECTION("twoKeyList")
506 {
Václav Kubernát912b9492020-05-29 02:03:40 +0200507 path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"twoKeyList"}});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200508 set = {"number", "name"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200509 }
510
Václav Kubernát912b9492020-05-29 02:03:40 +0200511 REQUIRE(ys.listKeys(path) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200512 }
513 SECTION("leafType")
514 {
Václav Kubernát3a99f002020-03-31 02:27:41 +0200515 yang::LeafDataType type;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200516
517 SECTION("leafString")
518 {
519 node.first = "example-schema";
520 node.second = "leafString";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200521 type = yang::String{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200522 }
523
524 SECTION("leafDecimal")
525 {
526 node.first = "example-schema";
527 node.second = "leafDecimal";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200528 type = yang::Decimal{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200529 }
530
531 SECTION("leafBool")
532 {
533 node.first = "example-schema";
534 node.second = "leafBool";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200535 type = yang::Bool{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200536 }
537
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200538 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200539 {
540 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200541 node.second = "leafInt8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200542 type = yang::Int8{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200543 }
544
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200545 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200546 {
547 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200548 node.second = "leafUint8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200549 type = yang::Uint8{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200550 }
551
Václav Kubernátb6d02752020-04-03 00:25:10 +0200552 SECTION("leafInt16")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200553 {
554 node.first = "example-schema";
555 node.second = "leafInt16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200556 type = yang::Int16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200557 }
558
559 SECTION("leafUint16")
560 {
561 node.first = "example-schema";
562 node.second = "leafUint16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200563 type = yang::Uint16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200564 }
565
566 SECTION("leafInt32")
567 {
568 node.first = "example-schema";
569 node.second = "leafInt32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200570 type = yang::Int32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200571 }
572
573 SECTION("leafUint32")
574 {
575 node.first = "example-schema";
576 node.second = "leafUint32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200577 type = yang::Uint32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200578 }
579
580 SECTION("leafInt64")
581 {
582 node.first = "example-schema";
583 node.second = "leafInt64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200584 type = yang::Int64{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200585 }
586
587 SECTION("leafUint64")
588 {
589 node.first = "example-schema";
590 node.second = "leafUint64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200591 type = yang::Uint64{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200592 }
593
594 SECTION("leafEnum")
595 {
596 node.first = "example-schema";
597 node.second = "leafEnum";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200598 type = createEnum({"lol", "data", "coze"});
599 }
600
601 SECTION("leafEnumTypedef")
602 {
603 node.first = "example-schema";
604 node.second = "leafEnumTypedef";
605 type = createEnum({"lol", "data", "coze"});
606 }
607
608 SECTION("leafEnumTypedefRestricted")
609 {
610 node.first = "example-schema";
611 node.second = "leafEnumTypedefRestricted";
612 type = createEnum({"data", "coze"});
613 }
614
615 SECTION("leafEnumTypedefRestricted2")
616 {
617 node.first = "example-schema";
618 node.second = "leafEnumTypedefRestricted2";
619 type = createEnum({"lol", "data"});
620 }
621
622 SECTION("pizzaSize")
623 {
624 node.first = "example-schema";
625 node.second = "pizzaSize";
626
627 SECTION("bigPizzas disabled")
628 {
629 type = createEnum({"small", "medium"});
630 }
631 SECTION("bigPizzas enabled")
632 {
633 ys.enableFeature("example-schema", "bigPizzas");
634 type = createEnum({"small", "medium", "large"});
635 }
636 }
637
638 SECTION("foodIdentLeaf")
639 {
640 node.first = "example-schema";
641 node.second = "foodIdentLeaf";
642 type = yang::IdentityRef{{{"second-schema", "pineapple"},
643 {"example-schema", "food"},
644 {"example-schema", "pizza"},
645 {"example-schema", "hawaii"},
646 {"example-schema", "fruit"}}};
647 }
648
649 SECTION("pizzaIdentLeaf")
650 {
651 node.first = "example-schema";
652 node.second = "pizzaIdentLeaf";
653
654 type = yang::IdentityRef{{
655 {"example-schema", "pizza"},
656 {"example-schema", "hawaii"},
657 }};
658 }
659
660 SECTION("foodDrinkIdentLeaf")
661 {
662 node.first = "example-schema";
663 node.second = "foodDrinkIdentLeaf";
664
665 type = yang::IdentityRef{{
666 {"example-schema", "food"},
667 {"example-schema", "drink"},
668 {"example-schema", "fruit"},
669 {"example-schema", "hawaii"},
670 {"example-schema", "pizza"},
671 {"example-schema", "voda"},
672 {"second-schema", "pineapple"},
673 }};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200674 }
675
Václav Kubernátb6d02752020-04-03 00:25:10 +0200676 SECTION("activeNumber")
677 {
678 node.first = "example-schema";
679 node.second = "activeNumber";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200680 type.emplace<yang::LeafRef>(
681 "/example-schema:_list/number",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200682 std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number"))
Václav Kubernát3a99f002020-03-31 02:27:41 +0200683 );
Václav Kubernátb6d02752020-04-03 00:25:10 +0200684 }
685
Václav Kubernát2984f442020-02-20 17:43:35 +0100686 SECTION("activePort")
687 {
688 node.first = "example-schema";
689 node.second = "activePort";
690
691 yang::Enum enums = [&ys]() {
692 SECTION("weird ports disabled")
693 {
694 return createEnum({"utf2", "utf3"});
695 }
696 SECTION("weird ports enabled")
697 {
698 ys.enableFeature("example-schema", "weirdPortNames");
699 return createEnum({"WEIRD", "utf2", "utf3"});
700 }
701 __builtin_unreachable();
702 }();
703
704 type = yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +0200705 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
706 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100707 "/example-schema:portSettings/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200708 std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"}))
709 }},
710 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100711 "/example-schema:activeMappedPort",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200712 std::make_unique<yang::TypeInfo>(yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100713 "/example-schema:portMapping/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200714 std::make_unique<yang::TypeInfo>(enums)
715 })
716 }},
Jan Kundrát379bb572020-05-07 03:23:13 +0200717 yang::TypeInfo{yang::Empty{}},
Václav Kubernát2984f442020-02-20 17:43:35 +0100718 }};
719 }
720
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200721 SECTION("addresses")
722 {
723 node.first = "example-schema";
724 node.second = "addresses";
725 type.emplace<yang::String>();
726 }
727
728
Václav Kubernát0d4db442018-07-18 17:18:43 +0200729 REQUIRE(ys.leafType(path, node) == type);
730 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200731 SECTION("availableNodes")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200732 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200733 // TODO: merge "path" and "module" sections and add recursive versions to the path section
734 SECTION("paths")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200735 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200736 std::set<ModuleNodePair> set;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200737
Václav Kubernát95b08872020-04-28 01:04:17 +0200738 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200739 SECTION("<root>")
740 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200741 set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"},
742 {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"},
743 {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"},
744 {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"},
745 {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"},
746 {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"},
747 {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"},
748 {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"},
749 {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"},
750 {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"},
751 {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"},
752 {"example-schema"s, "interrupt"},
753 {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"},
754 {"example-schema"s, "pizzaSize"},
755 {"example-schema"s, "length"}, {"example-schema"s, "wavelength"},
756 {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"},
757 {"example-schema"s, "activeNumber"},
758 {"example-schema"s, "numberOrString"},
759 {"example-schema"s, "portSettings"},
760 {"example-schema"s, "portMapping"},
761 {"example-schema"s, "activeMappedPort"},
762 {"example-schema"s, "activePort"},
763 {"example-schema"s, "clockSpeed"},
764 {"example-schema"s, "deprecatedLeaf"},
765 {"example-schema"s, "obsoleteLeaf"},
766 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
767 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200768 {"example-schema"s, "myRpc"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200769 {"example-schema"s, "systemStats"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200770 {"example-schema"s, "dummyLeaf"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200771 {"example-schema"s, "addresses"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200772 {"example-schema"s, "subLeaf"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200773 }
774
775 SECTION("example-schema:a")
776 {
777 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát95b08872020-04-28 01:04:17 +0200778 set = {
779 {boost::none, "a2"},
780 {boost::none, "leafa"},
781 {"second-schema"s, "augmentedContainer"}
782 };
Václav Kubernát3a823f42020-04-29 23:40:21 +0200783 }
784
785 SECTION("example-schema:ethernet")
786 {
787 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("ethernet")));
Václav Kubernát95b08872020-04-28 01:04:17 +0200788 set = {{boost::none, "ip"}};
789 }
790
791 SECTION("second-schema:bla")
792 {
793 path.m_nodes.push_back(schemaNode_(module_{"second-schema"}, container_("bla")));
794 set = {{boost::none, "bla2"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200795 }
796
797 REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200798 }
799
Václav Kubernát3a823f42020-04-29 23:40:21 +0200800 SECTION("modules")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200801 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200802 std::string module;
Václav Kubernát95b08872020-04-28 01:04:17 +0200803 std::set<ModuleNodePair> expectedNonRecursive;
804 std::set<ModuleNodePair> expectedRecursive;
805 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200806 SECTION("example-schema")
807 {
808 module = "example-schema";
809 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200810 {"example-schema"s, "_list"},
811 {"example-schema"s, "a"},
812 {"example-schema"s, "activeMappedPort"},
813 {"example-schema"s, "activeNumber"},
814 {"example-schema"s, "activePort"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200815 {"example-schema"s, "addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200816 {"example-schema"s, "another-duration"},
817 {"example-schema"s, "b"},
818 {"example-schema"s, "carry"},
819 {"example-schema"s, "clockSpeed"},
820 {"example-schema"s, "deprecatedLeaf"},
821 {"example-schema"s, "direction"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200822 {"example-schema"s, "dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200823 {"example-schema"s, "duration"},
824 {"example-schema"s, "ethernet"},
825 {"example-schema"s, "foodDrinkIdentLeaf"},
826 {"example-schema"s, "foodIdentLeaf"},
827 {"example-schema"s, "interrupt"},
828 {"example-schema"s, "leafBool"},
829 {"example-schema"s, "leafDecimal"},
830 {"example-schema"s, "leafEnum"},
831 {"example-schema"s, "leafEnumTypedef"},
832 {"example-schema"s, "leafEnumTypedefRestricted"},
833 {"example-schema"s, "leafEnumTypedefRestricted2"},
834 {"example-schema"s, "leafInt16"},
835 {"example-schema"s, "leafInt32"},
836 {"example-schema"s, "leafInt64"},
837 {"example-schema"s, "leafInt8"},
838 {"example-schema"s, "leafString"},
839 {"example-schema"s, "leafUint16"},
840 {"example-schema"s, "leafUint32"},
841 {"example-schema"s, "leafUint64"},
842 {"example-schema"s, "leafUint8"},
843 {"example-schema"s, "length"},
844 {"example-schema"s, "loopback"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200845 {"example-schema"s, "myRpc"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200846 {"example-schema"s, "numberOrString"},
847 {"example-schema"s, "obsoleteLeaf"},
848 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
849 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
850 {"example-schema"s, "pizzaIdentLeaf"},
851 {"example-schema"s, "pizzaSize"},
852 {"example-schema"s, "portMapping"},
853 {"example-schema"s, "portSettings"},
854 {"example-schema"s, "systemStats"},
855 {"example-schema"s, "twoKeyList"},
856 {"example-schema"s, "wavelength"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200857 {"example-schema"s, "zero"},
858 {"example-schema"s, "subLeaf"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200859 };
860 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200861 {boost::none, "/example-schema:_list"},
862 {boost::none, "/example-schema:_list/contInList"},
863 {boost::none, "/example-schema:_list/number"},
864 {boost::none, "/example-schema:a"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200865 {boost::none, "/example-schema:addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200866 {boost::none, "/example-schema:a/a2"},
867 {boost::none, "/example-schema:a/a2/a3"},
868 {boost::none, "/example-schema:a/leafa"},
869 {boost::none, "/example-schema:a/second-schema:augmentedContainer"},
870 {boost::none, "/example-schema:activeMappedPort"},
871 {boost::none, "/example-schema:activeNumber"},
872 {boost::none, "/example-schema:activePort"},
873 {boost::none, "/example-schema:another-duration"},
874 {boost::none, "/example-schema:b"},
875 {boost::none, "/example-schema:b/b2"},
876 {boost::none, "/example-schema:b/b2/b3"},
877 {boost::none, "/example-schema:carry"},
878 {boost::none, "/example-schema:clockSpeed"},
879 {boost::none, "/example-schema:deprecatedLeaf"},
880 {boost::none, "/example-schema:direction"},
881 {boost::none, "/example-schema:duration"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200882 {boost::none, "/example-schema:dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200883 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
884 {boost::none, "/example-schema:foodIdentLeaf"},
885 {boost::none, "/example-schema:interface/caseEthernet/ethernet"},
886 {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"},
887 {boost::none, "/example-schema:interface/caseLoopback/loopback"},
888 {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"},
889 {boost::none, "/example-schema:interrupt"},
890 {boost::none, "/example-schema:leafBool"},
891 {boost::none, "/example-schema:leafDecimal"},
892 {boost::none, "/example-schema:leafEnum"},
893 {boost::none, "/example-schema:leafEnumTypedef"},
894 {boost::none, "/example-schema:leafEnumTypedefRestricted"},
895 {boost::none, "/example-schema:leafEnumTypedefRestricted2"},
896 {boost::none, "/example-schema:leafInt16"},
897 {boost::none, "/example-schema:leafInt32"},
898 {boost::none, "/example-schema:leafInt64"},
899 {boost::none, "/example-schema:leafInt8"},
900 {boost::none, "/example-schema:leafString"},
901 {boost::none, "/example-schema:leafUint16"},
902 {boost::none, "/example-schema:leafUint32"},
903 {boost::none, "/example-schema:leafUint64"},
904 {boost::none, "/example-schema:leafUint8"},
905 {boost::none, "/example-schema:length"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200906 {boost::none, "/example-schema:myRpc"},
907 {boost::none, "/example-schema:myRpc/input"},
908 {boost::none, "/example-schema:myRpc/output"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200909 {boost::none, "/example-schema:numberOrString"},
910 {boost::none, "/example-schema:obsoleteLeaf"},
911 {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"},
912 {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"},
913 {boost::none, "/example-schema:pizzaIdentLeaf"},
914 {boost::none, "/example-schema:pizzaSize"},
915 {boost::none, "/example-schema:portMapping"},
916 {boost::none, "/example-schema:portMapping/port"},
917 {boost::none, "/example-schema:portSettings"},
918 {boost::none, "/example-schema:portSettings/port"},
919 {boost::none, "/example-schema:systemStats"},
920 {boost::none, "/example-schema:systemStats/upTime"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200921 {boost::none, "/example-schema:subLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200922 {boost::none, "/example-schema:twoKeyList"},
923 {boost::none, "/example-schema:twoKeyList/name"},
924 {boost::none, "/example-schema:twoKeyList/number"},
925 {boost::none, "/example-schema:wavelength"},
926 {boost::none, "/example-schema:zero"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200927 };
928 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200929 SECTION("second-schema")
930 {
931 module = "second-schema";
932 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200933 {"second-schema"s, "bla"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200934 };
935 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200936 {boost::none, "/second-schema:bla"},
937 {boost::none, "/second-schema:bla/bla2"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200938 };
939 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200940
Václav Kubernát3a823f42020-04-29 23:40:21 +0200941 REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive);
942 REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive);
Václav Kubernát47a3f672019-11-08 15:42:43 +0100943 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200944 }
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100945 SECTION("nodeType")
946 {
947 yang::NodeTypes expected;
948 SECTION("leafInt32")
949 {
950 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
951 expected = yang::NodeTypes::Leaf;
952 }
953
954 SECTION("a")
955 {
956 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
957 expected = yang::NodeTypes::Container;
958 }
959
960 SECTION("a/a2/a3")
961 {
962 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
963 path.m_nodes.push_back(schemaNode_(container_("a2")));
964 path.m_nodes.push_back(schemaNode_(container_("a3")));
965 expected = yang::NodeTypes::PresenceContainer;
966 }
967
968 SECTION("_list")
969 {
970 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, list_("_list")));
971 expected = yang::NodeTypes::List;
972 }
973
Václav Kubernát82d74632020-05-11 15:59:53 +0200974 SECTION("subLeaf")
975 {
976 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("subLeaf")));
977 expected = yang::NodeTypes::Leaf;
978 }
979
Václav Kubernát34ee85a2020-02-18 17:12:12 +0100980 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
981 }
Václav Kubernát1e09bd62020-02-17 15:13:38 +0100982
983 SECTION("description")
984 {
985 std::optional<std::string> expected;
986 SECTION("leafInt32")
987 {
988 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
989 expected = "A 32-bit integer leaf.";
990 }
991
992 SECTION("leafString")
993 {
994 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafString")));
995 }
996
Václav Kubernát2984f442020-02-20 17:43:35 +0100997 SECTION("numberOrString")
998 {
999 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("numberOrString")));
1000 expected = "Can be an int32 or a string.";
1001 }
1002
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001003 REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1004 }
1005
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +02001006 SECTION("status")
1007 {
1008 REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current);
1009 REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete);
1010 REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated);
1011 REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete);
1012 REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete);
1013 }
1014
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001015 SECTION("units")
1016 {
Václav Kubernát13b23d72020-04-16 21:49:51 +02001017 yang::LeafDataType expectedType;
1018 std::optional<std::string> expectedUnits;
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001019 SECTION("length")
1020 {
1021 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("length")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001022 expectedType.emplace<yang::Int32>();
1023 expectedUnits = "m";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001024 }
1025
1026 SECTION("wavelength")
1027 {
1028 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("wavelength")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001029 expectedType.emplace<yang::Decimal>();
1030 expectedUnits = "nm";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001031 }
1032
1033 SECTION("leafInt32")
1034 {
1035 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001036 expectedType.emplace<yang::Int32>();
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001037 }
1038
1039 SECTION("duration")
1040 {
1041 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("duration")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001042 expectedType.emplace<yang::Int32>();
1043 expectedUnits = "s";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001044 }
1045
1046 SECTION("another-duration")
1047 {
1048 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("another-duration")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001049 expectedType.emplace<yang::Int32>();
1050 expectedUnits = "vt";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001051 }
Václav Kubernát5b8a8f32020-05-20 00:57:22 +02001052 auto nodeType = ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded));
1053 REQUIRE((nodeType == yang::NodeTypes::Leaf || nodeType == yang::NodeTypes::LeafList));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001054 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits});
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001055 }
1056
1057 SECTION("nodeType")
1058 {
1059 yang::NodeTypes expected;
1060 SECTION("leafInt32")
1061 {
1062 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
1063 expected = yang::NodeTypes::Leaf;
1064 }
1065
1066 SECTION("a")
1067 {
1068 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1069 expected = yang::NodeTypes::Container;
1070 }
1071
1072 SECTION("a/a2/a3")
1073 {
1074 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1075 path.m_nodes.push_back(schemaNode_(container_("a2")));
1076 path.m_nodes.push_back(schemaNode_(container_("a3")));
1077 expected = yang::NodeTypes::PresenceContainer;
1078 }
1079
1080 SECTION("_list")
1081 {
1082 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, list_("_list")));
1083 expected = yang::NodeTypes::List;
1084 }
1085
1086 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1087 }
Václav Kubernátbd5e3c22020-02-19 15:22:00 +01001088
1089 SECTION("leafrefPath")
1090 {
1091 REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number");
1092 }
Václav Kubernát0599e9f2020-04-21 09:51:33 +02001093
1094 SECTION("isConfig")
1095 {
1096 REQUIRE(ys.isConfig("/example-schema:leafInt32"));
1097 REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed"));
1098 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats"));
1099 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime"));
1100 }
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001101
Václav Kubernátb1a75c62020-04-21 15:20:16 +02001102 SECTION("defaultValue")
1103 {
1104 REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001");
1105 REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data");
1106 REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt);
1107 }
1108
Václav Kubernát76ba4ec2020-05-18 13:26:56 +02001109 SECTION("leafTypeName")
1110 {
1111 REQUIRE(ys.leafTypeName("/example-schema:leafEnumTypedefRestricted") == "enumTypedef");
1112 REQUIRE(ys.leafTypeName("/example-schema:leafInt32") == std::nullopt);
1113 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001114 }
1115
1116 SECTION("negative")
1117 {
1118 SECTION("nonexistent nodes")
1119 {
1120 SECTION("example-schema:coze")
1121 {
1122 node.first = "example-schema";
1123 node.second = "coze";
1124 }
1125
1126 SECTION("example-schema:a/nevim")
1127 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001128 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001129 node.second = "nevim";
1130 }
1131
1132 SECTION("modul:a/nevim")
1133 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001134 path.m_nodes.push_back(schemaNode_(module_{"modul"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001135 node.second = "nevim";
1136 }
1137
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001138 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001139 }
1140
1141 SECTION("nodetype-specific methods called with different nodetypes")
1142 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001143 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát912b9492020-05-29 02:03:40 +02001144 path.m_nodes.push_back(schemaNode_(container_("a2")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001145
Václav Kubernát912b9492020-05-29 02:03:40 +02001146 REQUIRE(!ys.listHasKey(path, "chacha"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001147 }
1148
1149 SECTION("nonexistent module")
1150 {
Václav Kubernát75877de2019-11-20 17:43:02 +01001151 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001152 }
Václav Kubernáteeb38842019-03-20 19:46:05 +01001153
Václav Kubernát7d82da72019-04-11 15:16:38 +02001154 SECTION("grouping is not a node")
1155 {
1156 SECTION("example-schema:arithmeticFlags")
1157 {
1158 node.first = "example-schema";
1159 node.second = "arithmeticFlags";
1160 }
1161
1162 SECTION("example-schema:flags")
1163 {
1164 node.first = "example-schema";
1165 node.second = "startAndStop";
1166 }
1167
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001168 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát7d82da72019-04-11 15:16:38 +02001169 }
Václav Kubernát280df4a2019-11-01 14:46:34 +01001170
1171 SECTION("choice is not a node")
1172 {
1173 SECTION("example-schema:interface")
1174 {
1175 node.first = "example-schema";
1176 node.second = "interface";
1177 }
1178
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001179 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001180 }
1181
1182 SECTION("case is not a node")
1183 {
1184 SECTION("example-schema:caseLoopback")
1185 {
1186 node.first = "example-schema";
1187 node.second = "caseLoopback";
1188 }
1189
1190 SECTION("example-schema:caseEthernet")
1191 {
1192 node.first = "example-schema";
1193 node.second = "caseEthernet";
1194 }
1195
Václav Kubernáte811bfa2020-05-29 02:25:20 +02001196 REQUIRE_THROWS(ys.nodeType(path, node));
Václav Kubernát280df4a2019-11-01 14:46:34 +01001197 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001198 }
1199}