blob: d519825bc19a996fe04af90556b735b16a068f59 [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átb52dc252019-12-04 13:03:39 +0100281 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto, auto) {
Václav Kubernát4f77a252019-02-19 16:51:30 +0100282 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 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100363 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200364 }
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";
Václav Kubernáta38d4172019-11-04 12:36:39 +0100457 }
458 SECTION("medium")
459 {
460 value = "medium";
461 }
462
463 SECTION("large")
464 {
465 ys.enableFeature("example-schema", "bigPizzas");
466 value = "large";
467 }
468 }
469
Václav Kubernát0d4db442018-07-18 17:18:43 +0200470 REQUIRE(ys.leafEnumHasValue(path, node, value));
471 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100472 SECTION("leafIdentityIsValid")
473 {
474 ModuleValuePair value;
475
476 SECTION("foodIdentLeaf")
477 {
478 node.first = "example-schema";
479 node.second = "foodIdentLeaf";
480
481 SECTION("food")
482 {
483 value.second = "food";
484 }
485 SECTION("example-schema:food")
486 {
487 value.first = "example-schema";
488 value.second = "food";
489 }
490 SECTION("pizza")
491 {
492 value.second = "pizza";
493 }
494 SECTION("example-schema:pizza")
495 {
496 value.first = "example-schema";
497 value.second = "pizza";
498 }
499 SECTION("hawaii")
500 {
501 value.second = "hawaii";
502 }
503 SECTION("example-schema:hawaii")
504 {
505 value.first = "example-schema";
506 value.second = "hawaii";
507 }
508 SECTION("fruit")
509 {
510 value.second = "fruit";
511 }
512 SECTION("example-schema:fruit")
513 {
514 value.first = "example-schema";
515 value.second = "fruit";
516 }
517 SECTION("second-schema:pineapple")
518 {
519 value.first = "second-schema";
520 value.second = "pineapple";
521 }
522 }
523
524 SECTION("pizzaIdentLeaf")
525 {
526 node.first = "example-schema";
527 node.second = "pizzaIdentLeaf";
528
529 SECTION("pizza")
530 {
531 value.second = "pizza";
532 }
533 SECTION("example-schema:pizza")
534 {
535 value.first = "example-schema";
536 value.second = "pizza";
537 }
538 SECTION("hawaii")
539 {
540 value.second = "hawaii";
541 }
542 SECTION("example-schema:hawaii")
543 {
544 value.first = "example-schema";
545 value.second = "hawaii";
546 }
547 }
548
549 SECTION("foodDrinkIdentLeaf")
550 {
551 node.first = "example-schema";
552 node.second = "foodDrinkIdentLeaf";
553
554 SECTION("food")
555 {
556 value.second = "food";
557 }
558 SECTION("example-schema:food")
559 {
560 value.first = "example-schema";
561 value.second = "food";
562 }
563 SECTION("drink")
564 {
565 value.second = "drink";
566 }
567 SECTION("example-schema:drink")
568 {
569 value.first = "example-schema";
570 value.second = "drink";
571 }
572 }
573 REQUIRE(ys.leafIdentityIsValid(path, node, value));
574 }
575
Václav Kubernát0d4db442018-07-18 17:18:43 +0200576 SECTION("listHasKey")
577 {
578 std::string key;
579
580 SECTION("_list")
581 {
582 node.first = "example-schema";
583 node.second = "_list";
584 SECTION("number")
585 key = "number";
586 }
587
588 SECTION("twoKeyList")
589 {
590 node.first = "example-schema";
591 node.second = "twoKeyList";
592 SECTION("number")
593 key = "number";
594 SECTION("name")
595 key = "name";
596 }
597
598 REQUIRE(ys.listHasKey(path, node, key));
599 }
600 SECTION("listKeys")
601 {
602 std::set<std::string> set;
603
604 SECTION("_list")
605 {
606 set = {"number"};
607 node.first = "example-schema";
608 node.second = "_list";
609 }
610
611 SECTION("twoKeyList")
612 {
613 set = {"number", "name"};
614 node.first = "example-schema";
615 node.second = "twoKeyList";
616 }
617
618 REQUIRE(ys.listKeys(path, node) == set);
619 }
620 SECTION("leafType")
621 {
622 yang::LeafDataTypes type;
623
624 SECTION("leafString")
625 {
626 node.first = "example-schema";
627 node.second = "leafString";
628 type = yang::LeafDataTypes::String;
629 }
630
631 SECTION("leafDecimal")
632 {
633 node.first = "example-schema";
634 node.second = "leafDecimal";
635 type = yang::LeafDataTypes::Decimal;
636 }
637
638 SECTION("leafBool")
639 {
640 node.first = "example-schema";
641 node.second = "leafBool";
642 type = yang::LeafDataTypes::Bool;
643 }
644
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200645 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200646 {
647 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200648 node.second = "leafInt8";
649 type = yang::LeafDataTypes::Int8;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200650 }
651
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200652 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200653 {
654 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200655 node.second = "leafUint8";
656 type = yang::LeafDataTypes::Uint8;
657 }
658
659 SECTION("leafInt15")
660 {
661 node.first = "example-schema";
662 node.second = "leafInt16";
663 type = yang::LeafDataTypes::Int16;
664 }
665
666 SECTION("leafUint16")
667 {
668 node.first = "example-schema";
669 node.second = "leafUint16";
670 type = yang::LeafDataTypes::Uint16;
671 }
672
673 SECTION("leafInt32")
674 {
675 node.first = "example-schema";
676 node.second = "leafInt32";
677 type = yang::LeafDataTypes::Int32;
678 }
679
680 SECTION("leafUint32")
681 {
682 node.first = "example-schema";
683 node.second = "leafUint32";
684 type = yang::LeafDataTypes::Uint32;
685 }
686
687 SECTION("leafInt64")
688 {
689 node.first = "example-schema";
690 node.second = "leafInt64";
691 type = yang::LeafDataTypes::Int64;
692 }
693
694 SECTION("leafUint64")
695 {
696 node.first = "example-schema";
697 node.second = "leafUint64";
698 type = yang::LeafDataTypes::Uint64;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200699 }
700
701 SECTION("leafEnum")
702 {
703 node.first = "example-schema";
704 node.second = "leafEnum";
705 type = yang::LeafDataTypes::Enum;
706 }
707
708 REQUIRE(ys.leafType(path, node) == type);
709 }
710 SECTION("childNodes")
711 {
712 std::set<std::string> set;
713
714 SECTION("<root>")
715 {
716 set = {"example-schema:a", "example-schema:b", "example-schema:leafString",
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200717 "example-schema:leafDecimal", "example-schema:leafBool",
718 "example-schema:leafInt8", "example-schema:leafUint8",
719 "example-schema:leafInt16", "example-schema:leafUint16",
720 "example-schema:leafInt32", "example-schema:leafUint32",
721 "example-schema:leafInt64", "example-schema:leafUint64",
722 "example-schema:leafEnum", "example-schema:leafEnumTypedef",
Václav Kubernát6a713d62018-10-03 18:47:34 +0200723 "example-schema:leafEnumTypedefRestricted", "example-schema:leafEnumTypedefRestricted2",
Václav Kubernáteeb38842019-03-20 19:46:05 +0100724 "example-schema:foodIdentLeaf", "example-schema:pizzaIdentLeaf", "example-schema:foodDrinkIdentLeaf",
Václav Kubernát7d82da72019-04-11 15:16:38 +0200725 "example-schema:_list", "example-schema:twoKeyList", "second-schema:bla",
726 "example-schema:carry", "example-schema:zero", "example-schema:direction",
Václav Kubernát280df4a2019-11-01 14:46:34 +0100727 "example-schema:interrupt",
Václav Kubernáta38d4172019-11-04 12:36:39 +0100728 "example-schema:ethernet", "example-schema:loopback",
729 "example-schema:pizzaSize"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200730 }
731
Václav Kubernát4f77a252019-02-19 16:51:30 +0100732 SECTION("example-schema:a")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200733 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200734 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát4f77a252019-02-19 16:51:30 +0100735 set = {"a2", "leafa", "second-schema:augmentedContainer"};
736 }
737
738 SECTION("second-schema:bla")
739 {
740 path.m_nodes.push_back(schemaNode_(module_{"second-schema"}, container_("bla")));
741 set = {"bla2"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200742 }
743
Václav Kubernát47a3f672019-11-08 15:42:43 +0100744 SECTION("example-schema:ethernet")
745 {
746 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("ethernet")));
747 set = {"ip"};
748 }
749
Václav Kubernáte7d4aea2018-09-11 18:15:48 +0200750 REQUIRE(ys.childNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200751 }
752 }
753
754 SECTION("negative")
755 {
756 SECTION("nonexistent nodes")
757 {
758 SECTION("example-schema:coze")
759 {
760 node.first = "example-schema";
761 node.second = "coze";
762 }
763
764 SECTION("example-schema:a/nevim")
765 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200766 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200767 node.second = "nevim";
768 }
769
770 SECTION("modul:a/nevim")
771 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200772 path.m_nodes.push_back(schemaNode_(module_{"modul"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200773 node.second = "nevim";
774 }
775
776 REQUIRE(!ys.isPresenceContainer(path, node));
777 REQUIRE(!ys.isList(path, node));
778 REQUIRE(!ys.isLeaf(path, node));
779 REQUIRE(!ys.isContainer(path, node));
780 }
781
782 SECTION("\"is\" methods return false for existing nodes for different nodetypes")
783 {
784 SECTION("example-schema:a")
785 {
786 node.first = "example-schema";
787 node.second = "a";
788 }
789
790 SECTION("example-schema:a/a2")
791 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200792 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200793 node.second = "a2";
794 }
795
796 REQUIRE(!ys.isPresenceContainer(path, node));
797 REQUIRE(!ys.isList(path, node));
798 REQUIRE(!ys.isLeaf(path, node));
799 }
800
801 SECTION("nodetype-specific methods called with different nodetypes")
802 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200803 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200804 node.second = "a2";
805
806 REQUIRE(!ys.leafEnumHasValue(path, node, "haha"));
807 REQUIRE(!ys.listHasKey(path, node, "chacha"));
808 }
809
810 SECTION("nonexistent module")
811 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100812 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200813 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100814
815 SECTION("leafIdentityIsValid")
816 {
817 ModuleValuePair value;
818 SECTION("pizzaIdentLeaf")
819 {
820 node.first = "example-schema";
821 node.second = "pizzaIdentLeaf";
822
823 SECTION("wrong base ident")
824 {
825 SECTION("food")
826 {
827 value.second = "food";
828 }
829 SECTION("fruit")
830 {
831 value.second = "fruit";
832 }
833 }
834 SECTION("non-existent identity")
835 {
836 value.second = "nonexistent";
837 }
838 SECTION("weird module")
839 {
840 value.first = "ahahaha";
841 value.second = "pizza";
842 }
843 }
844 SECTION("different module identity, but withotu prefix")
845 {
846 node.first = "example-schema";
847 node.second = "foodIdentLeaf";
848 value.second = "pineapple";
849 }
850 REQUIRE_FALSE(ys.leafIdentityIsValid(path, node, value));
851 }
Václav Kubernát7d82da72019-04-11 15:16:38 +0200852
853 SECTION("grouping is not a node")
854 {
855 SECTION("example-schema:arithmeticFlags")
856 {
857 node.first = "example-schema";
858 node.second = "arithmeticFlags";
859 }
860
861 SECTION("example-schema:flags")
862 {
863 node.first = "example-schema";
864 node.second = "startAndStop";
865 }
866
867 REQUIRE(!ys.isPresenceContainer(path, node));
868 REQUIRE(!ys.isList(path, node));
869 REQUIRE(!ys.isLeaf(path, node));
870 REQUIRE(!ys.isContainer(path, node));
871 }
Václav Kubernát280df4a2019-11-01 14:46:34 +0100872
873 SECTION("choice is not a node")
874 {
875 SECTION("example-schema:interface")
876 {
877 node.first = "example-schema";
878 node.second = "interface";
879 }
880
881 REQUIRE(!ys.isPresenceContainer(path, node));
882 REQUIRE(!ys.isList(path, node));
883 REQUIRE(!ys.isLeaf(path, node));
884 REQUIRE(!ys.isContainer(path, node));
885 }
886
887 SECTION("case is not a node")
888 {
889 SECTION("example-schema:caseLoopback")
890 {
891 node.first = "example-schema";
892 node.second = "caseLoopback";
893 }
894
895 SECTION("example-schema:caseEthernet")
896 {
897 node.first = "example-schema";
898 node.second = "caseEthernet";
899 }
900
901 REQUIRE(!ys.isPresenceContainer(path, node));
902 REQUIRE(!ys.isList(path, node));
903 REQUIRE(!ys.isLeaf(path, node));
904 REQUIRE(!ys.isContainer(path, node));
905 }
Václav Kubernáta38d4172019-11-04 12:36:39 +0100906
907 SECTION("enum is disabled by if-feature if feature is not enabled")
908 {
909 node.first = "example-schema";
910 node.second = "pizzaSize";
911
912 std::string value = "large";
913
914 REQUIRE(!ys.leafEnumHasValue(path, node, value));
915 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200916 }
917}