blob: a90cb8e6904aca1500723964d3e36749b94993c3 [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át26b56082020-02-03 18:28:56 +010010#include "trompeloeil_doctest.hpp"
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átfa81c8c2020-02-13 17:22:46 +0100265 rpc myRpc {}
266
Václav Kubernát0d4db442018-07-18 17:18:43 +0200267})";
268
Václav Kubernát47a3f672019-11-08 15:42:43 +0100269namespace std {
270std::ostream& operator<<(std::ostream& s, const std::set<std::string> set)
271{
272 s << std::endl << "{";
273 std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", "));
274 s << "}" << std::endl;
275 return s;
276}
277}
278
Václav Kubernát0d4db442018-07-18 17:18:43 +0200279TEST_CASE("yangschema")
280{
Václav Kubernát4f77a252019-02-19 16:51:30 +0100281 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200282 YangSchema ys;
Václav Kubernátb52dc252019-12-04 13:03:39 +0100283 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto, auto) {
Václav Kubernát4f77a252019-02-19 16:51:30 +0100284 assert("example-schema"sv == modName);
285 return example_schema;
286 });
287 ys.addSchemaString(second_schema);
288
Václav Kubernátefcac932020-01-10 15:26:32 +0100289 schemaPath_ path{Scope::Absolute, {}};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200290 ModuleNodePair node;
291
292 SECTION("positive")
293 {
294 SECTION("isContainer")
295 {
296 SECTION("example-schema:a")
297 {
298 node.first = "example-schema";
299 node.second = "a";
300 }
301
302 SECTION("example-schema:a/a2")
303 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200304 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200305 node.second = "a2";
306 }
307
Václav Kubernát280df4a2019-11-01 14:46:34 +0100308 SECTION("example-schema:ethernet")
309 {
310 node.first = "example-schema";
311 node.second = "ethernet";
312 }
313
314 SECTION("example-schema:loopback")
315 {
316 node.first = "example-schema";
317 node.second = "loopback";
318 }
319
Václav Kubernát0d4db442018-07-18 17:18:43 +0200320 REQUIRE(ys.isContainer(path, node));
321 }
322 SECTION("isLeaf")
323 {
324 SECTION("example-schema:leafString")
325 {
326 node.first = "example-schema";
327 node.second = "leafString";
328 }
329
330 SECTION("example-schema:a/leafa")
331 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200332 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200333 node.first = "example-schema";
334 node.second = "leafa";
335 }
336
Václav Kubernát7d82da72019-04-11 15:16:38 +0200337 SECTION("example-schema:carry")
338 {
339 node.first = "example-schema";
340 node.second = "carry";
341 }
342
343 SECTION("example-schema:zero")
344 {
345 node.first = "example-schema";
346 node.second = "zero";
347 }
348
349 SECTION("example-schema:direction")
350 {
351 node.first = "example-schema";
352 node.second = "direction";
353 }
354
355 SECTION("example-schema:interrupt")
356 {
357 node.first = "example-schema";
358 node.second = "interrupt";
359 }
360
Václav Kubernát0d4db442018-07-18 17:18:43 +0200361 REQUIRE(ys.isLeaf(path, node));
362 }
363 SECTION("isModule")
364 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100365 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200366 }
367 SECTION("isList")
368 {
369 SECTION("example-schema:_list")
370 {
371 node.first = "example-schema";
372 node.second = "_list";
373 }
374
375 SECTION("example-schema:twoKeyList")
376 {
377 node.first = "example-schema";
378 node.second = "twoKeyList";
379 }
380
381 REQUIRE(ys.isList(path, node));
382 }
383 SECTION("isPresenceContainer")
384 {
385 SECTION("example-schema:a/a2/a3")
386 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200387 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
388 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a2")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200389 node.second = "a3";
390 }
391
392 REQUIRE(ys.isPresenceContainer(path, node));
393 }
394 SECTION("leafEnumHasValue")
395 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200396 std::string value;
Václav Kubernát6a713d62018-10-03 18:47:34 +0200397 SECTION("leafEnum")
398 {
399 node.first = "example-schema";
400 node.second = "leafEnum";
Václav Kubernát0d4db442018-07-18 17:18:43 +0200401
Václav Kubernát6a713d62018-10-03 18:47:34 +0200402 SECTION("lol")
403 value = "lol";
Václav Kubernát0d4db442018-07-18 17:18:43 +0200404
Václav Kubernát6a713d62018-10-03 18:47:34 +0200405 SECTION("data")
406 value = "data";
Václav Kubernát0d4db442018-07-18 17:18:43 +0200407
Václav Kubernát6a713d62018-10-03 18:47:34 +0200408 SECTION("coze")
409 value = "coze";
410 }
411
412 SECTION("leafEnumTypedef")
413 {
414 node.first = "example-schema";
415 node.second = "leafEnumTypedef";
416
417 SECTION("lol")
418 value = "lol";
419
420 SECTION("data")
421 value = "data";
422
423 SECTION("coze")
424 value = "coze";
425 }
426
427 SECTION("leafEnumTypedefRestricted")
428 {
429 node.first = "example-schema";
430 node.second = "leafEnumTypedefRestricted";
431
432 SECTION("data")
433 value = "data";
434
435 SECTION("coze")
436 value = "coze";
437 }
438
439 SECTION("leafEnumTypedefRestricted2")
440 {
441 node.first = "example-schema";
442 node.second = "leafEnumTypedefRestricted2";
443
444 SECTION("lol")
445 value = "lol";
446
447 SECTION("data")
448 value = "data";
449 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200450
Václav Kubernáta38d4172019-11-04 12:36:39 +0100451 SECTION("pizzaSize")
452 {
453 node.first = "example-schema";
454 node.second = "pizzaSize";
455
456 SECTION("small")
457 {
458 value = "small";
Václav Kubernáta38d4172019-11-04 12:36:39 +0100459 }
460 SECTION("medium")
461 {
462 value = "medium";
463 }
464
465 SECTION("large")
466 {
467 ys.enableFeature("example-schema", "bigPizzas");
468 value = "large";
469 }
470 }
471
Václav Kubernát0d4db442018-07-18 17:18:43 +0200472 REQUIRE(ys.leafEnumHasValue(path, node, value));
473 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100474 SECTION("leafIdentityIsValid")
475 {
476 ModuleValuePair value;
477
478 SECTION("foodIdentLeaf")
479 {
480 node.first = "example-schema";
481 node.second = "foodIdentLeaf";
482
483 SECTION("food")
484 {
485 value.second = "food";
486 }
487 SECTION("example-schema:food")
488 {
489 value.first = "example-schema";
490 value.second = "food";
491 }
492 SECTION("pizza")
493 {
494 value.second = "pizza";
495 }
496 SECTION("example-schema:pizza")
497 {
498 value.first = "example-schema";
499 value.second = "pizza";
500 }
501 SECTION("hawaii")
502 {
503 value.second = "hawaii";
504 }
505 SECTION("example-schema:hawaii")
506 {
507 value.first = "example-schema";
508 value.second = "hawaii";
509 }
510 SECTION("fruit")
511 {
512 value.second = "fruit";
513 }
514 SECTION("example-schema:fruit")
515 {
516 value.first = "example-schema";
517 value.second = "fruit";
518 }
519 SECTION("second-schema:pineapple")
520 {
521 value.first = "second-schema";
522 value.second = "pineapple";
523 }
524 }
525
526 SECTION("pizzaIdentLeaf")
527 {
528 node.first = "example-schema";
529 node.second = "pizzaIdentLeaf";
530
531 SECTION("pizza")
532 {
533 value.second = "pizza";
534 }
535 SECTION("example-schema:pizza")
536 {
537 value.first = "example-schema";
538 value.second = "pizza";
539 }
540 SECTION("hawaii")
541 {
542 value.second = "hawaii";
543 }
544 SECTION("example-schema:hawaii")
545 {
546 value.first = "example-schema";
547 value.second = "hawaii";
548 }
549 }
550
551 SECTION("foodDrinkIdentLeaf")
552 {
553 node.first = "example-schema";
554 node.second = "foodDrinkIdentLeaf";
555
556 SECTION("food")
557 {
558 value.second = "food";
559 }
560 SECTION("example-schema:food")
561 {
562 value.first = "example-schema";
563 value.second = "food";
564 }
565 SECTION("drink")
566 {
567 value.second = "drink";
568 }
569 SECTION("example-schema:drink")
570 {
571 value.first = "example-schema";
572 value.second = "drink";
573 }
574 }
575 REQUIRE(ys.leafIdentityIsValid(path, node, value));
576 }
577
Václav Kubernát0d4db442018-07-18 17:18:43 +0200578 SECTION("listHasKey")
579 {
580 std::string key;
581
582 SECTION("_list")
583 {
584 node.first = "example-schema";
585 node.second = "_list";
586 SECTION("number")
587 key = "number";
588 }
589
590 SECTION("twoKeyList")
591 {
592 node.first = "example-schema";
593 node.second = "twoKeyList";
594 SECTION("number")
595 key = "number";
596 SECTION("name")
597 key = "name";
598 }
599
600 REQUIRE(ys.listHasKey(path, node, key));
601 }
602 SECTION("listKeys")
603 {
604 std::set<std::string> set;
605
606 SECTION("_list")
607 {
608 set = {"number"};
609 node.first = "example-schema";
610 node.second = "_list";
611 }
612
613 SECTION("twoKeyList")
614 {
615 set = {"number", "name"};
616 node.first = "example-schema";
617 node.second = "twoKeyList";
618 }
619
620 REQUIRE(ys.listKeys(path, node) == set);
621 }
622 SECTION("leafType")
623 {
624 yang::LeafDataTypes type;
625
626 SECTION("leafString")
627 {
628 node.first = "example-schema";
629 node.second = "leafString";
630 type = yang::LeafDataTypes::String;
631 }
632
633 SECTION("leafDecimal")
634 {
635 node.first = "example-schema";
636 node.second = "leafDecimal";
637 type = yang::LeafDataTypes::Decimal;
638 }
639
640 SECTION("leafBool")
641 {
642 node.first = "example-schema";
643 node.second = "leafBool";
644 type = yang::LeafDataTypes::Bool;
645 }
646
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200647 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200648 {
649 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200650 node.second = "leafInt8";
651 type = yang::LeafDataTypes::Int8;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200652 }
653
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200654 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200655 {
656 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200657 node.second = "leafUint8";
658 type = yang::LeafDataTypes::Uint8;
659 }
660
661 SECTION("leafInt15")
662 {
663 node.first = "example-schema";
664 node.second = "leafInt16";
665 type = yang::LeafDataTypes::Int16;
666 }
667
668 SECTION("leafUint16")
669 {
670 node.first = "example-schema";
671 node.second = "leafUint16";
672 type = yang::LeafDataTypes::Uint16;
673 }
674
675 SECTION("leafInt32")
676 {
677 node.first = "example-schema";
678 node.second = "leafInt32";
679 type = yang::LeafDataTypes::Int32;
680 }
681
682 SECTION("leafUint32")
683 {
684 node.first = "example-schema";
685 node.second = "leafUint32";
686 type = yang::LeafDataTypes::Uint32;
687 }
688
689 SECTION("leafInt64")
690 {
691 node.first = "example-schema";
692 node.second = "leafInt64";
693 type = yang::LeafDataTypes::Int64;
694 }
695
696 SECTION("leafUint64")
697 {
698 node.first = "example-schema";
699 node.second = "leafUint64";
700 type = yang::LeafDataTypes::Uint64;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200701 }
702
703 SECTION("leafEnum")
704 {
705 node.first = "example-schema";
706 node.second = "leafEnum";
707 type = yang::LeafDataTypes::Enum;
708 }
709
710 REQUIRE(ys.leafType(path, node) == type);
711 }
712 SECTION("childNodes")
713 {
714 std::set<std::string> set;
715
716 SECTION("<root>")
717 {
718 set = {"example-schema:a", "example-schema:b", "example-schema:leafString",
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200719 "example-schema:leafDecimal", "example-schema:leafBool",
720 "example-schema:leafInt8", "example-schema:leafUint8",
721 "example-schema:leafInt16", "example-schema:leafUint16",
722 "example-schema:leafInt32", "example-schema:leafUint32",
723 "example-schema:leafInt64", "example-schema:leafUint64",
724 "example-schema:leafEnum", "example-schema:leafEnumTypedef",
Václav Kubernát6a713d62018-10-03 18:47:34 +0200725 "example-schema:leafEnumTypedefRestricted", "example-schema:leafEnumTypedefRestricted2",
Václav Kubernáteeb38842019-03-20 19:46:05 +0100726 "example-schema:foodIdentLeaf", "example-schema:pizzaIdentLeaf", "example-schema:foodDrinkIdentLeaf",
Václav Kubernát7d82da72019-04-11 15:16:38 +0200727 "example-schema:_list", "example-schema:twoKeyList", "second-schema:bla",
728 "example-schema:carry", "example-schema:zero", "example-schema:direction",
Václav Kubernát280df4a2019-11-01 14:46:34 +0100729 "example-schema:interrupt",
Václav Kubernáta38d4172019-11-04 12:36:39 +0100730 "example-schema:ethernet", "example-schema:loopback",
731 "example-schema:pizzaSize"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200732 }
733
Václav Kubernát4f77a252019-02-19 16:51:30 +0100734 SECTION("example-schema:a")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200735 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200736 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát4f77a252019-02-19 16:51:30 +0100737 set = {"a2", "leafa", "second-schema:augmentedContainer"};
738 }
739
740 SECTION("second-schema:bla")
741 {
742 path.m_nodes.push_back(schemaNode_(module_{"second-schema"}, container_("bla")));
743 set = {"bla2"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200744 }
745
Václav Kubernát47a3f672019-11-08 15:42:43 +0100746 SECTION("example-schema:ethernet")
747 {
748 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("ethernet")));
749 set = {"ip"};
750 }
751
Václav Kubernáte7d4aea2018-09-11 18:15:48 +0200752 REQUIRE(ys.childNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200753 }
754 }
755
756 SECTION("negative")
757 {
758 SECTION("nonexistent nodes")
759 {
760 SECTION("example-schema:coze")
761 {
762 node.first = "example-schema";
763 node.second = "coze";
764 }
765
766 SECTION("example-schema:a/nevim")
767 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200768 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200769 node.second = "nevim";
770 }
771
772 SECTION("modul:a/nevim")
773 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200774 path.m_nodes.push_back(schemaNode_(module_{"modul"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200775 node.second = "nevim";
776 }
777
778 REQUIRE(!ys.isPresenceContainer(path, node));
779 REQUIRE(!ys.isList(path, node));
780 REQUIRE(!ys.isLeaf(path, node));
781 REQUIRE(!ys.isContainer(path, node));
782 }
783
784 SECTION("\"is\" methods return false for existing nodes for different nodetypes")
785 {
786 SECTION("example-schema:a")
787 {
788 node.first = "example-schema";
789 node.second = "a";
790 }
791
792 SECTION("example-schema:a/a2")
793 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200794 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200795 node.second = "a2";
796 }
797
798 REQUIRE(!ys.isPresenceContainer(path, node));
799 REQUIRE(!ys.isList(path, node));
800 REQUIRE(!ys.isLeaf(path, node));
801 }
802
803 SECTION("nodetype-specific methods called with different nodetypes")
804 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200805 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200806 node.second = "a2";
807
808 REQUIRE(!ys.leafEnumHasValue(path, node, "haha"));
809 REQUIRE(!ys.listHasKey(path, node, "chacha"));
810 }
811
812 SECTION("nonexistent module")
813 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100814 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200815 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100816
817 SECTION("leafIdentityIsValid")
818 {
819 ModuleValuePair value;
820 SECTION("pizzaIdentLeaf")
821 {
822 node.first = "example-schema";
823 node.second = "pizzaIdentLeaf";
824
825 SECTION("wrong base ident")
826 {
827 SECTION("food")
828 {
829 value.second = "food";
830 }
831 SECTION("fruit")
832 {
833 value.second = "fruit";
834 }
835 }
836 SECTION("non-existent identity")
837 {
838 value.second = "nonexistent";
839 }
840 SECTION("weird module")
841 {
842 value.first = "ahahaha";
843 value.second = "pizza";
844 }
845 }
846 SECTION("different module identity, but withotu prefix")
847 {
848 node.first = "example-schema";
849 node.second = "foodIdentLeaf";
850 value.second = "pineapple";
851 }
852 REQUIRE_FALSE(ys.leafIdentityIsValid(path, node, value));
853 }
Václav Kubernát7d82da72019-04-11 15:16:38 +0200854
855 SECTION("grouping is not a node")
856 {
857 SECTION("example-schema:arithmeticFlags")
858 {
859 node.first = "example-schema";
860 node.second = "arithmeticFlags";
861 }
862
863 SECTION("example-schema:flags")
864 {
865 node.first = "example-schema";
866 node.second = "startAndStop";
867 }
868
869 REQUIRE(!ys.isPresenceContainer(path, node));
870 REQUIRE(!ys.isList(path, node));
871 REQUIRE(!ys.isLeaf(path, node));
872 REQUIRE(!ys.isContainer(path, node));
873 }
Václav Kubernát280df4a2019-11-01 14:46:34 +0100874
875 SECTION("choice is not a node")
876 {
877 SECTION("example-schema:interface")
878 {
879 node.first = "example-schema";
880 node.second = "interface";
881 }
882
883 REQUIRE(!ys.isPresenceContainer(path, node));
884 REQUIRE(!ys.isList(path, node));
885 REQUIRE(!ys.isLeaf(path, node));
886 REQUIRE(!ys.isContainer(path, node));
887 }
888
889 SECTION("case is not a node")
890 {
891 SECTION("example-schema:caseLoopback")
892 {
893 node.first = "example-schema";
894 node.second = "caseLoopback";
895 }
896
897 SECTION("example-schema:caseEthernet")
898 {
899 node.first = "example-schema";
900 node.second = "caseEthernet";
901 }
902
903 REQUIRE(!ys.isPresenceContainer(path, node));
904 REQUIRE(!ys.isList(path, node));
905 REQUIRE(!ys.isLeaf(path, node));
906 REQUIRE(!ys.isContainer(path, node));
907 }
Václav Kubernáta38d4172019-11-04 12:36:39 +0100908
909 SECTION("enum is disabled by if-feature if feature is not enabled")
910 {
911 node.first = "example-schema";
912 node.second = "pizzaSize";
913
914 std::string value = "large";
915
916 REQUIRE(!ys.leafEnumHasValue(path, node, value));
917 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200918 }
919}