blob: 2ca1704e2cf343e1e1863c518e2ad0a3a32dd465 [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>
Jan Kundráta33cf082019-03-28 11:55:57 +010010#include "trompeloeil_doctest.h"
Václav Kubernát0d4db442018-07-18 17:18:43 +020011#include "yang_schema.hpp"
12
Václav Kubernát4f77a252019-02-19 16:51:30 +010013const char* second_schema = R"(
14module second-schema {
15 namespace "http://example.com/nevim";
16 prefix second;
17
18 import example-schema {
19 prefix "example";
20 }
21
Václav Kubernáteeb38842019-03-20 19:46:05 +010022 identity pineapple {
23 base "example:fruit";
24 }
25
Václav Kubernát4f77a252019-02-19 16:51:30 +010026 augment /example:a {
27 container augmentedContainer {
28 }
29 }
30
31 container bla {
32 container bla2 {
33 }
34 }
35}
36)";
37
38const char* example_schema = R"(
Václav Kubernát0d4db442018-07-18 17:18:43 +020039module example-schema {
Václav Kubernát6a713d62018-10-03 18:47:34 +020040 yang-version 1.1;
Václav Kubernát0d4db442018-07-18 17:18:43 +020041 namespace "http://example.com/example-sports";
42 prefix coze;
43
Václav Kubernáteeb38842019-03-20 19:46:05 +010044 identity drink {
45 }
46
47 identity voda {
48 base "drink";
49 }
50
51 identity food {
52 }
53
54 identity fruit {
55 base "food";
56 }
57
58 identity pizza {
59 base "food";
60 }
61
62 identity hawaii {
63 base "pizza";
64 }
65
Václav Kubernát0d4db442018-07-18 17:18:43 +020066 container a {
67 container a2 {
68 container a3 {
69 presence true;
70 }
71 }
72
73 leaf leafa {
74 type string;
75 }
76 }
77
78 container b {
79 container b2 {
80 presence true;
81 container b3 {
82 }
83 }
84 }
85
86 leaf leafString {
87 type string;
88 }
89
90 leaf leafDecimal {
91 type decimal64 {
92 fraction-digits 5;
93 }
94 }
95
96 leaf leafBool {
97 type boolean;
98 }
99
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200100 leaf leafInt8 {
101 type int8;
102 }
103
104 leaf leafUint8 {
105 type uint8;
106 }
107
108 leaf leafInt16 {
109 type int16;
110 }
111
112 leaf leafUint16 {
113 type uint16;
114 }
115
116 leaf leafInt32 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200117 type int32;
118 }
119
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200120 leaf leafUint32 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200121 type uint32;
122 }
123
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200124 leaf leafInt64 {
125 type int64;
126 }
127
128 leaf leafUint64 {
129 type uint64;
130 }
131
Václav Kubernát0d4db442018-07-18 17:18:43 +0200132 leaf leafEnum {
133 type enumeration {
134 enum lol;
135 enum data;
136 enum coze;
137 }
138 }
139
Václav Kubernát6a713d62018-10-03 18:47:34 +0200140 typedef enumTypedef {
141 type enumeration {
142 enum lol;
143 enum data;
144 enum coze;
145 }
146 }
147
148 typedef enumTypedefRestricted {
149 type enumTypedef {
150 enum lol;
151 enum data;
152 }
153 }
154
155 leaf leafEnumTypedef {
156 type enumTypedef;
157 }
158
159 leaf leafEnumTypedefRestricted {
160 type enumTypedef {
161 enum data;
162 enum coze;
163 }
164 }
165
166 leaf leafEnumTypedefRestricted2 {
167 type enumTypedefRestricted;
168 }
169
Václav Kubernáteeb38842019-03-20 19:46:05 +0100170 leaf foodIdentLeaf {
171 type identityref {
172 base "food";
173 }
174 }
175
176 leaf pizzaIdentLeaf {
177 type identityref {
178 base "pizza";
179 }
180 }
181
182 leaf foodDrinkIdentLeaf {
183 type identityref {
184 base "food";
185 base "drink";
186 }
187 }
188
Václav Kubernát0d4db442018-07-18 17:18:43 +0200189 list _list {
190 key number;
191
192 leaf number {
193 type int32;
194 }
195
196 container contInList {
197 presence true;
198 }
199 }
200
201 list twoKeyList {
202 key "name number";
203
204 leaf number {
205 type int32;
206 }
207
208 leaf name {
209 type string;
210 }
211 }
Václav Kubernát7d82da72019-04-11 15:16:38 +0200212
213 grouping arithmeticFlags {
214 leaf carry {
215 type boolean;
216 }
217 leaf zero {
218 type boolean;
219 }
220 }
221
222 grouping flags {
223 leaf direction {
224 type boolean;
225 }
226 leaf interrupt {
227 type boolean;
228 }
229
230 uses arithmeticFlags;
231 }
232
233 uses flags;
Václav Kubernát280df4a2019-11-01 14:46:34 +0100234
235 choice interface {
236 case caseLoopback {
237 container loopback {
238 leaf ip {
239 type string;
240 }
241 }
242 }
243
244 case caseEthernet {
245 container ethernet {
246 leaf ip {
247 type string;
248 }
249 }
250 }
251 }
252
Václav Kubernáta38d4172019-11-04 12:36:39 +0100253 feature bigPizzas;
254
255 leaf pizzaSize {
256 type enumeration {
257 enum large {
258 if-feature "bigPizzas";
259 }
260 enum medium;
261 enum small;
262 }
263 }
264
Václav Kubernát0d4db442018-07-18 17:18:43 +0200265})";
266
Václav Kubernát47a3f672019-11-08 15:42:43 +0100267namespace std {
268std::ostream& operator<<(std::ostream& s, const std::set<std::string> set)
269{
270 s << std::endl << "{";
271 std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", "));
272 s << "}" << std::endl;
273 return s;
274}
275}
276
Václav Kubernát0d4db442018-07-18 17:18:43 +0200277TEST_CASE("yangschema")
278{
Václav Kubernát4f77a252019-02-19 16:51:30 +0100279 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200280 YangSchema ys;
Václav Kubernát4f77a252019-02-19 16:51:30 +0100281 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto) {
282 assert("example-schema"sv == modName);
283 return example_schema;
284 });
285 ys.addSchemaString(second_schema);
286
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200287 schemaPath_ path;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200288 ModuleNodePair node;
289
290 SECTION("positive")
291 {
292 SECTION("isContainer")
293 {
294 SECTION("example-schema:a")
295 {
296 node.first = "example-schema";
297 node.second = "a";
298 }
299
300 SECTION("example-schema:a/a2")
301 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200302 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200303 node.second = "a2";
304 }
305
Václav Kubernát280df4a2019-11-01 14:46:34 +0100306 SECTION("example-schema:ethernet")
307 {
308 node.first = "example-schema";
309 node.second = "ethernet";
310 }
311
312 SECTION("example-schema:loopback")
313 {
314 node.first = "example-schema";
315 node.second = "loopback";
316 }
317
Václav Kubernát0d4db442018-07-18 17:18:43 +0200318 REQUIRE(ys.isContainer(path, node));
319 }
320 SECTION("isLeaf")
321 {
322 SECTION("example-schema:leafString")
323 {
324 node.first = "example-schema";
325 node.second = "leafString";
326 }
327
328 SECTION("example-schema:a/leafa")
329 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200330 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200331 node.first = "example-schema";
332 node.second = "leafa";
333 }
334
Václav Kubernát7d82da72019-04-11 15:16:38 +0200335 SECTION("example-schema:carry")
336 {
337 node.first = "example-schema";
338 node.second = "carry";
339 }
340
341 SECTION("example-schema:zero")
342 {
343 node.first = "example-schema";
344 node.second = "zero";
345 }
346
347 SECTION("example-schema:direction")
348 {
349 node.first = "example-schema";
350 node.second = "direction";
351 }
352
353 SECTION("example-schema:interrupt")
354 {
355 node.first = "example-schema";
356 node.second = "interrupt";
357 }
358
Václav Kubernát0d4db442018-07-18 17:18:43 +0200359 REQUIRE(ys.isLeaf(path, node));
360 }
361 SECTION("isModule")
362 {
363 REQUIRE(ys.isModule(path, "example-schema"));
364 }
365 SECTION("isList")
366 {
367 SECTION("example-schema:_list")
368 {
369 node.first = "example-schema";
370 node.second = "_list";
371 }
372
373 SECTION("example-schema:twoKeyList")
374 {
375 node.first = "example-schema";
376 node.second = "twoKeyList";
377 }
378
379 REQUIRE(ys.isList(path, node));
380 }
381 SECTION("isPresenceContainer")
382 {
383 SECTION("example-schema:a/a2/a3")
384 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200385 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
386 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a2")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200387 node.second = "a3";
388 }
389
390 REQUIRE(ys.isPresenceContainer(path, node));
391 }
392 SECTION("leafEnumHasValue")
393 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200394 std::string value;
Václav Kubernát6a713d62018-10-03 18:47:34 +0200395 SECTION("leafEnum")
396 {
397 node.first = "example-schema";
398 node.second = "leafEnum";
Václav Kubernát0d4db442018-07-18 17:18:43 +0200399
Václav Kubernát6a713d62018-10-03 18:47:34 +0200400 SECTION("lol")
401 value = "lol";
Václav Kubernát0d4db442018-07-18 17:18:43 +0200402
Václav Kubernát6a713d62018-10-03 18:47:34 +0200403 SECTION("data")
404 value = "data";
Václav Kubernát0d4db442018-07-18 17:18:43 +0200405
Václav Kubernát6a713d62018-10-03 18:47:34 +0200406 SECTION("coze")
407 value = "coze";
408 }
409
410 SECTION("leafEnumTypedef")
411 {
412 node.first = "example-schema";
413 node.second = "leafEnumTypedef";
414
415 SECTION("lol")
416 value = "lol";
417
418 SECTION("data")
419 value = "data";
420
421 SECTION("coze")
422 value = "coze";
423 }
424
425 SECTION("leafEnumTypedefRestricted")
426 {
427 node.first = "example-schema";
428 node.second = "leafEnumTypedefRestricted";
429
430 SECTION("data")
431 value = "data";
432
433 SECTION("coze")
434 value = "coze";
435 }
436
437 SECTION("leafEnumTypedefRestricted2")
438 {
439 node.first = "example-schema";
440 node.second = "leafEnumTypedefRestricted2";
441
442 SECTION("lol")
443 value = "lol";
444
445 SECTION("data")
446 value = "data";
447 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200448
Václav Kubernáta38d4172019-11-04 12:36:39 +0100449 SECTION("pizzaSize")
450 {
451 node.first = "example-schema";
452 node.second = "pizzaSize";
453
454 SECTION("small")
455 {
456 value = "small";
457
458 }
459 SECTION("medium")
460 {
461 value = "medium";
462 }
463
464 SECTION("large")
465 {
466 ys.enableFeature("example-schema", "bigPizzas");
467 value = "large";
468 }
469 }
470
Václav Kubernát0d4db442018-07-18 17:18:43 +0200471 REQUIRE(ys.leafEnumHasValue(path, node, value));
472 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100473 SECTION("leafIdentityIsValid")
474 {
475 ModuleValuePair value;
476
477 SECTION("foodIdentLeaf")
478 {
479 node.first = "example-schema";
480 node.second = "foodIdentLeaf";
481
482 SECTION("food")
483 {
484 value.second = "food";
485 }
486 SECTION("example-schema:food")
487 {
488 value.first = "example-schema";
489 value.second = "food";
490 }
491 SECTION("pizza")
492 {
493 value.second = "pizza";
494 }
495 SECTION("example-schema:pizza")
496 {
497 value.first = "example-schema";
498 value.second = "pizza";
499 }
500 SECTION("hawaii")
501 {
502 value.second = "hawaii";
503 }
504 SECTION("example-schema:hawaii")
505 {
506 value.first = "example-schema";
507 value.second = "hawaii";
508 }
509 SECTION("fruit")
510 {
511 value.second = "fruit";
512 }
513 SECTION("example-schema:fruit")
514 {
515 value.first = "example-schema";
516 value.second = "fruit";
517 }
518 SECTION("second-schema:pineapple")
519 {
520 value.first = "second-schema";
521 value.second = "pineapple";
522 }
523 }
524
525 SECTION("pizzaIdentLeaf")
526 {
527 node.first = "example-schema";
528 node.second = "pizzaIdentLeaf";
529
530 SECTION("pizza")
531 {
532 value.second = "pizza";
533 }
534 SECTION("example-schema:pizza")
535 {
536 value.first = "example-schema";
537 value.second = "pizza";
538 }
539 SECTION("hawaii")
540 {
541 value.second = "hawaii";
542 }
543 SECTION("example-schema:hawaii")
544 {
545 value.first = "example-schema";
546 value.second = "hawaii";
547 }
548 }
549
550 SECTION("foodDrinkIdentLeaf")
551 {
552 node.first = "example-schema";
553 node.second = "foodDrinkIdentLeaf";
554
555 SECTION("food")
556 {
557 value.second = "food";
558 }
559 SECTION("example-schema:food")
560 {
561 value.first = "example-schema";
562 value.second = "food";
563 }
564 SECTION("drink")
565 {
566 value.second = "drink";
567 }
568 SECTION("example-schema:drink")
569 {
570 value.first = "example-schema";
571 value.second = "drink";
572 }
573 }
574 REQUIRE(ys.leafIdentityIsValid(path, node, value));
575 }
576
Václav Kubernát0d4db442018-07-18 17:18:43 +0200577 SECTION("listHasKey")
578 {
579 std::string key;
580
581 SECTION("_list")
582 {
583 node.first = "example-schema";
584 node.second = "_list";
585 SECTION("number")
586 key = "number";
587 }
588
589 SECTION("twoKeyList")
590 {
591 node.first = "example-schema";
592 node.second = "twoKeyList";
593 SECTION("number")
594 key = "number";
595 SECTION("name")
596 key = "name";
597 }
598
599 REQUIRE(ys.listHasKey(path, node, key));
600 }
601 SECTION("listKeys")
602 {
603 std::set<std::string> set;
604
605 SECTION("_list")
606 {
607 set = {"number"};
608 node.first = "example-schema";
609 node.second = "_list";
610 }
611
612 SECTION("twoKeyList")
613 {
614 set = {"number", "name"};
615 node.first = "example-schema";
616 node.second = "twoKeyList";
617 }
618
619 REQUIRE(ys.listKeys(path, node) == set);
620 }
621 SECTION("leafType")
622 {
623 yang::LeafDataTypes type;
624
625 SECTION("leafString")
626 {
627 node.first = "example-schema";
628 node.second = "leafString";
629 type = yang::LeafDataTypes::String;
630 }
631
632 SECTION("leafDecimal")
633 {
634 node.first = "example-schema";
635 node.second = "leafDecimal";
636 type = yang::LeafDataTypes::Decimal;
637 }
638
639 SECTION("leafBool")
640 {
641 node.first = "example-schema";
642 node.second = "leafBool";
643 type = yang::LeafDataTypes::Bool;
644 }
645
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200646 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200647 {
648 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200649 node.second = "leafInt8";
650 type = yang::LeafDataTypes::Int8;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200651 }
652
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200653 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200654 {
655 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200656 node.second = "leafUint8";
657 type = yang::LeafDataTypes::Uint8;
658 }
659
660 SECTION("leafInt15")
661 {
662 node.first = "example-schema";
663 node.second = "leafInt16";
664 type = yang::LeafDataTypes::Int16;
665 }
666
667 SECTION("leafUint16")
668 {
669 node.first = "example-schema";
670 node.second = "leafUint16";
671 type = yang::LeafDataTypes::Uint16;
672 }
673
674 SECTION("leafInt32")
675 {
676 node.first = "example-schema";
677 node.second = "leafInt32";
678 type = yang::LeafDataTypes::Int32;
679 }
680
681 SECTION("leafUint32")
682 {
683 node.first = "example-schema";
684 node.second = "leafUint32";
685 type = yang::LeafDataTypes::Uint32;
686 }
687
688 SECTION("leafInt64")
689 {
690 node.first = "example-schema";
691 node.second = "leafInt64";
692 type = yang::LeafDataTypes::Int64;
693 }
694
695 SECTION("leafUint64")
696 {
697 node.first = "example-schema";
698 node.second = "leafUint64";
699 type = yang::LeafDataTypes::Uint64;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200700 }
701
702 SECTION("leafEnum")
703 {
704 node.first = "example-schema";
705 node.second = "leafEnum";
706 type = yang::LeafDataTypes::Enum;
707 }
708
709 REQUIRE(ys.leafType(path, node) == type);
710 }
711 SECTION("childNodes")
712 {
713 std::set<std::string> set;
714
715 SECTION("<root>")
716 {
717 set = {"example-schema:a", "example-schema:b", "example-schema:leafString",
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200718 "example-schema:leafDecimal", "example-schema:leafBool",
719 "example-schema:leafInt8", "example-schema:leafUint8",
720 "example-schema:leafInt16", "example-schema:leafUint16",
721 "example-schema:leafInt32", "example-schema:leafUint32",
722 "example-schema:leafInt64", "example-schema:leafUint64",
723 "example-schema:leafEnum", "example-schema:leafEnumTypedef",
Václav Kubernát6a713d62018-10-03 18:47:34 +0200724 "example-schema:leafEnumTypedefRestricted", "example-schema:leafEnumTypedefRestricted2",
Václav Kubernáteeb38842019-03-20 19:46:05 +0100725 "example-schema:foodIdentLeaf", "example-schema:pizzaIdentLeaf", "example-schema:foodDrinkIdentLeaf",
Václav Kubernát7d82da72019-04-11 15:16:38 +0200726 "example-schema:_list", "example-schema:twoKeyList", "second-schema:bla",
727 "example-schema:carry", "example-schema:zero", "example-schema:direction",
Václav Kubernát280df4a2019-11-01 14:46:34 +0100728 "example-schema:interrupt",
Václav Kubernáta38d4172019-11-04 12:36:39 +0100729 "example-schema:ethernet", "example-schema:loopback",
730 "example-schema:pizzaSize"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200731 }
732
Václav Kubernát4f77a252019-02-19 16:51:30 +0100733 SECTION("example-schema:a")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200734 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200735 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát4f77a252019-02-19 16:51:30 +0100736 set = {"a2", "leafa", "second-schema:augmentedContainer"};
737 }
738
739 SECTION("second-schema:bla")
740 {
741 path.m_nodes.push_back(schemaNode_(module_{"second-schema"}, container_("bla")));
742 set = {"bla2"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200743 }
744
Václav Kubernát47a3f672019-11-08 15:42:43 +0100745 SECTION("example-schema:ethernet")
746 {
747 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("ethernet")));
748 set = {"ip"};
749 }
750
Václav Kubernáte7d4aea2018-09-11 18:15:48 +0200751 REQUIRE(ys.childNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200752 }
753 }
754
755 SECTION("negative")
756 {
757 SECTION("nonexistent nodes")
758 {
759 SECTION("example-schema:coze")
760 {
761 node.first = "example-schema";
762 node.second = "coze";
763 }
764
765 SECTION("example-schema:a/nevim")
766 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200767 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200768 node.second = "nevim";
769 }
770
771 SECTION("modul:a/nevim")
772 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200773 path.m_nodes.push_back(schemaNode_(module_{"modul"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200774 node.second = "nevim";
775 }
776
777 REQUIRE(!ys.isPresenceContainer(path, node));
778 REQUIRE(!ys.isList(path, node));
779 REQUIRE(!ys.isLeaf(path, node));
780 REQUIRE(!ys.isContainer(path, node));
781 }
782
783 SECTION("\"is\" methods return false for existing nodes for different nodetypes")
784 {
785 SECTION("example-schema:a")
786 {
787 node.first = "example-schema";
788 node.second = "a";
789 }
790
791 SECTION("example-schema:a/a2")
792 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200793 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200794 node.second = "a2";
795 }
796
797 REQUIRE(!ys.isPresenceContainer(path, node));
798 REQUIRE(!ys.isList(path, node));
799 REQUIRE(!ys.isLeaf(path, node));
800 }
801
802 SECTION("nodetype-specific methods called with different nodetypes")
803 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200804 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200805 node.second = "a2";
806
807 REQUIRE(!ys.leafEnumHasValue(path, node, "haha"));
808 REQUIRE(!ys.listHasKey(path, node, "chacha"));
809 }
810
811 SECTION("nonexistent module")
812 {
813 REQUIRE(!ys.isModule(path, "notAModule"));
814 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100815
816 SECTION("leafIdentityIsValid")
817 {
818 ModuleValuePair value;
819 SECTION("pizzaIdentLeaf")
820 {
821 node.first = "example-schema";
822 node.second = "pizzaIdentLeaf";
823
824 SECTION("wrong base ident")
825 {
826 SECTION("food")
827 {
828 value.second = "food";
829 }
830 SECTION("fruit")
831 {
832 value.second = "fruit";
833 }
834 }
835 SECTION("non-existent identity")
836 {
837 value.second = "nonexistent";
838 }
839 SECTION("weird module")
840 {
841 value.first = "ahahaha";
842 value.second = "pizza";
843 }
844 }
845 SECTION("different module identity, but withotu prefix")
846 {
847 node.first = "example-schema";
848 node.second = "foodIdentLeaf";
849 value.second = "pineapple";
850 }
851 REQUIRE_FALSE(ys.leafIdentityIsValid(path, node, value));
852 }
Václav Kubernát7d82da72019-04-11 15:16:38 +0200853
854 SECTION("grouping is not a node")
855 {
856 SECTION("example-schema:arithmeticFlags")
857 {
858 node.first = "example-schema";
859 node.second = "arithmeticFlags";
860 }
861
862 SECTION("example-schema:flags")
863 {
864 node.first = "example-schema";
865 node.second = "startAndStop";
866 }
867
868 REQUIRE(!ys.isPresenceContainer(path, node));
869 REQUIRE(!ys.isList(path, node));
870 REQUIRE(!ys.isLeaf(path, node));
871 REQUIRE(!ys.isContainer(path, node));
872 }
Václav Kubernát280df4a2019-11-01 14:46:34 +0100873
874 SECTION("choice is not a node")
875 {
876 SECTION("example-schema:interface")
877 {
878 node.first = "example-schema";
879 node.second = "interface";
880 }
881
882 REQUIRE(!ys.isPresenceContainer(path, node));
883 REQUIRE(!ys.isList(path, node));
884 REQUIRE(!ys.isLeaf(path, node));
885 REQUIRE(!ys.isContainer(path, node));
886 }
887
888 SECTION("case is not a node")
889 {
890 SECTION("example-schema:caseLoopback")
891 {
892 node.first = "example-schema";
893 node.second = "caseLoopback";
894 }
895
896 SECTION("example-schema:caseEthernet")
897 {
898 node.first = "example-schema";
899 node.second = "caseEthernet";
900 }
901
902 REQUIRE(!ys.isPresenceContainer(path, node));
903 REQUIRE(!ys.isList(path, node));
904 REQUIRE(!ys.isLeaf(path, node));
905 REQUIRE(!ys.isContainer(path, node));
906 }
Václav Kubernáta38d4172019-11-04 12:36:39 +0100907
908 SECTION("enum is disabled by if-feature if feature is not enabled")
909 {
910 node.first = "example-schema";
911 node.second = "pizzaSize";
912
913 std::string value = "large";
914
915 REQUIRE(!ys.leafEnumHasValue(path, node, value));
916 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200917 }
918}