blob: 79bad710f893c4adafa102c9ebe20503347d473a [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át0d4db442018-07-18 17:18:43 +0200422})";
423
Václav Kubernát47a3f672019-11-08 15:42:43 +0100424namespace std {
425std::ostream& operator<<(std::ostream& s, const std::set<std::string> set)
426{
427 s << std::endl << "{";
428 std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", "));
429 s << "}" << std::endl;
430 return s;
431}
432}
433
Václav Kubernát0d4db442018-07-18 17:18:43 +0200434TEST_CASE("yangschema")
435{
Václav Kubernát82d74632020-05-11 15:59:53 +0200436 using namespace std::string_literals;
Václav Kubernát4f77a252019-02-19 16:51:30 +0100437 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200438 YangSchema ys;
Václav Kubernát82d74632020-05-11 15:59:53 +0200439 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) {
440 if (modName != "example-schema"sv) {
441 throw std::logic_error("unrecognized module "s + modName);
442 }
443 if (subModule == nullptr) {
444 return example_schema;
445 }
446 if (subModule == "sub-module"sv) {
447 return included_submodule;
448 }
449
450 throw std::logic_error("unrecognized submodule "s + subModule);
Václav Kubernát4f77a252019-02-19 16:51:30 +0100451 });
452 ys.addSchemaString(second_schema);
453
Václav Kubernátefcac932020-01-10 15:26:32 +0100454 schemaPath_ path{Scope::Absolute, {}};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200455 ModuleNodePair node;
456
457 SECTION("positive")
458 {
459 SECTION("isContainer")
460 {
461 SECTION("example-schema:a")
462 {
463 node.first = "example-schema";
464 node.second = "a";
465 }
466
467 SECTION("example-schema:a/a2")
468 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200469 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200470 node.second = "a2";
471 }
472
Václav Kubernát280df4a2019-11-01 14:46:34 +0100473 SECTION("example-schema:ethernet")
474 {
475 node.first = "example-schema";
476 node.second = "ethernet";
477 }
478
479 SECTION("example-schema:loopback")
480 {
481 node.first = "example-schema";
482 node.second = "loopback";
483 }
484
Václav Kubernát0d4db442018-07-18 17:18:43 +0200485 REQUIRE(ys.isContainer(path, node));
486 }
487 SECTION("isLeaf")
488 {
489 SECTION("example-schema:leafString")
490 {
491 node.first = "example-schema";
492 node.second = "leafString";
493 }
494
495 SECTION("example-schema:a/leafa")
496 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200497 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200498 node.first = "example-schema";
499 node.second = "leafa";
500 }
501
Václav Kubernát7d82da72019-04-11 15:16:38 +0200502 SECTION("example-schema:carry")
503 {
504 node.first = "example-schema";
505 node.second = "carry";
506 }
507
508 SECTION("example-schema:zero")
509 {
510 node.first = "example-schema";
511 node.second = "zero";
512 }
513
514 SECTION("example-schema:direction")
515 {
516 node.first = "example-schema";
517 node.second = "direction";
518 }
519
520 SECTION("example-schema:interrupt")
521 {
522 node.first = "example-schema";
523 node.second = "interrupt";
524 }
525
Václav Kubernát0d4db442018-07-18 17:18:43 +0200526 REQUIRE(ys.isLeaf(path, node));
527 }
528 SECTION("isModule")
529 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100530 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200531 }
532 SECTION("isList")
533 {
534 SECTION("example-schema:_list")
535 {
536 node.first = "example-schema";
537 node.second = "_list";
538 }
539
540 SECTION("example-schema:twoKeyList")
541 {
542 node.first = "example-schema";
543 node.second = "twoKeyList";
544 }
545
546 REQUIRE(ys.isList(path, node));
547 }
548 SECTION("isPresenceContainer")
549 {
550 SECTION("example-schema:a/a2/a3")
551 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200552 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
553 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a2")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200554 node.second = "a3";
555 }
556
557 REQUIRE(ys.isPresenceContainer(path, node));
558 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100559
Václav Kubernát0d4db442018-07-18 17:18:43 +0200560 SECTION("listHasKey")
561 {
562 std::string key;
563
564 SECTION("_list")
565 {
566 node.first = "example-schema";
567 node.second = "_list";
568 SECTION("number")
569 key = "number";
570 }
571
572 SECTION("twoKeyList")
573 {
574 node.first = "example-schema";
575 node.second = "twoKeyList";
576 SECTION("number")
577 key = "number";
578 SECTION("name")
579 key = "name";
580 }
581
582 REQUIRE(ys.listHasKey(path, node, key));
583 }
584 SECTION("listKeys")
585 {
586 std::set<std::string> set;
587
588 SECTION("_list")
589 {
590 set = {"number"};
591 node.first = "example-schema";
592 node.second = "_list";
593 }
594
595 SECTION("twoKeyList")
596 {
597 set = {"number", "name"};
598 node.first = "example-schema";
599 node.second = "twoKeyList";
600 }
601
602 REQUIRE(ys.listKeys(path, node) == set);
603 }
604 SECTION("leafType")
605 {
Václav Kubernát3a99f002020-03-31 02:27:41 +0200606 yang::LeafDataType type;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200607
608 SECTION("leafString")
609 {
610 node.first = "example-schema";
611 node.second = "leafString";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200612 type = yang::String{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200613 }
614
615 SECTION("leafDecimal")
616 {
617 node.first = "example-schema";
618 node.second = "leafDecimal";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200619 type = yang::Decimal{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200620 }
621
622 SECTION("leafBool")
623 {
624 node.first = "example-schema";
625 node.second = "leafBool";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200626 type = yang::Bool{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200627 }
628
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200629 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200630 {
631 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200632 node.second = "leafInt8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200633 type = yang::Int8{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200634 }
635
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200636 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200637 {
638 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200639 node.second = "leafUint8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200640 type = yang::Uint8{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200641 }
642
Václav Kubernátb6d02752020-04-03 00:25:10 +0200643 SECTION("leafInt16")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200644 {
645 node.first = "example-schema";
646 node.second = "leafInt16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200647 type = yang::Int16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200648 }
649
650 SECTION("leafUint16")
651 {
652 node.first = "example-schema";
653 node.second = "leafUint16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200654 type = yang::Uint16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200655 }
656
657 SECTION("leafInt32")
658 {
659 node.first = "example-schema";
660 node.second = "leafInt32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200661 type = yang::Int32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200662 }
663
664 SECTION("leafUint32")
665 {
666 node.first = "example-schema";
667 node.second = "leafUint32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200668 type = yang::Uint32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200669 }
670
671 SECTION("leafInt64")
672 {
673 node.first = "example-schema";
674 node.second = "leafInt64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200675 type = yang::Int64{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200676 }
677
678 SECTION("leafUint64")
679 {
680 node.first = "example-schema";
681 node.second = "leafUint64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200682 type = yang::Uint64{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200683 }
684
685 SECTION("leafEnum")
686 {
687 node.first = "example-schema";
688 node.second = "leafEnum";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200689 type = createEnum({"lol", "data", "coze"});
690 }
691
692 SECTION("leafEnumTypedef")
693 {
694 node.first = "example-schema";
695 node.second = "leafEnumTypedef";
696 type = createEnum({"lol", "data", "coze"});
697 }
698
699 SECTION("leafEnumTypedefRestricted")
700 {
701 node.first = "example-schema";
702 node.second = "leafEnumTypedefRestricted";
703 type = createEnum({"data", "coze"});
704 }
705
706 SECTION("leafEnumTypedefRestricted2")
707 {
708 node.first = "example-schema";
709 node.second = "leafEnumTypedefRestricted2";
710 type = createEnum({"lol", "data"});
711 }
712
713 SECTION("pizzaSize")
714 {
715 node.first = "example-schema";
716 node.second = "pizzaSize";
717
718 SECTION("bigPizzas disabled")
719 {
720 type = createEnum({"small", "medium"});
721 }
722 SECTION("bigPizzas enabled")
723 {
724 ys.enableFeature("example-schema", "bigPizzas");
725 type = createEnum({"small", "medium", "large"});
726 }
727 }
728
729 SECTION("foodIdentLeaf")
730 {
731 node.first = "example-schema";
732 node.second = "foodIdentLeaf";
733 type = yang::IdentityRef{{{"second-schema", "pineapple"},
734 {"example-schema", "food"},
735 {"example-schema", "pizza"},
736 {"example-schema", "hawaii"},
737 {"example-schema", "fruit"}}};
738 }
739
740 SECTION("pizzaIdentLeaf")
741 {
742 node.first = "example-schema";
743 node.second = "pizzaIdentLeaf";
744
745 type = yang::IdentityRef{{
746 {"example-schema", "pizza"},
747 {"example-schema", "hawaii"},
748 }};
749 }
750
751 SECTION("foodDrinkIdentLeaf")
752 {
753 node.first = "example-schema";
754 node.second = "foodDrinkIdentLeaf";
755
756 type = yang::IdentityRef{{
757 {"example-schema", "food"},
758 {"example-schema", "drink"},
759 {"example-schema", "fruit"},
760 {"example-schema", "hawaii"},
761 {"example-schema", "pizza"},
762 {"example-schema", "voda"},
763 {"second-schema", "pineapple"},
764 }};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200765 }
766
Václav Kubernátb6d02752020-04-03 00:25:10 +0200767 SECTION("activeNumber")
768 {
769 node.first = "example-schema";
770 node.second = "activeNumber";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200771 type.emplace<yang::LeafRef>(
772 "/example-schema:_list/number",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200773 std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number"))
Václav Kubernát3a99f002020-03-31 02:27:41 +0200774 );
Václav Kubernátb6d02752020-04-03 00:25:10 +0200775 }
776
Václav Kubernát2984f442020-02-20 17:43:35 +0100777 SECTION("activePort")
778 {
779 node.first = "example-schema";
780 node.second = "activePort";
781
782 yang::Enum enums = [&ys]() {
783 SECTION("weird ports disabled")
784 {
785 return createEnum({"utf2", "utf3"});
786 }
787 SECTION("weird ports enabled")
788 {
789 ys.enableFeature("example-schema", "weirdPortNames");
790 return createEnum({"WEIRD", "utf2", "utf3"});
791 }
792 __builtin_unreachable();
793 }();
794
795 type = yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +0200796 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
797 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100798 "/example-schema:portSettings/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200799 std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"}))
800 }},
801 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100802 "/example-schema:activeMappedPort",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200803 std::make_unique<yang::TypeInfo>(yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100804 "/example-schema:portMapping/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200805 std::make_unique<yang::TypeInfo>(enums)
806 })
807 }},
Jan Kundrát379bb572020-05-07 03:23:13 +0200808 yang::TypeInfo{yang::Empty{}},
Václav Kubernát2984f442020-02-20 17:43:35 +0100809 }};
810 }
811
Václav Kubernát0d4db442018-07-18 17:18:43 +0200812 REQUIRE(ys.leafType(path, node) == type);
813 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200814 SECTION("availableNodes")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200815 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200816 // TODO: merge "path" and "module" sections and add recursive versions to the path section
817 SECTION("paths")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200818 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200819 std::set<ModuleNodePair> set;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200820
Václav Kubernát95b08872020-04-28 01:04:17 +0200821 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200822 SECTION("<root>")
823 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200824 set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"},
825 {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"},
826 {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"},
827 {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"},
828 {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"},
829 {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"},
830 {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"},
831 {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"},
832 {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"},
833 {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"},
834 {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"},
835 {"example-schema"s, "interrupt"},
836 {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"},
837 {"example-schema"s, "pizzaSize"},
838 {"example-schema"s, "length"}, {"example-schema"s, "wavelength"},
839 {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"},
840 {"example-schema"s, "activeNumber"},
841 {"example-schema"s, "numberOrString"},
842 {"example-schema"s, "portSettings"},
843 {"example-schema"s, "portMapping"},
844 {"example-schema"s, "activeMappedPort"},
845 {"example-schema"s, "activePort"},
846 {"example-schema"s, "clockSpeed"},
847 {"example-schema"s, "deprecatedLeaf"},
848 {"example-schema"s, "obsoleteLeaf"},
849 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
850 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200851 {"example-schema"s, "myRpc"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200852 {"example-schema"s, "systemStats"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200853 {"example-schema"s, "dummyLeaf"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200854 {"example-schema"s, "subLeaf"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200855 }
856
857 SECTION("example-schema:a")
858 {
859 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát95b08872020-04-28 01:04:17 +0200860 set = {
861 {boost::none, "a2"},
862 {boost::none, "leafa"},
863 {"second-schema"s, "augmentedContainer"}
864 };
Václav Kubernát3a823f42020-04-29 23:40:21 +0200865 }
866
867 SECTION("example-schema:ethernet")
868 {
869 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("ethernet")));
Václav Kubernát95b08872020-04-28 01:04:17 +0200870 set = {{boost::none, "ip"}};
871 }
872
873 SECTION("second-schema:bla")
874 {
875 path.m_nodes.push_back(schemaNode_(module_{"second-schema"}, container_("bla")));
876 set = {{boost::none, "bla2"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200877 }
878
879 REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200880 }
881
Václav Kubernát3a823f42020-04-29 23:40:21 +0200882 SECTION("modules")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200883 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200884 std::string module;
Václav Kubernát95b08872020-04-28 01:04:17 +0200885 std::set<ModuleNodePair> expectedNonRecursive;
886 std::set<ModuleNodePair> expectedRecursive;
887 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200888 SECTION("example-schema")
889 {
890 module = "example-schema";
891 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200892 {"example-schema"s, "_list"},
893 {"example-schema"s, "a"},
894 {"example-schema"s, "activeMappedPort"},
895 {"example-schema"s, "activeNumber"},
896 {"example-schema"s, "activePort"},
897 {"example-schema"s, "another-duration"},
898 {"example-schema"s, "b"},
899 {"example-schema"s, "carry"},
900 {"example-schema"s, "clockSpeed"},
901 {"example-schema"s, "deprecatedLeaf"},
902 {"example-schema"s, "direction"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200903 {"example-schema"s, "dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200904 {"example-schema"s, "duration"},
905 {"example-schema"s, "ethernet"},
906 {"example-schema"s, "foodDrinkIdentLeaf"},
907 {"example-schema"s, "foodIdentLeaf"},
908 {"example-schema"s, "interrupt"},
909 {"example-schema"s, "leafBool"},
910 {"example-schema"s, "leafDecimal"},
911 {"example-schema"s, "leafEnum"},
912 {"example-schema"s, "leafEnumTypedef"},
913 {"example-schema"s, "leafEnumTypedefRestricted"},
914 {"example-schema"s, "leafEnumTypedefRestricted2"},
915 {"example-schema"s, "leafInt16"},
916 {"example-schema"s, "leafInt32"},
917 {"example-schema"s, "leafInt64"},
918 {"example-schema"s, "leafInt8"},
919 {"example-schema"s, "leafString"},
920 {"example-schema"s, "leafUint16"},
921 {"example-schema"s, "leafUint32"},
922 {"example-schema"s, "leafUint64"},
923 {"example-schema"s, "leafUint8"},
924 {"example-schema"s, "length"},
925 {"example-schema"s, "loopback"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200926 {"example-schema"s, "myRpc"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200927 {"example-schema"s, "numberOrString"},
928 {"example-schema"s, "obsoleteLeaf"},
929 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
930 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
931 {"example-schema"s, "pizzaIdentLeaf"},
932 {"example-schema"s, "pizzaSize"},
933 {"example-schema"s, "portMapping"},
934 {"example-schema"s, "portSettings"},
935 {"example-schema"s, "systemStats"},
936 {"example-schema"s, "twoKeyList"},
937 {"example-schema"s, "wavelength"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200938 {"example-schema"s, "zero"},
939 {"example-schema"s, "subLeaf"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200940 };
941 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200942 {boost::none, "/example-schema:_list"},
943 {boost::none, "/example-schema:_list/contInList"},
944 {boost::none, "/example-schema:_list/number"},
945 {boost::none, "/example-schema:a"},
946 {boost::none, "/example-schema:a/a2"},
947 {boost::none, "/example-schema:a/a2/a3"},
948 {boost::none, "/example-schema:a/leafa"},
949 {boost::none, "/example-schema:a/second-schema:augmentedContainer"},
950 {boost::none, "/example-schema:activeMappedPort"},
951 {boost::none, "/example-schema:activeNumber"},
952 {boost::none, "/example-schema:activePort"},
953 {boost::none, "/example-schema:another-duration"},
954 {boost::none, "/example-schema:b"},
955 {boost::none, "/example-schema:b/b2"},
956 {boost::none, "/example-schema:b/b2/b3"},
957 {boost::none, "/example-schema:carry"},
958 {boost::none, "/example-schema:clockSpeed"},
959 {boost::none, "/example-schema:deprecatedLeaf"},
960 {boost::none, "/example-schema:direction"},
961 {boost::none, "/example-schema:duration"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200962 {boost::none, "/example-schema:dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200963 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
964 {boost::none, "/example-schema:foodIdentLeaf"},
965 {boost::none, "/example-schema:interface/caseEthernet/ethernet"},
966 {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"},
967 {boost::none, "/example-schema:interface/caseLoopback/loopback"},
968 {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"},
969 {boost::none, "/example-schema:interrupt"},
970 {boost::none, "/example-schema:leafBool"},
971 {boost::none, "/example-schema:leafDecimal"},
972 {boost::none, "/example-schema:leafEnum"},
973 {boost::none, "/example-schema:leafEnumTypedef"},
974 {boost::none, "/example-schema:leafEnumTypedefRestricted"},
975 {boost::none, "/example-schema:leafEnumTypedefRestricted2"},
976 {boost::none, "/example-schema:leafInt16"},
977 {boost::none, "/example-schema:leafInt32"},
978 {boost::none, "/example-schema:leafInt64"},
979 {boost::none, "/example-schema:leafInt8"},
980 {boost::none, "/example-schema:leafString"},
981 {boost::none, "/example-schema:leafUint16"},
982 {boost::none, "/example-schema:leafUint32"},
983 {boost::none, "/example-schema:leafUint64"},
984 {boost::none, "/example-schema:leafUint8"},
985 {boost::none, "/example-schema:length"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200986 {boost::none, "/example-schema:myRpc"},
987 {boost::none, "/example-schema:myRpc/input"},
988 {boost::none, "/example-schema:myRpc/output"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200989 {boost::none, "/example-schema:numberOrString"},
990 {boost::none, "/example-schema:obsoleteLeaf"},
991 {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"},
992 {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"},
993 {boost::none, "/example-schema:pizzaIdentLeaf"},
994 {boost::none, "/example-schema:pizzaSize"},
995 {boost::none, "/example-schema:portMapping"},
996 {boost::none, "/example-schema:portMapping/port"},
997 {boost::none, "/example-schema:portSettings"},
998 {boost::none, "/example-schema:portSettings/port"},
999 {boost::none, "/example-schema:systemStats"},
1000 {boost::none, "/example-schema:systemStats/upTime"},
Václav Kubernát82d74632020-05-11 15:59:53 +02001001 {boost::none, "/example-schema:subLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +02001002 {boost::none, "/example-schema:twoKeyList"},
1003 {boost::none, "/example-schema:twoKeyList/name"},
1004 {boost::none, "/example-schema:twoKeyList/number"},
1005 {boost::none, "/example-schema:wavelength"},
1006 {boost::none, "/example-schema:zero"}
Václav Kubernát3a823f42020-04-29 23:40:21 +02001007 };
1008 }
Václav Kubernát3a823f42020-04-29 23:40:21 +02001009 SECTION("second-schema")
1010 {
1011 module = "second-schema";
1012 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +02001013 {"second-schema"s, "bla"}
Václav Kubernát3a823f42020-04-29 23:40:21 +02001014 };
1015 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +02001016 {boost::none, "/second-schema:bla"},
1017 {boost::none, "/second-schema:bla/bla2"}
Václav Kubernát3a823f42020-04-29 23:40:21 +02001018 };
1019 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001020
Václav Kubernát3a823f42020-04-29 23:40:21 +02001021 REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive);
1022 REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive);
Václav Kubernát47a3f672019-11-08 15:42:43 +01001023 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001024 }
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001025 SECTION("nodeType")
1026 {
1027 yang::NodeTypes expected;
1028 SECTION("leafInt32")
1029 {
1030 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
1031 expected = yang::NodeTypes::Leaf;
1032 }
1033
1034 SECTION("a")
1035 {
1036 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1037 expected = yang::NodeTypes::Container;
1038 }
1039
1040 SECTION("a/a2/a3")
1041 {
1042 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1043 path.m_nodes.push_back(schemaNode_(container_("a2")));
1044 path.m_nodes.push_back(schemaNode_(container_("a3")));
1045 expected = yang::NodeTypes::PresenceContainer;
1046 }
1047
1048 SECTION("_list")
1049 {
1050 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, list_("_list")));
1051 expected = yang::NodeTypes::List;
1052 }
1053
Václav Kubernát82d74632020-05-11 15:59:53 +02001054 SECTION("subLeaf")
1055 {
1056 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("subLeaf")));
1057 expected = yang::NodeTypes::Leaf;
1058 }
1059
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001060 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1061 }
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001062
1063 SECTION("description")
1064 {
1065 std::optional<std::string> expected;
1066 SECTION("leafInt32")
1067 {
1068 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
1069 expected = "A 32-bit integer leaf.";
1070 }
1071
1072 SECTION("leafString")
1073 {
1074 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafString")));
1075 }
1076
Václav Kubernát2984f442020-02-20 17:43:35 +01001077 SECTION("numberOrString")
1078 {
1079 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("numberOrString")));
1080 expected = "Can be an int32 or a string.";
1081 }
1082
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001083 REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1084 }
1085
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +02001086 SECTION("status")
1087 {
1088 REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current);
1089 REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete);
1090 REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated);
1091 REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete);
1092 REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete);
1093 }
1094
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001095 SECTION("units")
1096 {
Václav Kubernát13b23d72020-04-16 21:49:51 +02001097 yang::LeafDataType expectedType;
1098 std::optional<std::string> expectedUnits;
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001099 SECTION("length")
1100 {
1101 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("length")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001102 expectedType.emplace<yang::Int32>();
1103 expectedUnits = "m";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001104 }
1105
1106 SECTION("wavelength")
1107 {
1108 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("wavelength")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001109 expectedType.emplace<yang::Decimal>();
1110 expectedUnits = "nm";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001111 }
1112
1113 SECTION("leafInt32")
1114 {
1115 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001116 expectedType.emplace<yang::Int32>();
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001117 }
1118
1119 SECTION("duration")
1120 {
1121 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("duration")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001122 expectedType.emplace<yang::Int32>();
1123 expectedUnits = "s";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001124 }
1125
1126 SECTION("another-duration")
1127 {
1128 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("another-duration")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001129 expectedType.emplace<yang::Int32>();
1130 expectedUnits = "vt";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001131 }
Václav Kubernát13b23d72020-04-16 21:49:51 +02001132 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits});
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001133 }
1134
1135 SECTION("nodeType")
1136 {
1137 yang::NodeTypes expected;
1138 SECTION("leafInt32")
1139 {
1140 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
1141 expected = yang::NodeTypes::Leaf;
1142 }
1143
1144 SECTION("a")
1145 {
1146 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1147 expected = yang::NodeTypes::Container;
1148 }
1149
1150 SECTION("a/a2/a3")
1151 {
1152 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1153 path.m_nodes.push_back(schemaNode_(container_("a2")));
1154 path.m_nodes.push_back(schemaNode_(container_("a3")));
1155 expected = yang::NodeTypes::PresenceContainer;
1156 }
1157
1158 SECTION("_list")
1159 {
1160 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, list_("_list")));
1161 expected = yang::NodeTypes::List;
1162 }
1163
1164 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1165 }
Václav Kubernátbd5e3c22020-02-19 15:22:00 +01001166
1167 SECTION("leafrefPath")
1168 {
1169 REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number");
1170 }
Václav Kubernát0599e9f2020-04-21 09:51:33 +02001171
1172 SECTION("isConfig")
1173 {
1174 REQUIRE(ys.isConfig("/example-schema:leafInt32"));
1175 REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed"));
1176 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats"));
1177 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime"));
1178 }
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001179
Václav Kubernátb1a75c62020-04-21 15:20:16 +02001180 SECTION("defaultValue")
1181 {
1182 REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001");
1183 REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data");
1184 REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt);
1185 }
1186
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001187 SECTION("moduleNodes")
1188 {
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001189 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001190 }
1191
1192 SECTION("negative")
1193 {
1194 SECTION("nonexistent nodes")
1195 {
1196 SECTION("example-schema:coze")
1197 {
1198 node.first = "example-schema";
1199 node.second = "coze";
1200 }
1201
1202 SECTION("example-schema:a/nevim")
1203 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001204 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001205 node.second = "nevim";
1206 }
1207
1208 SECTION("modul:a/nevim")
1209 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001210 path.m_nodes.push_back(schemaNode_(module_{"modul"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001211 node.second = "nevim";
1212 }
1213
1214 REQUIRE(!ys.isPresenceContainer(path, node));
1215 REQUIRE(!ys.isList(path, node));
1216 REQUIRE(!ys.isLeaf(path, node));
1217 REQUIRE(!ys.isContainer(path, node));
1218 }
1219
1220 SECTION("\"is\" methods return false for existing nodes for different nodetypes")
1221 {
1222 SECTION("example-schema:a")
1223 {
1224 node.first = "example-schema";
1225 node.second = "a";
1226 }
1227
1228 SECTION("example-schema:a/a2")
1229 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001230 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001231 node.second = "a2";
1232 }
1233
1234 REQUIRE(!ys.isPresenceContainer(path, node));
1235 REQUIRE(!ys.isList(path, node));
1236 REQUIRE(!ys.isLeaf(path, node));
1237 }
1238
1239 SECTION("nodetype-specific methods called with different nodetypes")
1240 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001241 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001242 node.second = "a2";
1243
Václav Kubernát0d4db442018-07-18 17:18:43 +02001244 REQUIRE(!ys.listHasKey(path, node, "chacha"));
1245 }
1246
1247 SECTION("nonexistent module")
1248 {
Václav Kubernát75877de2019-11-20 17:43:02 +01001249 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001250 }
Václav Kubernáteeb38842019-03-20 19:46:05 +01001251
Václav Kubernát7d82da72019-04-11 15:16:38 +02001252 SECTION("grouping is not a node")
1253 {
1254 SECTION("example-schema:arithmeticFlags")
1255 {
1256 node.first = "example-schema";
1257 node.second = "arithmeticFlags";
1258 }
1259
1260 SECTION("example-schema:flags")
1261 {
1262 node.first = "example-schema";
1263 node.second = "startAndStop";
1264 }
1265
1266 REQUIRE(!ys.isPresenceContainer(path, node));
1267 REQUIRE(!ys.isList(path, node));
1268 REQUIRE(!ys.isLeaf(path, node));
1269 REQUIRE(!ys.isContainer(path, node));
1270 }
Václav Kubernát280df4a2019-11-01 14:46:34 +01001271
1272 SECTION("choice is not a node")
1273 {
1274 SECTION("example-schema:interface")
1275 {
1276 node.first = "example-schema";
1277 node.second = "interface";
1278 }
1279
1280 REQUIRE(!ys.isPresenceContainer(path, node));
1281 REQUIRE(!ys.isList(path, node));
1282 REQUIRE(!ys.isLeaf(path, node));
1283 REQUIRE(!ys.isContainer(path, node));
1284 }
1285
1286 SECTION("case is not a node")
1287 {
1288 SECTION("example-schema:caseLoopback")
1289 {
1290 node.first = "example-schema";
1291 node.second = "caseLoopback";
1292 }
1293
1294 SECTION("example-schema:caseEthernet")
1295 {
1296 node.first = "example-schema";
1297 node.second = "caseEthernet";
1298 }
1299
1300 REQUIRE(!ys.isPresenceContainer(path, node));
1301 REQUIRE(!ys.isList(path, node));
1302 REQUIRE(!ys.isLeaf(path, node));
1303 REQUIRE(!ys.isContainer(path, node));
1304 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001305 }
1306}