blob: e2ece6f8403761e9fdcc859d508d1748417bf5f0 [file] [log] [blame]
Václav Kubernát0d4db442018-07-18 17:18:43 +02001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
4 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8
Václav Kubernát47a3f672019-11-08 15:42:43 +01009#include <experimental/iterator>
Václav Kubernát3a99f002020-03-31 02:27:41 +020010#include "leaf_data_helpers.hpp"
Václav Kubernát1e09bd62020-02-17 15:13:38 +010011#include "pretty_printers.hpp"
Václav Kubernát26b56082020-02-03 18:28:56 +010012#include "trompeloeil_doctest.hpp"
Václav Kubernát0d4db442018-07-18 17:18:43 +020013#include "yang_schema.hpp"
14
Václav Kubernát4f77a252019-02-19 16:51:30 +010015const char* second_schema = R"(
16module second-schema {
17 namespace "http://example.com/nevim";
18 prefix second;
19
20 import example-schema {
21 prefix "example";
22 }
23
Václav Kubernáteeb38842019-03-20 19:46:05 +010024 identity pineapple {
25 base "example:fruit";
26 }
27
Václav Kubernát4f77a252019-02-19 16:51:30 +010028 augment /example:a {
29 container augmentedContainer {
30 }
31 }
32
33 container bla {
34 container bla2 {
35 }
36 }
37}
38)";
39
Václav Kubernát82d74632020-05-11 15:59:53 +020040const char* included_submodule = R"(
41submodule sub-module {
42 yang-version 1.1;
43
44 belongs-to example-schema {
45 prefix sub;
46 }
47
48 leaf subLeaf {
49 type string;
50 }
51}
52)";
53
Václav Kubernát4f77a252019-02-19 16:51:30 +010054const char* example_schema = R"(
Václav Kubernát0d4db442018-07-18 17:18:43 +020055module example-schema {
Václav Kubernát6a713d62018-10-03 18:47:34 +020056 yang-version 1.1;
Václav Kubernát0d4db442018-07-18 17:18:43 +020057 namespace "http://example.com/example-sports";
58 prefix coze;
59
Václav Kubernát82d74632020-05-11 15:59:53 +020060 include sub-module;
61
Václav Kubernáteeb38842019-03-20 19:46:05 +010062 identity drink {
63 }
64
65 identity voda {
66 base "drink";
67 }
68
69 identity food {
70 }
71
72 identity fruit {
73 base "food";
74 }
75
76 identity pizza {
77 base "food";
78 }
79
80 identity hawaii {
81 base "pizza";
82 }
83
Václav Kubernát0d4db442018-07-18 17:18:43 +020084 container a {
85 container a2 {
86 container a3 {
87 presence true;
88 }
89 }
90
91 leaf leafa {
92 type string;
93 }
94 }
95
96 container b {
97 container b2 {
98 presence true;
99 container b3 {
100 }
101 }
102 }
103
104 leaf leafString {
105 type string;
106 }
107
108 leaf leafDecimal {
109 type decimal64 {
110 fraction-digits 5;
111 }
112 }
113
114 leaf leafBool {
115 type boolean;
116 }
117
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200118 leaf leafInt8 {
119 type int8;
120 }
121
122 leaf leafUint8 {
123 type uint8;
124 }
125
126 leaf leafInt16 {
127 type int16;
128 }
129
130 leaf leafUint16 {
131 type uint16;
132 }
133
134 leaf leafInt32 {
Václav Kubernát1e09bd62020-02-17 15:13:38 +0100135 description "A 32-bit integer leaf.";
Václav Kubernát0d4db442018-07-18 17:18:43 +0200136 type int32;
137 }
138
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200139 leaf leafUint32 {
Václav Kubernát0d4db442018-07-18 17:18:43 +0200140 type uint32;
141 }
142
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200143 leaf leafInt64 {
144 type int64;
145 }
146
147 leaf leafUint64 {
148 type uint64;
Václav Kubernátb1a75c62020-04-21 15:20:16 +0200149 default 9001;
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200150 }
151
Václav Kubernát0d4db442018-07-18 17:18:43 +0200152 leaf leafEnum {
153 type enumeration {
154 enum lol;
155 enum data;
156 enum coze;
157 }
158 }
159
Václav Kubernát6a713d62018-10-03 18:47:34 +0200160 typedef enumTypedef {
161 type enumeration {
162 enum lol;
163 enum data;
164 enum coze;
165 }
Václav Kubernátb1a75c62020-04-21 15:20:16 +0200166 default data;
Václav Kubernát6a713d62018-10-03 18:47:34 +0200167 }
168
169 typedef enumTypedefRestricted {
170 type enumTypedef {
171 enum lol;
172 enum data;
173 }
174 }
175
176 leaf leafEnumTypedef {
177 type enumTypedef;
178 }
179
180 leaf leafEnumTypedefRestricted {
181 type enumTypedef {
182 enum data;
183 enum coze;
184 }
185 }
186
187 leaf leafEnumTypedefRestricted2 {
188 type enumTypedefRestricted;
189 }
190
Václav Kubernáteeb38842019-03-20 19:46:05 +0100191 leaf foodIdentLeaf {
192 type identityref {
193 base "food";
194 }
195 }
196
197 leaf pizzaIdentLeaf {
198 type identityref {
199 base "pizza";
200 }
201 }
202
203 leaf foodDrinkIdentLeaf {
204 type identityref {
205 base "food";
206 base "drink";
207 }
208 }
209
Václav Kubernát0d4db442018-07-18 17:18:43 +0200210 list _list {
211 key number;
212
213 leaf number {
214 type int32;
215 }
216
217 container contInList {
218 presence true;
219 }
220 }
221
222 list twoKeyList {
223 key "name number";
224
225 leaf number {
226 type int32;
227 }
228
229 leaf name {
230 type string;
231 }
232 }
Václav Kubernát7d82da72019-04-11 15:16:38 +0200233
234 grouping arithmeticFlags {
235 leaf carry {
236 type boolean;
237 }
238 leaf zero {
239 type boolean;
240 }
241 }
242
243 grouping flags {
244 leaf direction {
245 type boolean;
246 }
247 leaf interrupt {
248 type boolean;
249 }
250
251 uses arithmeticFlags;
252 }
253
254 uses flags;
Václav Kubernát280df4a2019-11-01 14:46:34 +0100255
256 choice interface {
257 case caseLoopback {
258 container loopback {
259 leaf ip {
260 type string;
261 }
262 }
263 }
264
265 case caseEthernet {
266 container ethernet {
267 leaf ip {
268 type string;
269 }
270 }
271 }
272 }
273
Václav Kubernáta38d4172019-11-04 12:36:39 +0100274 feature bigPizzas;
275
276 leaf pizzaSize {
277 type enumeration {
278 enum large {
279 if-feature "bigPizzas";
280 }
281 enum medium;
282 enum small;
283 }
284 }
285
Václav Kubernát1e09bd62020-02-17 15:13:38 +0100286 leaf length {
287 type int32;
288 units "m";
289 }
290
291 leaf wavelength {
292 type decimal64 {
293 fraction-digits 10;
294 }
295 units "nm";
296 }
297
298 typedef seconds {
299 type int32;
300 units "s";
301 }
302
303 leaf duration {
304 type seconds;
305 }
306
307 leaf another-duration {
308 type seconds;
309 units "vt";
310 }
311
Václav Kubernátbd5e3c22020-02-19 15:22:00 +0100312 leaf activeNumber {
313 type leafref {
314 path "/_list/number";
315 }
316 }
317
Václav Kubernátfa81c8c2020-02-13 17:22:46 +0100318 rpc myRpc {}
319
Václav Kubernát2984f442020-02-20 17:43:35 +0100320 leaf numberOrString {
321 type union {
322 type int32;
323 type string;
324 }
325 description "Can be an int32 or a string.";
326 }
327
328 list portSettings {
329 key "port";
330 leaf port {
331 type enumeration {
332 enum eth0;
333 enum eth1;
334 enum eth2;
335 }
336 }
337 }
338
339 feature weirdPortNames;
340
341 list portMapping {
342 key "port";
343 leaf port {
344 type enumeration {
345 enum WEIRD {
346 if-feature "weirdPortNames";
347 }
348 enum utf2;
349 enum utf3;
350 }
351 }
352 }
353
354 leaf activeMappedPort {
355 type leafref {
356 path "../portMapping/port";
357 }
358 }
359
360 leaf activePort {
361 type union {
362 type enumeration {
363 enum wlan0;
364 enum wlan1;
365 }
366 type leafref {
367 path "../portSettings/port";
368 }
369 type leafref {
370 path "../activeMappedPort";
371 }
Jan Kundrát379bb572020-05-07 03:23:13 +0200372 type empty;
Václav Kubernát2984f442020-02-20 17:43:35 +0100373 }
374 }
375
Jan Kundrát379bb572020-05-07 03:23:13 +0200376 leaf dummyLeaf {
377 type empty;
378 }
379
Václav Kubernát0599e9f2020-04-21 09:51:33 +0200380 leaf clockSpeed {
381 type int64;
382 config false;
383 }
384
385 container systemStats {
386 config false;
387 leaf upTime {
388 type uint64;
389 }
390 }
391
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +0200392 leaf obsoleteLeaf {
393 type int32;
394 status obsolete;
395 }
396
397 leaf deprecatedLeaf {
398 type int32;
399 status deprecated;
400 }
401
402 typedef deprecatedType {
403 type int32;
404 status deprecated;
405 }
406
407 leaf obsoleteLeafWithDeprecatedType {
408 type deprecatedType;
409 status obsolete;
410 }
411
412 typedef obsoleteType {
413 type int32;
414 status obsolete;
415 }
416
417 leaf obsoleteLeafWithObsoleteType {
418 type deprecatedType;
419 status obsolete;
420 }
421
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200422 leaf-list addresses {
423 type string;
424 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200425})";
426
Václav Kubernát47a3f672019-11-08 15:42:43 +0100427namespace std {
428std::ostream& operator<<(std::ostream& s, const std::set<std::string> set)
429{
430 s << std::endl << "{";
431 std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", "));
432 s << "}" << std::endl;
433 return s;
434}
435}
436
Václav Kubernát0d4db442018-07-18 17:18:43 +0200437TEST_CASE("yangschema")
438{
Václav Kubernát82d74632020-05-11 15:59:53 +0200439 using namespace std::string_literals;
Václav Kubernát4f77a252019-02-19 16:51:30 +0100440 using namespace std::string_view_literals;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200441 YangSchema ys;
Václav Kubernát82d74632020-05-11 15:59:53 +0200442 ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) {
443 if (modName != "example-schema"sv) {
444 throw std::logic_error("unrecognized module "s + modName);
445 }
446 if (subModule == nullptr) {
447 return example_schema;
448 }
449 if (subModule == "sub-module"sv) {
450 return included_submodule;
451 }
452
453 throw std::logic_error("unrecognized submodule "s + subModule);
Václav Kubernát4f77a252019-02-19 16:51:30 +0100454 });
455 ys.addSchemaString(second_schema);
456
Václav Kubernátefcac932020-01-10 15:26:32 +0100457 schemaPath_ path{Scope::Absolute, {}};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200458 ModuleNodePair node;
459
460 SECTION("positive")
461 {
462 SECTION("isContainer")
463 {
464 SECTION("example-schema:a")
465 {
466 node.first = "example-schema";
467 node.second = "a";
468 }
469
470 SECTION("example-schema:a/a2")
471 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200472 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200473 node.second = "a2";
474 }
475
Václav Kubernát280df4a2019-11-01 14:46:34 +0100476 SECTION("example-schema:ethernet")
477 {
478 node.first = "example-schema";
479 node.second = "ethernet";
480 }
481
482 SECTION("example-schema:loopback")
483 {
484 node.first = "example-schema";
485 node.second = "loopback";
486 }
487
Václav Kubernát0d4db442018-07-18 17:18:43 +0200488 REQUIRE(ys.isContainer(path, node));
489 }
490 SECTION("isLeaf")
491 {
492 SECTION("example-schema:leafString")
493 {
494 node.first = "example-schema";
495 node.second = "leafString";
496 }
497
498 SECTION("example-schema:a/leafa")
499 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200500 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200501 node.first = "example-schema";
502 node.second = "leafa";
503 }
504
Václav Kubernát7d82da72019-04-11 15:16:38 +0200505 SECTION("example-schema:carry")
506 {
507 node.first = "example-schema";
508 node.second = "carry";
509 }
510
511 SECTION("example-schema:zero")
512 {
513 node.first = "example-schema";
514 node.second = "zero";
515 }
516
517 SECTION("example-schema:direction")
518 {
519 node.first = "example-schema";
520 node.second = "direction";
521 }
522
523 SECTION("example-schema:interrupt")
524 {
525 node.first = "example-schema";
526 node.second = "interrupt";
527 }
528
Václav Kubernát0d4db442018-07-18 17:18:43 +0200529 REQUIRE(ys.isLeaf(path, node));
530 }
531 SECTION("isModule")
532 {
Václav Kubernát75877de2019-11-20 17:43:02 +0100533 REQUIRE(ys.isModule("example-schema"));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200534 }
535 SECTION("isList")
536 {
537 SECTION("example-schema:_list")
538 {
539 node.first = "example-schema";
540 node.second = "_list";
541 }
542
543 SECTION("example-schema:twoKeyList")
544 {
545 node.first = "example-schema";
546 node.second = "twoKeyList";
547 }
548
549 REQUIRE(ys.isList(path, node));
550 }
551 SECTION("isPresenceContainer")
552 {
553 SECTION("example-schema:a/a2/a3")
554 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200555 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
556 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a2")));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200557 node.second = "a3";
558 }
559
560 REQUIRE(ys.isPresenceContainer(path, node));
561 }
Václav Kubernáteeb38842019-03-20 19:46:05 +0100562
Václav Kubernát0d4db442018-07-18 17:18:43 +0200563 SECTION("listHasKey")
564 {
565 std::string key;
566
567 SECTION("_list")
568 {
Václav Kubernát912b9492020-05-29 02:03:40 +0200569 path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"_list"}});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200570 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200571 {
572 key = "number";
573 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200574 }
575
576 SECTION("twoKeyList")
577 {
Václav Kubernát912b9492020-05-29 02:03:40 +0200578 path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"twoKeyList"}});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200579 SECTION("number")
Václav Kubernát912b9492020-05-29 02:03:40 +0200580 {
581 key = "number";
582 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200583 SECTION("name")
Václav Kubernát912b9492020-05-29 02:03:40 +0200584 {
585 key = "name";
586 }
Václav Kubernát0d4db442018-07-18 17:18:43 +0200587 }
588
Václav Kubernát912b9492020-05-29 02:03:40 +0200589 REQUIRE(ys.listHasKey(path, key));
Václav Kubernát0d4db442018-07-18 17:18:43 +0200590 }
591 SECTION("listKeys")
592 {
593 std::set<std::string> set;
594
595 SECTION("_list")
596 {
Václav Kubernát912b9492020-05-29 02:03:40 +0200597 path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"_list"}});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200598 set = {"number"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200599 }
600
601 SECTION("twoKeyList")
602 {
Václav Kubernát912b9492020-05-29 02:03:40 +0200603 path.m_nodes.push_back(schemaNode_{module_{"example-schema"}, list_{"twoKeyList"}});
Václav Kubernát0d4db442018-07-18 17:18:43 +0200604 set = {"number", "name"};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200605 }
606
Václav Kubernát912b9492020-05-29 02:03:40 +0200607 REQUIRE(ys.listKeys(path) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200608 }
609 SECTION("leafType")
610 {
Václav Kubernát3a99f002020-03-31 02:27:41 +0200611 yang::LeafDataType type;
Václav Kubernát0d4db442018-07-18 17:18:43 +0200612
613 SECTION("leafString")
614 {
615 node.first = "example-schema";
616 node.second = "leafString";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200617 type = yang::String{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200618 }
619
620 SECTION("leafDecimal")
621 {
622 node.first = "example-schema";
623 node.second = "leafDecimal";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200624 type = yang::Decimal{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200625 }
626
627 SECTION("leafBool")
628 {
629 node.first = "example-schema";
630 node.second = "leafBool";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200631 type = yang::Bool{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200632 }
633
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200634 SECTION("leafInt8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200635 {
636 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200637 node.second = "leafInt8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200638 type = yang::Int8{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200639 }
640
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200641 SECTION("leafUint8")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200642 {
643 node.first = "example-schema";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200644 node.second = "leafUint8";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200645 type = yang::Uint8{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200646 }
647
Václav Kubernátb6d02752020-04-03 00:25:10 +0200648 SECTION("leafInt16")
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200649 {
650 node.first = "example-schema";
651 node.second = "leafInt16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200652 type = yang::Int16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200653 }
654
655 SECTION("leafUint16")
656 {
657 node.first = "example-schema";
658 node.second = "leafUint16";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200659 type = yang::Uint16{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200660 }
661
662 SECTION("leafInt32")
663 {
664 node.first = "example-schema";
665 node.second = "leafInt32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200666 type = yang::Int32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200667 }
668
669 SECTION("leafUint32")
670 {
671 node.first = "example-schema";
672 node.second = "leafUint32";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200673 type = yang::Uint32{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200674 }
675
676 SECTION("leafInt64")
677 {
678 node.first = "example-schema";
679 node.second = "leafInt64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200680 type = yang::Int64{};
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200681 }
682
683 SECTION("leafUint64")
684 {
685 node.first = "example-schema";
686 node.second = "leafUint64";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200687 type = yang::Uint64{};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200688 }
689
690 SECTION("leafEnum")
691 {
692 node.first = "example-schema";
693 node.second = "leafEnum";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200694 type = createEnum({"lol", "data", "coze"});
695 }
696
697 SECTION("leafEnumTypedef")
698 {
699 node.first = "example-schema";
700 node.second = "leafEnumTypedef";
701 type = createEnum({"lol", "data", "coze"});
702 }
703
704 SECTION("leafEnumTypedefRestricted")
705 {
706 node.first = "example-schema";
707 node.second = "leafEnumTypedefRestricted";
708 type = createEnum({"data", "coze"});
709 }
710
711 SECTION("leafEnumTypedefRestricted2")
712 {
713 node.first = "example-schema";
714 node.second = "leafEnumTypedefRestricted2";
715 type = createEnum({"lol", "data"});
716 }
717
718 SECTION("pizzaSize")
719 {
720 node.first = "example-schema";
721 node.second = "pizzaSize";
722
723 SECTION("bigPizzas disabled")
724 {
725 type = createEnum({"small", "medium"});
726 }
727 SECTION("bigPizzas enabled")
728 {
729 ys.enableFeature("example-schema", "bigPizzas");
730 type = createEnum({"small", "medium", "large"});
731 }
732 }
733
734 SECTION("foodIdentLeaf")
735 {
736 node.first = "example-schema";
737 node.second = "foodIdentLeaf";
738 type = yang::IdentityRef{{{"second-schema", "pineapple"},
739 {"example-schema", "food"},
740 {"example-schema", "pizza"},
741 {"example-schema", "hawaii"},
742 {"example-schema", "fruit"}}};
743 }
744
745 SECTION("pizzaIdentLeaf")
746 {
747 node.first = "example-schema";
748 node.second = "pizzaIdentLeaf";
749
750 type = yang::IdentityRef{{
751 {"example-schema", "pizza"},
752 {"example-schema", "hawaii"},
753 }};
754 }
755
756 SECTION("foodDrinkIdentLeaf")
757 {
758 node.first = "example-schema";
759 node.second = "foodDrinkIdentLeaf";
760
761 type = yang::IdentityRef{{
762 {"example-schema", "food"},
763 {"example-schema", "drink"},
764 {"example-schema", "fruit"},
765 {"example-schema", "hawaii"},
766 {"example-schema", "pizza"},
767 {"example-schema", "voda"},
768 {"second-schema", "pineapple"},
769 }};
Václav Kubernát0d4db442018-07-18 17:18:43 +0200770 }
771
Václav Kubernátb6d02752020-04-03 00:25:10 +0200772 SECTION("activeNumber")
773 {
774 node.first = "example-schema";
775 node.second = "activeNumber";
Václav Kubernát3a99f002020-03-31 02:27:41 +0200776 type.emplace<yang::LeafRef>(
777 "/example-schema:_list/number",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200778 std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number"))
Václav Kubernát3a99f002020-03-31 02:27:41 +0200779 );
Václav Kubernátb6d02752020-04-03 00:25:10 +0200780 }
781
Václav Kubernát2984f442020-02-20 17:43:35 +0100782 SECTION("activePort")
783 {
784 node.first = "example-schema";
785 node.second = "activePort";
786
787 yang::Enum enums = [&ys]() {
788 SECTION("weird ports disabled")
789 {
790 return createEnum({"utf2", "utf3"});
791 }
792 SECTION("weird ports enabled")
793 {
794 ys.enableFeature("example-schema", "weirdPortNames");
795 return createEnum({"WEIRD", "utf2", "utf3"});
796 }
797 __builtin_unreachable();
798 }();
799
800 type = yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +0200801 yang::TypeInfo{createEnum({"wlan0", "wlan1"})},
802 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100803 "/example-schema:portSettings/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200804 std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"}))
805 }},
806 yang::TypeInfo{yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100807 "/example-schema:activeMappedPort",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200808 std::make_unique<yang::TypeInfo>(yang::LeafRef{
Václav Kubernát2984f442020-02-20 17:43:35 +0100809 "/example-schema:portMapping/port",
Václav Kubernát13b23d72020-04-16 21:49:51 +0200810 std::make_unique<yang::TypeInfo>(enums)
811 })
812 }},
Jan Kundrát379bb572020-05-07 03:23:13 +0200813 yang::TypeInfo{yang::Empty{}},
Václav Kubernát2984f442020-02-20 17:43:35 +0100814 }};
815 }
816
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200817 SECTION("addresses")
818 {
819 node.first = "example-schema";
820 node.second = "addresses";
821 type.emplace<yang::String>();
822 }
823
824
Václav Kubernát0d4db442018-07-18 17:18:43 +0200825 REQUIRE(ys.leafType(path, node) == type);
826 }
Václav Kubernát3a823f42020-04-29 23:40:21 +0200827 SECTION("availableNodes")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200828 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200829 // TODO: merge "path" and "module" sections and add recursive versions to the path section
830 SECTION("paths")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200831 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200832 std::set<ModuleNodePair> set;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200833
Václav Kubernát95b08872020-04-28 01:04:17 +0200834 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200835 SECTION("<root>")
836 {
Václav Kubernát95b08872020-04-28 01:04:17 +0200837 set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"},
838 {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"},
839 {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"},
840 {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"},
841 {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"},
842 {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"},
843 {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"},
844 {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"},
845 {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"},
846 {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"},
847 {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"},
848 {"example-schema"s, "interrupt"},
849 {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"},
850 {"example-schema"s, "pizzaSize"},
851 {"example-schema"s, "length"}, {"example-schema"s, "wavelength"},
852 {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"},
853 {"example-schema"s, "activeNumber"},
854 {"example-schema"s, "numberOrString"},
855 {"example-schema"s, "portSettings"},
856 {"example-schema"s, "portMapping"},
857 {"example-schema"s, "activeMappedPort"},
858 {"example-schema"s, "activePort"},
859 {"example-schema"s, "clockSpeed"},
860 {"example-schema"s, "deprecatedLeaf"},
861 {"example-schema"s, "obsoleteLeaf"},
862 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
863 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200864 {"example-schema"s, "myRpc"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200865 {"example-schema"s, "systemStats"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200866 {"example-schema"s, "dummyLeaf"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200867 {"example-schema"s, "addresses"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200868 {"example-schema"s, "subLeaf"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200869 }
870
871 SECTION("example-schema:a")
872 {
873 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát95b08872020-04-28 01:04:17 +0200874 set = {
875 {boost::none, "a2"},
876 {boost::none, "leafa"},
877 {"second-schema"s, "augmentedContainer"}
878 };
Václav Kubernát3a823f42020-04-29 23:40:21 +0200879 }
880
881 SECTION("example-schema:ethernet")
882 {
883 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("ethernet")));
Václav Kubernát95b08872020-04-28 01:04:17 +0200884 set = {{boost::none, "ip"}};
885 }
886
887 SECTION("second-schema:bla")
888 {
889 path.m_nodes.push_back(schemaNode_(module_{"second-schema"}, container_("bla")));
890 set = {{boost::none, "bla2"}};
Václav Kubernát3a823f42020-04-29 23:40:21 +0200891 }
892
893 REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set);
Václav Kubernát0d4db442018-07-18 17:18:43 +0200894 }
895
Václav Kubernát3a823f42020-04-29 23:40:21 +0200896 SECTION("modules")
Václav Kubernát0d4db442018-07-18 17:18:43 +0200897 {
Václav Kubernát3a823f42020-04-29 23:40:21 +0200898 std::string module;
Václav Kubernát95b08872020-04-28 01:04:17 +0200899 std::set<ModuleNodePair> expectedNonRecursive;
900 std::set<ModuleNodePair> expectedRecursive;
901 using namespace std::string_literals;
Václav Kubernát3a823f42020-04-29 23:40:21 +0200902 SECTION("example-schema")
903 {
904 module = "example-schema";
905 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200906 {"example-schema"s, "_list"},
907 {"example-schema"s, "a"},
908 {"example-schema"s, "activeMappedPort"},
909 {"example-schema"s, "activeNumber"},
910 {"example-schema"s, "activePort"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200911 {"example-schema"s, "addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200912 {"example-schema"s, "another-duration"},
913 {"example-schema"s, "b"},
914 {"example-schema"s, "carry"},
915 {"example-schema"s, "clockSpeed"},
916 {"example-schema"s, "deprecatedLeaf"},
917 {"example-schema"s, "direction"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200918 {"example-schema"s, "dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200919 {"example-schema"s, "duration"},
920 {"example-schema"s, "ethernet"},
921 {"example-schema"s, "foodDrinkIdentLeaf"},
922 {"example-schema"s, "foodIdentLeaf"},
923 {"example-schema"s, "interrupt"},
924 {"example-schema"s, "leafBool"},
925 {"example-schema"s, "leafDecimal"},
926 {"example-schema"s, "leafEnum"},
927 {"example-schema"s, "leafEnumTypedef"},
928 {"example-schema"s, "leafEnumTypedefRestricted"},
929 {"example-schema"s, "leafEnumTypedefRestricted2"},
930 {"example-schema"s, "leafInt16"},
931 {"example-schema"s, "leafInt32"},
932 {"example-schema"s, "leafInt64"},
933 {"example-schema"s, "leafInt8"},
934 {"example-schema"s, "leafString"},
935 {"example-schema"s, "leafUint16"},
936 {"example-schema"s, "leafUint32"},
937 {"example-schema"s, "leafUint64"},
938 {"example-schema"s, "leafUint8"},
939 {"example-schema"s, "length"},
940 {"example-schema"s, "loopback"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +0200941 {"example-schema"s, "myRpc"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200942 {"example-schema"s, "numberOrString"},
943 {"example-schema"s, "obsoleteLeaf"},
944 {"example-schema"s, "obsoleteLeafWithDeprecatedType"},
945 {"example-schema"s, "obsoleteLeafWithObsoleteType"},
946 {"example-schema"s, "pizzaIdentLeaf"},
947 {"example-schema"s, "pizzaSize"},
948 {"example-schema"s, "portMapping"},
949 {"example-schema"s, "portSettings"},
950 {"example-schema"s, "systemStats"},
951 {"example-schema"s, "twoKeyList"},
952 {"example-schema"s, "wavelength"},
Václav Kubernát82d74632020-05-11 15:59:53 +0200953 {"example-schema"s, "zero"},
954 {"example-schema"s, "subLeaf"}
Václav Kubernát3a823f42020-04-29 23:40:21 +0200955 };
956 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +0200957 {boost::none, "/example-schema:_list"},
958 {boost::none, "/example-schema:_list/contInList"},
959 {boost::none, "/example-schema:_list/number"},
960 {boost::none, "/example-schema:a"},
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200961 {boost::none, "/example-schema:addresses"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200962 {boost::none, "/example-schema:a/a2"},
963 {boost::none, "/example-schema:a/a2/a3"},
964 {boost::none, "/example-schema:a/leafa"},
965 {boost::none, "/example-schema:a/second-schema:augmentedContainer"},
966 {boost::none, "/example-schema:activeMappedPort"},
967 {boost::none, "/example-schema:activeNumber"},
968 {boost::none, "/example-schema:activePort"},
969 {boost::none, "/example-schema:another-duration"},
970 {boost::none, "/example-schema:b"},
971 {boost::none, "/example-schema:b/b2"},
972 {boost::none, "/example-schema:b/b2/b3"},
973 {boost::none, "/example-schema:carry"},
974 {boost::none, "/example-schema:clockSpeed"},
975 {boost::none, "/example-schema:deprecatedLeaf"},
976 {boost::none, "/example-schema:direction"},
977 {boost::none, "/example-schema:duration"},
Jan Kundrát379bb572020-05-07 03:23:13 +0200978 {boost::none, "/example-schema:dummyLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +0200979 {boost::none, "/example-schema:foodDrinkIdentLeaf"},
980 {boost::none, "/example-schema:foodIdentLeaf"},
981 {boost::none, "/example-schema:interface/caseEthernet/ethernet"},
982 {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"},
983 {boost::none, "/example-schema:interface/caseLoopback/loopback"},
984 {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"},
985 {boost::none, "/example-schema:interrupt"},
986 {boost::none, "/example-schema:leafBool"},
987 {boost::none, "/example-schema:leafDecimal"},
988 {boost::none, "/example-schema:leafEnum"},
989 {boost::none, "/example-schema:leafEnumTypedef"},
990 {boost::none, "/example-schema:leafEnumTypedefRestricted"},
991 {boost::none, "/example-schema:leafEnumTypedefRestricted2"},
992 {boost::none, "/example-schema:leafInt16"},
993 {boost::none, "/example-schema:leafInt32"},
994 {boost::none, "/example-schema:leafInt64"},
995 {boost::none, "/example-schema:leafInt8"},
996 {boost::none, "/example-schema:leafString"},
997 {boost::none, "/example-schema:leafUint16"},
998 {boost::none, "/example-schema:leafUint32"},
999 {boost::none, "/example-schema:leafUint64"},
1000 {boost::none, "/example-schema:leafUint8"},
1001 {boost::none, "/example-schema:length"},
Václav Kubernátaaafeae2020-05-05 15:41:45 +02001002 {boost::none, "/example-schema:myRpc"},
1003 {boost::none, "/example-schema:myRpc/input"},
1004 {boost::none, "/example-schema:myRpc/output"},
Václav Kubernát95b08872020-04-28 01:04:17 +02001005 {boost::none, "/example-schema:numberOrString"},
1006 {boost::none, "/example-schema:obsoleteLeaf"},
1007 {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"},
1008 {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"},
1009 {boost::none, "/example-schema:pizzaIdentLeaf"},
1010 {boost::none, "/example-schema:pizzaSize"},
1011 {boost::none, "/example-schema:portMapping"},
1012 {boost::none, "/example-schema:portMapping/port"},
1013 {boost::none, "/example-schema:portSettings"},
1014 {boost::none, "/example-schema:portSettings/port"},
1015 {boost::none, "/example-schema:systemStats"},
1016 {boost::none, "/example-schema:systemStats/upTime"},
Václav Kubernát82d74632020-05-11 15:59:53 +02001017 {boost::none, "/example-schema:subLeaf"},
Václav Kubernát95b08872020-04-28 01:04:17 +02001018 {boost::none, "/example-schema:twoKeyList"},
1019 {boost::none, "/example-schema:twoKeyList/name"},
1020 {boost::none, "/example-schema:twoKeyList/number"},
1021 {boost::none, "/example-schema:wavelength"},
1022 {boost::none, "/example-schema:zero"}
Václav Kubernát3a823f42020-04-29 23:40:21 +02001023 };
1024 }
Václav Kubernát3a823f42020-04-29 23:40:21 +02001025 SECTION("second-schema")
1026 {
1027 module = "second-schema";
1028 expectedNonRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +02001029 {"second-schema"s, "bla"}
Václav Kubernát3a823f42020-04-29 23:40:21 +02001030 };
1031 expectedRecursive = {
Václav Kubernát95b08872020-04-28 01:04:17 +02001032 {boost::none, "/second-schema:bla"},
1033 {boost::none, "/second-schema:bla/bla2"}
Václav Kubernát3a823f42020-04-29 23:40:21 +02001034 };
1035 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001036
Václav Kubernát3a823f42020-04-29 23:40:21 +02001037 REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive);
1038 REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive);
Václav Kubernát47a3f672019-11-08 15:42:43 +01001039 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001040 }
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001041 SECTION("nodeType")
1042 {
1043 yang::NodeTypes expected;
1044 SECTION("leafInt32")
1045 {
1046 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
1047 expected = yang::NodeTypes::Leaf;
1048 }
1049
1050 SECTION("a")
1051 {
1052 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1053 expected = yang::NodeTypes::Container;
1054 }
1055
1056 SECTION("a/a2/a3")
1057 {
1058 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1059 path.m_nodes.push_back(schemaNode_(container_("a2")));
1060 path.m_nodes.push_back(schemaNode_(container_("a3")));
1061 expected = yang::NodeTypes::PresenceContainer;
1062 }
1063
1064 SECTION("_list")
1065 {
1066 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, list_("_list")));
1067 expected = yang::NodeTypes::List;
1068 }
1069
Václav Kubernát82d74632020-05-11 15:59:53 +02001070 SECTION("subLeaf")
1071 {
1072 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("subLeaf")));
1073 expected = yang::NodeTypes::Leaf;
1074 }
1075
Václav Kubernát34ee85a2020-02-18 17:12:12 +01001076 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1077 }
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001078
1079 SECTION("description")
1080 {
1081 std::optional<std::string> expected;
1082 SECTION("leafInt32")
1083 {
1084 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
1085 expected = "A 32-bit integer leaf.";
1086 }
1087
1088 SECTION("leafString")
1089 {
1090 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafString")));
1091 }
1092
Václav Kubernát2984f442020-02-20 17:43:35 +01001093 SECTION("numberOrString")
1094 {
1095 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("numberOrString")));
1096 expected = "Can be an int32 or a string.";
1097 }
1098
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001099 REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1100 }
1101
Václav Kubernáta1c4c9e2020-04-22 00:37:52 +02001102 SECTION("status")
1103 {
1104 REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current);
1105 REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete);
1106 REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated);
1107 REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete);
1108 REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete);
1109 }
1110
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001111 SECTION("units")
1112 {
Václav Kubernát13b23d72020-04-16 21:49:51 +02001113 yang::LeafDataType expectedType;
1114 std::optional<std::string> expectedUnits;
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001115 SECTION("length")
1116 {
1117 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("length")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001118 expectedType.emplace<yang::Int32>();
1119 expectedUnits = "m";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001120 }
1121
1122 SECTION("wavelength")
1123 {
1124 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("wavelength")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001125 expectedType.emplace<yang::Decimal>();
1126 expectedUnits = "nm";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001127 }
1128
1129 SECTION("leafInt32")
1130 {
1131 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001132 expectedType.emplace<yang::Int32>();
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001133 }
1134
1135 SECTION("duration")
1136 {
1137 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("duration")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001138 expectedType.emplace<yang::Int32>();
1139 expectedUnits = "s";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001140 }
1141
1142 SECTION("another-duration")
1143 {
1144 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("another-duration")));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001145 expectedType.emplace<yang::Int32>();
1146 expectedUnits = "vt";
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001147 }
Václav Kubernát5b8a8f32020-05-20 00:57:22 +02001148 auto nodeType = ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded));
1149 REQUIRE((nodeType == yang::NodeTypes::Leaf || nodeType == yang::NodeTypes::LeafList));
Václav Kubernát13b23d72020-04-16 21:49:51 +02001150 REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits});
Václav Kubernát1e09bd62020-02-17 15:13:38 +01001151 }
1152
1153 SECTION("nodeType")
1154 {
1155 yang::NodeTypes expected;
1156 SECTION("leafInt32")
1157 {
1158 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32")));
1159 expected = yang::NodeTypes::Leaf;
1160 }
1161
1162 SECTION("a")
1163 {
1164 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1165 expected = yang::NodeTypes::Container;
1166 }
1167
1168 SECTION("a/a2/a3")
1169 {
1170 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
1171 path.m_nodes.push_back(schemaNode_(container_("a2")));
1172 path.m_nodes.push_back(schemaNode_(container_("a3")));
1173 expected = yang::NodeTypes::PresenceContainer;
1174 }
1175
1176 SECTION("_list")
1177 {
1178 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, list_("_list")));
1179 expected = yang::NodeTypes::List;
1180 }
1181
1182 REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected);
1183 }
Václav Kubernátbd5e3c22020-02-19 15:22:00 +01001184
1185 SECTION("leafrefPath")
1186 {
1187 REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number");
1188 }
Václav Kubernát0599e9f2020-04-21 09:51:33 +02001189
1190 SECTION("isConfig")
1191 {
1192 REQUIRE(ys.isConfig("/example-schema:leafInt32"));
1193 REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed"));
1194 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats"));
1195 REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime"));
1196 }
Václav Kubernátbd0d5c82020-04-21 10:22:03 +02001197
Václav Kubernátb1a75c62020-04-21 15:20:16 +02001198 SECTION("defaultValue")
1199 {
1200 REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001");
1201 REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data");
1202 REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt);
1203 }
1204
Václav Kubernát76ba4ec2020-05-18 13:26:56 +02001205 SECTION("leafTypeName")
1206 {
1207 REQUIRE(ys.leafTypeName("/example-schema:leafEnumTypedefRestricted") == "enumTypedef");
1208 REQUIRE(ys.leafTypeName("/example-schema:leafInt32") == std::nullopt);
1209 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001210 }
1211
1212 SECTION("negative")
1213 {
1214 SECTION("nonexistent nodes")
1215 {
1216 SECTION("example-schema:coze")
1217 {
1218 node.first = "example-schema";
1219 node.second = "coze";
1220 }
1221
1222 SECTION("example-schema:a/nevim")
1223 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001224 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001225 node.second = "nevim";
1226 }
1227
1228 SECTION("modul:a/nevim")
1229 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001230 path.m_nodes.push_back(schemaNode_(module_{"modul"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001231 node.second = "nevim";
1232 }
1233
1234 REQUIRE(!ys.isPresenceContainer(path, node));
1235 REQUIRE(!ys.isList(path, node));
1236 REQUIRE(!ys.isLeaf(path, node));
1237 REQUIRE(!ys.isContainer(path, node));
1238 }
1239
1240 SECTION("\"is\" methods return false for existing nodes for different nodetypes")
1241 {
1242 SECTION("example-schema:a")
1243 {
1244 node.first = "example-schema";
1245 node.second = "a";
1246 }
1247
1248 SECTION("example-schema:a/a2")
1249 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001250 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001251 node.second = "a2";
1252 }
1253
1254 REQUIRE(!ys.isPresenceContainer(path, node));
1255 REQUIRE(!ys.isList(path, node));
1256 REQUIRE(!ys.isLeaf(path, node));
1257 }
1258
1259 SECTION("nodetype-specific methods called with different nodetypes")
1260 {
Václav Kubernát2eaceb82018-10-08 19:56:30 +02001261 path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
Václav Kubernát912b9492020-05-29 02:03:40 +02001262 path.m_nodes.push_back(schemaNode_(container_("a2")));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001263
Václav Kubernát912b9492020-05-29 02:03:40 +02001264 REQUIRE(!ys.listHasKey(path, "chacha"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001265 }
1266
1267 SECTION("nonexistent module")
1268 {
Václav Kubernát75877de2019-11-20 17:43:02 +01001269 REQUIRE(!ys.isModule("notAModule"));
Václav Kubernát0d4db442018-07-18 17:18:43 +02001270 }
Václav Kubernáteeb38842019-03-20 19:46:05 +01001271
Václav Kubernát7d82da72019-04-11 15:16:38 +02001272 SECTION("grouping is not a node")
1273 {
1274 SECTION("example-schema:arithmeticFlags")
1275 {
1276 node.first = "example-schema";
1277 node.second = "arithmeticFlags";
1278 }
1279
1280 SECTION("example-schema:flags")
1281 {
1282 node.first = "example-schema";
1283 node.second = "startAndStop";
1284 }
1285
1286 REQUIRE(!ys.isPresenceContainer(path, node));
1287 REQUIRE(!ys.isList(path, node));
1288 REQUIRE(!ys.isLeaf(path, node));
1289 REQUIRE(!ys.isContainer(path, node));
1290 }
Václav Kubernát280df4a2019-11-01 14:46:34 +01001291
1292 SECTION("choice is not a node")
1293 {
1294 SECTION("example-schema:interface")
1295 {
1296 node.first = "example-schema";
1297 node.second = "interface";
1298 }
1299
1300 REQUIRE(!ys.isPresenceContainer(path, node));
1301 REQUIRE(!ys.isList(path, node));
1302 REQUIRE(!ys.isLeaf(path, node));
1303 REQUIRE(!ys.isContainer(path, node));
1304 }
1305
1306 SECTION("case is not a node")
1307 {
1308 SECTION("example-schema:caseLoopback")
1309 {
1310 node.first = "example-schema";
1311 node.second = "caseLoopback";
1312 }
1313
1314 SECTION("example-schema:caseEthernet")
1315 {
1316 node.first = "example-schema";
1317 node.second = "caseEthernet";
1318 }
1319
1320 REQUIRE(!ys.isPresenceContainer(path, node));
1321 REQUIRE(!ys.isList(path, node));
1322 REQUIRE(!ys.isLeaf(path, node));
1323 REQUIRE(!ys.isContainer(path, node));
1324 }
Václav Kubernát0d4db442018-07-18 17:18:43 +02001325 }
1326}