blob: 009465b39dec3aa36b24369e08b151a82f60d176 [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 }
372 }
373 }
374
Václav Kubernát0599e9f2020-04-21 09:51:33 +0200375 leaf clockSpeed {
376 type int64;
377 config false;
378 }
379
380 container systemStats {
381 config false;
382 leaf upTime {
383 type uint64;
384 }
385 }
386
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +0200387 leaf obsoleteLeaf {
388 type int32;
389 status obsolete;
390 }
391
392 leaf deprecatedLeaf {
393 type int32;
394 status deprecated;
395 }
396
397 typedef deprecatedType {
398 type int32;
399 status deprecated;
400 }
401
402 leaf obsoleteLeafWithDeprecatedType {
403 type deprecatedType;
404 status obsolete;
405 }
406
407 typedef obsoleteType {
408 type int32;
409 status obsolete;
410 }
411
412 leaf obsoleteLeafWithObsoleteType {
413 type deprecatedType;
414 status obsolete;
415 }
416
Václav Kubernát0d4db442018-07-18 17:18:43 +0200417})";
418
Václav Kubernát47a3f672019-11-08 15:42:43 +0100419namespace std {
420std::ostream& operator<<(std::ostream& s, const std::set<std::string> set)
421{
422 s << std::endl << "{";
423 std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", "));
424 s << "}" << std::endl;
425 return s;
426}
427}
428
Václav Kubernát0d4db442018-07-18 17:18:43 +0200429TEST_CASE("yangschema")
430{
Václav Kubernát82d74632020-05-11 15:59:53 +0200431 using namespace std::string_literals;
Václav Kubernát4f77a252019-02-19 16:51:30 +0100432 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200433 YangSchema ys;
Václav Kubernát82d74632020-05-11 15:59:53 +0200434 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) {
435 if (modName != "example-schema"sv) {
436 throw std::logic_error("unrecognized module "s + modName);
437 }
438 if (subModule == nullptr) {
439 return example_schema;
440 }
441 if (subModule == "sub-module"sv) {
442 return included_submodule;
443 }
444
445 throw std::logic_error("unrecognized submodule "s + subModule);
Václav Kubernát4f77a252019-02-19 16:51:30 +0100446 });
447 ys.addSchemaString(second_schema);
448
Václav Kubernátefcac932020-01-10 15:26:32 +0100449 schemaPath_ path{Scope::Absolute, {}};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200450 ModuleNodePair node;
451
452 SECTION("positive")
453 {
454 SECTION("isContainer")
455 {
456 SECTION("example-schema:a")
457 {
458 node.first = "example-schema";
459 node.second = "a";
460 }
461
462 SECTION("example-schema:a/a2")
463 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200464 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200465 node.second = "a2";
466 }
467
Václav Kubernát280df4a2019-11-01 14:46:34 +0100468 SECTION("example-schema:ethernet")
469 {
470 node.first = "example-schema";
471 node.second = "ethernet";
472 }
473
474 SECTION("example-schema:loopback")
475 {
476 node.first = "example-schema";
477 node.second = "loopback";
478 }
479
Václav Kubernát0d4db442018-07-18 17:18:43 +0200480 REQUIRE(ys.isContainer(path, node));
481 }
482 SECTION("isLeaf")
483 {
484 SECTION("example-schema:leafString")
485 {
486 node.first = "example-schema";
487 node.second = "leafString";
488 }
489
490 SECTION("example-schema:a/leafa")
491 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200492 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200493 node.first = "example-schema";
494 node.second = "leafa";
495 }
496
Václav Kubernát7d82da72019-04-11 15:16:38 +0200497 SECTION("example-schema:carry")
498 {
499 node.first = "example-schema";
500 node.second = "carry";
501 }
502
503 SECTION("example-schema:zero")
504 {
505 node.first = "example-schema";
506 node.second = "zero";
507 }
508
509 SECTION("example-schema:direction")
510 {
511 node.first = "example-schema";
512 node.second = "direction";
513 }
514
515 SECTION("example-schema:interrupt")
516 {
517 node.first = "example-schema";
518 node.second = "interrupt";
519 }
520
Václav Kubernát0d4db442018-07-18 17:18:43 +0200521 REQUIRE(ys.isLeaf(path, node));
522 }
523 SECTION("isModule")
524 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100525 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200526 }
527 SECTION("isList")
528 {
529 SECTION("example-schema:_list")
530 {
531 node.first = "example-schema";
532 node.second = "_list";
533 }
534
535 SECTION("example-schema:twoKeyList")
536 {
537 node.first = "example-schema";
538 node.second = "twoKeyList";
539 }
540
541 REQUIRE(ys.isList(path, node));
542 }
543 SECTION("isPresenceContainer")
544 {
545 SECTION("example-schema:a/a2/a3")
546 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200547 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
548 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a2")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200549 node.second = "a3";
550 }
551
552 REQUIRE(ys.isPresenceContainer(path, node));
553 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100554
Václav Kubernát0d4db442018-07-18 17:18:43 +0200555 SECTION("listHasKey")
556 {
557 std::string key;
558
559 SECTION("_list")
560 {
561 node.first = "example-schema";
562 node.second = "_list";
563 SECTION("number")
564 key = "number";
565 }
566
567 SECTION("twoKeyList")
568 {
569 node.first = "example-schema";
570 node.second = "twoKeyList";
571 SECTION("number")
572 key = "number";
573 SECTION("name")
574 key = "name";
575 }
576
577 REQUIRE(ys.listHasKey(path, node, key));
578 }
579 SECTION("listKeys")
580 {
581 std::set<std::string> set;
582
583 SECTION("_list")
584 {
585 set = {"number"};
586 node.first = "example-schema";
587 node.second = "_list";
588 }
589
590 SECTION("twoKeyList")
591 {
592 set = {"number", "name"};
593 node.first = "example-schema";
594 node.second = "twoKeyList";
595 }
596
597 REQUIRE(ys.listKeys(path, node) == set);
598 }
599 SECTION("leafType")
600 {
Václav Kubernát3a99f002020-03-31 02:27:41 +0200601 yang::LeafDataType type;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200602
603 SECTION("leafString")
604 {
605 node.first = "example-schema";
606 node.second = "leafString";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200607 type = yang::String{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200608 }
609
610 SECTION("leafDecimal")
611 {
612 node.first = "example-schema";
613 node.second = "leafDecimal";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200614 type = yang::Decimal{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200615 }
616
617 SECTION("leafBool")
618 {
619 node.first = "example-schema";
620 node.second = "leafBool";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200621 type = yang::Bool{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200622 }
623
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200624 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200625 {
626 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200627 node.second = "leafInt8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200628 type = yang::Int8{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200629 }
630
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200631 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200632 {
633 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200634 node.second = "leafUint8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200635 type = yang::Uint8{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200636 }
637
Václav Kubernátb6d02752020-04-03 00:25:10 +0200638 SECTION("leafInt16")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200639 {
640 node.first = "example-schema";
641 node.second = "leafInt16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200642 type = yang::Int16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200643 }
644
645 SECTION("leafUint16")
646 {
647 node.first = "example-schema";
648 node.second = "leafUint16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200649 type = yang::Uint16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200650 }
651
652 SECTION("leafInt32")
653 {
654 node.first = "example-schema";
655 node.second = "leafInt32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200656 type = yang::Int32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200657 }
658
659 SECTION("leafUint32")
660 {
661 node.first = "example-schema";
662 node.second = "leafUint32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200663 type = yang::Uint32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200664 }
665
666 SECTION("leafInt64")
667 {
668 node.first = "example-schema";
669 node.second = "leafInt64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200670 type = yang::Int64{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200671 }
672
673 SECTION("leafUint64")
674 {
675 node.first = "example-schema";
676 node.second = "leafUint64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200677 type = yang::Uint64{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200678 }
679
680 SECTION("leafEnum")
681 {
682 node.first = "example-schema";
683 node.second = "leafEnum";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200684 type = createEnum({"lol", "data", "coze"});
685 }
686
687 SECTION("leafEnumTypedef")
688 {
689 node.first = "example-schema";
690 node.second = "leafEnumTypedef";
691 type = createEnum({"lol", "data", "coze"});
692 }
693
694 SECTION("leafEnumTypedefRestricted")
695 {
696 node.first = "example-schema";
697 node.second = "leafEnumTypedefRestricted";
698 type = createEnum({"data", "coze"});
699 }
700
701 SECTION("leafEnumTypedefRestricted2")
702 {
703 node.first = "example-schema";
704 node.second = "leafEnumTypedefRestricted2";
705 type = createEnum({"lol", "data"});
706 }
707
708 SECTION("pizzaSize")
709 {
710 node.first = "example-schema";
711 node.second = "pizzaSize";
712
713 SECTION("bigPizzas disabled")
714 {
715 type = createEnum({"small", "medium"});
716 }
717 SECTION("bigPizzas enabled")
718 {
719 ys.enableFeature("example-schema", "bigPizzas");
720 type = createEnum({"small", "medium", "large"});
721 }
722 }
723
724 SECTION("foodIdentLeaf")
725 {
726 node.first = "example-schema";
727 node.second = "foodIdentLeaf";
728 type = yang::IdentityRef{{{"second-schema", "pineapple"},
729 {"example-schema", "food"},
730 {"example-schema", "pizza"},
731 {"example-schema", "hawaii"},
732 {"example-schema", "fruit"}}};
733 }
734
735 SECTION("pizzaIdentLeaf")
736 {
737 node.first = "example-schema";
738 node.second = "pizzaIdentLeaf";
739
740 type = yang::IdentityRef{{
741 {"example-schema", "pizza"},
742 {"example-schema", "hawaii"},
743 }};
744 }
745
746 SECTION("foodDrinkIdentLeaf")
747 {
748 node.first = "example-schema";
749 node.second = "foodDrinkIdentLeaf";
750
751 type = yang::IdentityRef{{
752 {"example-schema", "food"},
753 {"example-schema", "drink"},
754 {"example-schema", "fruit"},
755 {"example-schema", "hawaii"},
756 {"example-schema", "pizza"},
757 {"example-schema", "voda"},
758 {"second-schema", "pineapple"},
759 }};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200760 }
761
Václav Kubernátb6d02752020-04-03 00:25:10 +0200762 SECTION("activeNumber")
763 {
764 node.first = "example-schema";
765 node.second = "activeNumber";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200766 type.emplace<yang::LeafRef>(
767 "/example-schema:_list/number",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200768 std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number"))
Václav Kubernát3a99f002020-03-31 02:27:41 +0200769 );
Václav Kubernátb6d02752020-04-03 00:25:10 +0200770 }
771
Václav Kubernát2984f442020-02-20 17:43:35 +0100772 SECTION("activePort")
773 {
774 node.first = "example-schema";
775 node.second = "activePort";
776
777 yang::Enum enums = [&ys]() {
778 SECTION("weird ports disabled")
779 {
780 return createEnum({"utf2", "utf3"});
781 }
782 SECTION("weird ports enabled")
783 {
784 ys.enableFeature("example-schema", "weirdPortNames");
785 return createEnum({"WEIRD", "utf2", "utf3"});
786 }
787 __builtin_unreachable();
788 }();
789
790 type = yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +0200791 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
792 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100793 "/example-schema:portSettings/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200794 std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"}))
795 }},
796 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100797 "/example-schema:activeMappedPort",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200798 std::make_unique<yang::TypeInfo>(yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100799 "/example-schema:portMapping/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200800 std::make_unique<yang::TypeInfo>(enums)
801 })
802 }},
Václav Kubernát2984f442020-02-20 17:43:35 +0100803 }};
804 }
805
Václav Kubernát0d4db442018-07-18 17:18:43 +0200806 REQUIRE(ys.leafType(path, node) == type);
807 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200808 SECTION("availableNodes")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200809 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200810 // TODO: merge "path" and "module" sections and add recursive versions to the path section
811 SECTION("paths")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200812 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200813 std::set<ModuleNodePair> set;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200814
Václav Kubernát95b08872020-04-28 01:04:17 +0200815 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200816 SECTION("<root>")
817 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200818 set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"},
819 {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"},
820 {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"},
821 {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"},
822 {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"},
823 {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"},
824 {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"},
825 {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"},
826 {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"},
827 {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"},
828 {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"},
829 {"example-schema"s, "interrupt"},
830 {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"},
831 {"example-schema"s, "pizzaSize"},
832 {"example-schema"s, "length"}, {"example-schema"s, "wavelength"},
833 {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"},
834 {"example-schema"s, "activeNumber"},
835 {"example-schema"s, "numberOrString"},
836 {"example-schema"s, "portSettings"},
837 {"example-schema"s, "portMapping"},
838 {"example-schema"s, "activeMappedPort"},
839 {"example-schema"s, "activePort"},
840 {"example-schema"s, "clockSpeed"},
841 {"example-schema"s, "deprecatedLeaf"},
842 {"example-schema"s, "obsoleteLeaf"},
843 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
844 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200845 {"example-schema"s, "myRpc"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200846 {"example-schema"s, "systemStats"},
847 {"example-schema"s, "subLeaf"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200848 }
849
850 SECTION("example-schema:a")
851 {
852 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát95b08872020-04-28 01:04:17 +0200853 set = {
854 {boost::none, "a2"},
855 {boost::none, "leafa"},
856 {"second-schema"s, "augmentedContainer"}
857 };
Václav Kubernát3a823f42020-04-29 23:40:21 +0200858 }
859
860 SECTION("example-schema:ethernet")
861 {
862 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("ethernet")));
Václav Kubernát95b08872020-04-28 01:04:17 +0200863 set = {{boost::none, "ip"}};
864 }
865
866 SECTION("second-schema:bla")
867 {
868 path.m_nodes.push_back(schemaNode_(module_{"second-schema"}, container_("bla")));
869 set = {{boost::none, "bla2"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200870 }
871
872 REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200873 }
874
Václav Kubernát3a823f42020-04-29 23:40:21 +0200875 SECTION("modules")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200876 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200877 std::string module;
Václav Kubernát95b08872020-04-28 01:04:17 +0200878 std::set<ModuleNodePair> expectedNonRecursive;
879 std::set<ModuleNodePair> expectedRecursive;
880 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200881 SECTION("example-schema")
882 {
883 module = "example-schema";
884 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200885 {"example-schema"s, "_list"},
886 {"example-schema"s, "a"},
887 {"example-schema"s, "activeMappedPort"},
888 {"example-schema"s, "activeNumber"},
889 {"example-schema"s, "activePort"},
890 {"example-schema"s, "another-duration"},
891 {"example-schema"s, "b"},
892 {"example-schema"s, "carry"},
893 {"example-schema"s, "clockSpeed"},
894 {"example-schema"s, "deprecatedLeaf"},
895 {"example-schema"s, "direction"},
896 {"example-schema"s, "duration"},
897 {"example-schema"s, "ethernet"},
898 {"example-schema"s, "foodDrinkIdentLeaf"},
899 {"example-schema"s, "foodIdentLeaf"},
900 {"example-schema"s, "interrupt"},
901 {"example-schema"s, "leafBool"},
902 {"example-schema"s, "leafDecimal"},
903 {"example-schema"s, "leafEnum"},
904 {"example-schema"s, "leafEnumTypedef"},
905 {"example-schema"s, "leafEnumTypedefRestricted"},
906 {"example-schema"s, "leafEnumTypedefRestricted2"},
907 {"example-schema"s, "leafInt16"},
908 {"example-schema"s, "leafInt32"},
909 {"example-schema"s, "leafInt64"},
910 {"example-schema"s, "leafInt8"},
911 {"example-schema"s, "leafString"},
912 {"example-schema"s, "leafUint16"},
913 {"example-schema"s, "leafUint32"},
914 {"example-schema"s, "leafUint64"},
915 {"example-schema"s, "leafUint8"},
916 {"example-schema"s, "length"},
917 {"example-schema"s, "loopback"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200918 {"example-schema"s, "myRpc"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200919 {"example-schema"s, "numberOrString"},
920 {"example-schema"s, "obsoleteLeaf"},
921 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
922 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
923 {"example-schema"s, "pizzaIdentLeaf"},
924 {"example-schema"s, "pizzaSize"},
925 {"example-schema"s, "portMapping"},
926 {"example-schema"s, "portSettings"},
927 {"example-schema"s, "systemStats"},
928 {"example-schema"s, "twoKeyList"},
929 {"example-schema"s, "wavelength"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200930 {"example-schema"s, "zero"},
931 {"example-schema"s, "subLeaf"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200932 };
933 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200934 {boost::none, "/example-schema:_list"},
935 {boost::none, "/example-schema:_list/contInList"},
936 {boost::none, "/example-schema:_list/number"},
937 {boost::none, "/example-schema:a"},
938 {boost::none, "/example-schema:a/a2"},
939 {boost::none, "/example-schema:a/a2/a3"},
940 {boost::none, "/example-schema:a/leafa"},
941 {boost::none, "/example-schema:a/second-schema:augmentedContainer"},
942 {boost::none, "/example-schema:activeMappedPort"},
943 {boost::none, "/example-schema:activeNumber"},
944 {boost::none, "/example-schema:activePort"},
945 {boost::none, "/example-schema:another-duration"},
946 {boost::none, "/example-schema:b"},
947 {boost::none, "/example-schema:b/b2"},
948 {boost::none, "/example-schema:b/b2/b3"},
949 {boost::none, "/example-schema:carry"},
950 {boost::none, "/example-schema:clockSpeed"},
951 {boost::none, "/example-schema:deprecatedLeaf"},
952 {boost::none, "/example-schema:direction"},
953 {boost::none, "/example-schema:duration"},
954 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
955 {boost::none, "/example-schema:foodIdentLeaf"},
956 {boost::none, "/example-schema:interface/caseEthernet/ethernet"},
957 {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"},
958 {boost::none, "/example-schema:interface/caseLoopback/loopback"},
959 {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"},
960 {boost::none, "/example-schema:interrupt"},
961 {boost::none, "/example-schema:leafBool"},
962 {boost::none, "/example-schema:leafDecimal"},
963 {boost::none, "/example-schema:leafEnum"},
964 {boost::none, "/example-schema:leafEnumTypedef"},
965 {boost::none, "/example-schema:leafEnumTypedefRestricted"},
966 {boost::none, "/example-schema:leafEnumTypedefRestricted2"},
967 {boost::none, "/example-schema:leafInt16"},
968 {boost::none, "/example-schema:leafInt32"},
969 {boost::none, "/example-schema:leafInt64"},
970 {boost::none, "/example-schema:leafInt8"},
971 {boost::none, "/example-schema:leafString"},
972 {boost::none, "/example-schema:leafUint16"},
973 {boost::none, "/example-schema:leafUint32"},
974 {boost::none, "/example-schema:leafUint64"},
975 {boost::none, "/example-schema:leafUint8"},
976 {boost::none, "/example-schema:length"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200977 {boost::none, "/example-schema:myRpc"},
978 {boost::none, "/example-schema:myRpc/input"},
979 {boost::none, "/example-schema:myRpc/output"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200980 {boost::none, "/example-schema:numberOrString"},
981 {boost::none, "/example-schema:obsoleteLeaf"},
982 {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"},
983 {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"},
984 {boost::none, "/example-schema:pizzaIdentLeaf"},
985 {boost::none, "/example-schema:pizzaSize"},
986 {boost::none, "/example-schema:portMapping"},
987 {boost::none, "/example-schema:portMapping/port"},
988 {boost::none, "/example-schema:portSettings"},
989 {boost::none, "/example-schema:portSettings/port"},
990 {boost::none, "/example-schema:systemStats"},
991 {boost::none, "/example-schema:systemStats/upTime"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200992 {boost::none, "/example-schema:subLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200993 {boost::none, "/example-schema:twoKeyList"},
994 {boost::none, "/example-schema:twoKeyList/name"},
995 {boost::none, "/example-schema:twoKeyList/number"},
996 {boost::none, "/example-schema:wavelength"},
997 {boost::none, "/example-schema:zero"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200998 };
999 }
Václav Kubernát3a823f42020-04-29 23:40:21 +02001000 SECTION("second-schema")
1001 {
1002 module = "second-schema";
1003 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +02001004 {"second-schema"s, "bla"}
Václav Kubernát3a823f42020-04-29 23:40:21 +02001005 };
1006 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +02001007 {boost::none, "/second-schema:bla"},
1008 {boost::none, "/second-schema:bla/bla2"}
Václav Kubernát3a823f42020-04-29 23:40:21 +02001009 };
1010 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001011
Václav Kubernát3a823f42020-04-29 23:40:21 +02001012 REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive);
1013 REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive);
Václav Kubernát47a3f672019-11-08 15:42:43 +01001014 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001015 }
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001016 SECTION("nodeType")
1017 {
1018 yang::NodeTypes expected;
1019 SECTION("leafInt32")
1020 {
1021 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
1022 expected = yang::NodeTypes::Leaf;
1023 }
1024
1025 SECTION("a")
1026 {
1027 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1028 expected = yang::NodeTypes::Container;
1029 }
1030
1031 SECTION("a/a2/a3")
1032 {
1033 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1034 path.m_nodes.push_back(schemaNode_(container_("a2")));
1035 path.m_nodes.push_back(schemaNode_(container_("a3")));
1036 expected = yang::NodeTypes::PresenceContainer;
1037 }
1038
1039 SECTION("_list")
1040 {
1041 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, list_("_list")));
1042 expected = yang::NodeTypes::List;
1043 }
1044
Václav Kubernát82d74632020-05-11 15:59:53 +02001045 SECTION("subLeaf")
1046 {
1047 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("subLeaf")));
1048 expected = yang::NodeTypes::Leaf;
1049 }
1050
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001051 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1052 }
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001053
1054 SECTION("description")
1055 {
1056 std::optional<std::string> expected;
1057 SECTION("leafInt32")
1058 {
1059 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
1060 expected = "A 32-bit integer leaf.";
1061 }
1062
1063 SECTION("leafString")
1064 {
1065 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafString")));
1066 }
1067
Václav Kubernát2984f442020-02-20 17:43:35 +01001068 SECTION("numberOrString")
1069 {
1070 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("numberOrString")));
1071 expected = "Can be an int32 or a string.";
1072 }
1073
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001074 REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1075 }
1076
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +02001077 SECTION("status")
1078 {
1079 REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current);
1080 REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete);
1081 REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated);
1082 REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete);
1083 REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete);
1084 }
1085
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001086 SECTION("units")
1087 {
Václav Kubernát13b23d72020-04-16 21:49:51 +02001088 yang::LeafDataType expectedType;
1089 std::optional<std::string> expectedUnits;
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001090 SECTION("length")
1091 {
1092 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("length")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001093 expectedType.emplace<yang::Int32>();
1094 expectedUnits = "m";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001095 }
1096
1097 SECTION("wavelength")
1098 {
1099 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("wavelength")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001100 expectedType.emplace<yang::Decimal>();
1101 expectedUnits = "nm";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001102 }
1103
1104 SECTION("leafInt32")
1105 {
1106 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001107 expectedType.emplace<yang::Int32>();
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001108 }
1109
1110 SECTION("duration")
1111 {
1112 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("duration")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001113 expectedType.emplace<yang::Int32>();
1114 expectedUnits = "s";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001115 }
1116
1117 SECTION("another-duration")
1118 {
1119 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("another-duration")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001120 expectedType.emplace<yang::Int32>();
1121 expectedUnits = "vt";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001122 }
Václav Kubernát13b23d72020-04-16 21:49:51 +02001123 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits});
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001124 }
1125
1126 SECTION("nodeType")
1127 {
1128 yang::NodeTypes expected;
1129 SECTION("leafInt32")
1130 {
1131 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
1132 expected = yang::NodeTypes::Leaf;
1133 }
1134
1135 SECTION("a")
1136 {
1137 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1138 expected = yang::NodeTypes::Container;
1139 }
1140
1141 SECTION("a/a2/a3")
1142 {
1143 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1144 path.m_nodes.push_back(schemaNode_(container_("a2")));
1145 path.m_nodes.push_back(schemaNode_(container_("a3")));
1146 expected = yang::NodeTypes::PresenceContainer;
1147 }
1148
1149 SECTION("_list")
1150 {
1151 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, list_("_list")));
1152 expected = yang::NodeTypes::List;
1153 }
1154
1155 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1156 }
Václav Kubernátbd5e3c22020-02-19 15:22:00 +01001157
1158 SECTION("leafrefPath")
1159 {
1160 REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number");
1161 }
Václav Kubernát0599e9f2020-04-21 09:51:33 +02001162
1163 SECTION("isConfig")
1164 {
1165 REQUIRE(ys.isConfig("/example-schema:leafInt32"));
1166 REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed"));
1167 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats"));
1168 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime"));
1169 }
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001170
Václav Kubernátb1a75c62020-04-21 15:20:16 +02001171 SECTION("defaultValue")
1172 {
1173 REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001");
1174 REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data");
1175 REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt);
1176 }
1177
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001178 SECTION("moduleNodes")
1179 {
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001180 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001181 }
1182
1183 SECTION("negative")
1184 {
1185 SECTION("nonexistent nodes")
1186 {
1187 SECTION("example-schema:coze")
1188 {
1189 node.first = "example-schema";
1190 node.second = "coze";
1191 }
1192
1193 SECTION("example-schema:a/nevim")
1194 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001195 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001196 node.second = "nevim";
1197 }
1198
1199 SECTION("modul:a/nevim")
1200 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001201 path.m_nodes.push_back(schemaNode_(module_{"modul"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001202 node.second = "nevim";
1203 }
1204
1205 REQUIRE(!ys.isPresenceContainer(path, node));
1206 REQUIRE(!ys.isList(path, node));
1207 REQUIRE(!ys.isLeaf(path, node));
1208 REQUIRE(!ys.isContainer(path, node));
1209 }
1210
1211 SECTION("\"is\" methods return false for existing nodes for different nodetypes")
1212 {
1213 SECTION("example-schema:a")
1214 {
1215 node.first = "example-schema";
1216 node.second = "a";
1217 }
1218
1219 SECTION("example-schema:a/a2")
1220 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001221 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001222 node.second = "a2";
1223 }
1224
1225 REQUIRE(!ys.isPresenceContainer(path, node));
1226 REQUIRE(!ys.isList(path, node));
1227 REQUIRE(!ys.isLeaf(path, node));
1228 }
1229
1230 SECTION("nodetype-specific methods called with different nodetypes")
1231 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001232 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001233 node.second = "a2";
1234
Václav Kubernát0d4db442018-07-18 17:18:43 +02001235 REQUIRE(!ys.listHasKey(path, node, "chacha"));
1236 }
1237
1238 SECTION("nonexistent module")
1239 {
Václav Kubernát75877de2019-11-20 17:43:02 +01001240 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001241 }
Václav Kubernáteeb38842019-03-20 19:46:05 +01001242
Václav Kubernát7d82da72019-04-11 15:16:38 +02001243 SECTION("grouping is not a node")
1244 {
1245 SECTION("example-schema:arithmeticFlags")
1246 {
1247 node.first = "example-schema";
1248 node.second = "arithmeticFlags";
1249 }
1250
1251 SECTION("example-schema:flags")
1252 {
1253 node.first = "example-schema";
1254 node.second = "startAndStop";
1255 }
1256
1257 REQUIRE(!ys.isPresenceContainer(path, node));
1258 REQUIRE(!ys.isList(path, node));
1259 REQUIRE(!ys.isLeaf(path, node));
1260 REQUIRE(!ys.isContainer(path, node));
1261 }
Václav Kubernát280df4a2019-11-01 14:46:34 +01001262
1263 SECTION("choice is not a node")
1264 {
1265 SECTION("example-schema:interface")
1266 {
1267 node.first = "example-schema";
1268 node.second = "interface";
1269 }
1270
1271 REQUIRE(!ys.isPresenceContainer(path, node));
1272 REQUIRE(!ys.isList(path, node));
1273 REQUIRE(!ys.isLeaf(path, node));
1274 REQUIRE(!ys.isContainer(path, node));
1275 }
1276
1277 SECTION("case is not a node")
1278 {
1279 SECTION("example-schema:caseLoopback")
1280 {
1281 node.first = "example-schema";
1282 node.second = "caseLoopback";
1283 }
1284
1285 SECTION("example-schema:caseEthernet")
1286 {
1287 node.first = "example-schema";
1288 node.second = "caseEthernet";
1289 }
1290
1291 REQUIRE(!ys.isPresenceContainer(path, node));
1292 REQUIRE(!ys.isList(path, node));
1293 REQUIRE(!ys.isLeaf(path, node));
1294 REQUIRE(!ys.isContainer(path, node));
1295 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001296 }
1297}