Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1 | /* |
| 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át | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 9 | #include <experimental/iterator> |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 10 | #include "leaf_data_helpers.hpp" |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 11 | #include "pretty_printers.hpp" |
Václav Kubernát | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 12 | #include "trompeloeil_doctest.hpp" |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 13 | #include "yang_schema.hpp" |
| 14 | |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 15 | const char* second_schema = R"( |
| 16 | module second-schema { |
| 17 | namespace "http://example.com/nevim"; |
| 18 | prefix second; |
| 19 | |
| 20 | import example-schema { |
| 21 | prefix "example"; |
| 22 | } |
| 23 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 24 | identity pineapple { |
| 25 | base "example:fruit"; |
| 26 | } |
| 27 | |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 28 | augment /example:a { |
| 29 | container augmentedContainer { |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | container bla { |
| 34 | container bla2 { |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | )"; |
| 39 | |
| 40 | const char* example_schema = R"( |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 41 | module example-schema { |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 42 | yang-version 1.1; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 43 | namespace "http://example.com/example-sports"; |
| 44 | prefix coze; |
| 45 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 46 | identity drink { |
| 47 | } |
| 48 | |
| 49 | identity voda { |
| 50 | base "drink"; |
| 51 | } |
| 52 | |
| 53 | identity food { |
| 54 | } |
| 55 | |
| 56 | identity fruit { |
| 57 | base "food"; |
| 58 | } |
| 59 | |
| 60 | identity pizza { |
| 61 | base "food"; |
| 62 | } |
| 63 | |
| 64 | identity hawaii { |
| 65 | base "pizza"; |
| 66 | } |
| 67 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 68 | container a { |
| 69 | container a2 { |
| 70 | container a3 { |
| 71 | presence true; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | leaf leafa { |
| 76 | type string; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | container b { |
| 81 | container b2 { |
| 82 | presence true; |
| 83 | container b3 { |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | leaf leafString { |
| 89 | type string; |
| 90 | } |
| 91 | |
| 92 | leaf leafDecimal { |
| 93 | type decimal64 { |
| 94 | fraction-digits 5; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | leaf leafBool { |
| 99 | type boolean; |
| 100 | } |
| 101 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 102 | leaf leafInt8 { |
| 103 | type int8; |
| 104 | } |
| 105 | |
| 106 | leaf leafUint8 { |
| 107 | type uint8; |
| 108 | } |
| 109 | |
| 110 | leaf leafInt16 { |
| 111 | type int16; |
| 112 | } |
| 113 | |
| 114 | leaf leafUint16 { |
| 115 | type uint16; |
| 116 | } |
| 117 | |
| 118 | leaf leafInt32 { |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 119 | description "A 32-bit integer leaf."; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 120 | type int32; |
| 121 | } |
| 122 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 123 | leaf leafUint32 { |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 124 | type uint32; |
| 125 | } |
| 126 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 127 | leaf leafInt64 { |
| 128 | type int64; |
| 129 | } |
| 130 | |
| 131 | leaf leafUint64 { |
| 132 | type uint64; |
| 133 | } |
| 134 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 135 | leaf leafEnum { |
| 136 | type enumeration { |
| 137 | enum lol; |
| 138 | enum data; |
| 139 | enum coze; |
| 140 | } |
| 141 | } |
| 142 | |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 143 | typedef enumTypedef { |
| 144 | type enumeration { |
| 145 | enum lol; |
| 146 | enum data; |
| 147 | enum coze; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | typedef enumTypedefRestricted { |
| 152 | type enumTypedef { |
| 153 | enum lol; |
| 154 | enum data; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | leaf leafEnumTypedef { |
| 159 | type enumTypedef; |
| 160 | } |
| 161 | |
| 162 | leaf leafEnumTypedefRestricted { |
| 163 | type enumTypedef { |
| 164 | enum data; |
| 165 | enum coze; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | leaf leafEnumTypedefRestricted2 { |
| 170 | type enumTypedefRestricted; |
| 171 | } |
| 172 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 173 | leaf foodIdentLeaf { |
| 174 | type identityref { |
| 175 | base "food"; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | leaf pizzaIdentLeaf { |
| 180 | type identityref { |
| 181 | base "pizza"; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | leaf foodDrinkIdentLeaf { |
| 186 | type identityref { |
| 187 | base "food"; |
| 188 | base "drink"; |
| 189 | } |
| 190 | } |
| 191 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 192 | list _list { |
| 193 | key number; |
| 194 | |
| 195 | leaf number { |
| 196 | type int32; |
| 197 | } |
| 198 | |
| 199 | container contInList { |
| 200 | presence true; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | list twoKeyList { |
| 205 | key "name number"; |
| 206 | |
| 207 | leaf number { |
| 208 | type int32; |
| 209 | } |
| 210 | |
| 211 | leaf name { |
| 212 | type string; |
| 213 | } |
| 214 | } |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 215 | |
| 216 | grouping arithmeticFlags { |
| 217 | leaf carry { |
| 218 | type boolean; |
| 219 | } |
| 220 | leaf zero { |
| 221 | type boolean; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | grouping flags { |
| 226 | leaf direction { |
| 227 | type boolean; |
| 228 | } |
| 229 | leaf interrupt { |
| 230 | type boolean; |
| 231 | } |
| 232 | |
| 233 | uses arithmeticFlags; |
| 234 | } |
| 235 | |
| 236 | uses flags; |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 237 | |
| 238 | choice interface { |
| 239 | case caseLoopback { |
| 240 | container loopback { |
| 241 | leaf ip { |
| 242 | type string; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | case caseEthernet { |
| 248 | container ethernet { |
| 249 | leaf ip { |
| 250 | type string; |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
Václav Kubernát | a38d417 | 2019-11-04 12:36:39 +0100 | [diff] [blame] | 256 | feature bigPizzas; |
| 257 | |
| 258 | leaf pizzaSize { |
| 259 | type enumeration { |
| 260 | enum large { |
| 261 | if-feature "bigPizzas"; |
| 262 | } |
| 263 | enum medium; |
| 264 | enum small; |
| 265 | } |
| 266 | } |
| 267 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 268 | leaf length { |
| 269 | type int32; |
| 270 | units "m"; |
| 271 | } |
| 272 | |
| 273 | leaf wavelength { |
| 274 | type decimal64 { |
| 275 | fraction-digits 10; |
| 276 | } |
| 277 | units "nm"; |
| 278 | } |
| 279 | |
| 280 | typedef seconds { |
| 281 | type int32; |
| 282 | units "s"; |
| 283 | } |
| 284 | |
| 285 | leaf duration { |
| 286 | type seconds; |
| 287 | } |
| 288 | |
| 289 | leaf another-duration { |
| 290 | type seconds; |
| 291 | units "vt"; |
| 292 | } |
| 293 | |
Václav Kubernát | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 294 | leaf activeNumber { |
| 295 | type leafref { |
| 296 | path "/_list/number"; |
| 297 | } |
| 298 | } |
| 299 | |
Václav Kubernát | fa81c8c | 2020-02-13 17:22:46 +0100 | [diff] [blame] | 300 | rpc myRpc {} |
| 301 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 302 | leaf numberOrString { |
| 303 | type union { |
| 304 | type int32; |
| 305 | type string; |
| 306 | } |
| 307 | description "Can be an int32 or a string."; |
| 308 | } |
| 309 | |
| 310 | list portSettings { |
| 311 | key "port"; |
| 312 | leaf port { |
| 313 | type enumeration { |
| 314 | enum eth0; |
| 315 | enum eth1; |
| 316 | enum eth2; |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | feature weirdPortNames; |
| 322 | |
| 323 | list portMapping { |
| 324 | key "port"; |
| 325 | leaf port { |
| 326 | type enumeration { |
| 327 | enum WEIRD { |
| 328 | if-feature "weirdPortNames"; |
| 329 | } |
| 330 | enum utf2; |
| 331 | enum utf3; |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | leaf activeMappedPort { |
| 337 | type leafref { |
| 338 | path "../portMapping/port"; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | leaf activePort { |
| 343 | type union { |
| 344 | type enumeration { |
| 345 | enum wlan0; |
| 346 | enum wlan1; |
| 347 | } |
| 348 | type leafref { |
| 349 | path "../portSettings/port"; |
| 350 | } |
| 351 | type leafref { |
| 352 | path "../activeMappedPort"; |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame^] | 357 | leaf clockSpeed { |
| 358 | type int64; |
| 359 | config false; |
| 360 | } |
| 361 | |
| 362 | container systemStats { |
| 363 | config false; |
| 364 | leaf upTime { |
| 365 | type uint64; |
| 366 | } |
| 367 | } |
| 368 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 369 | })"; |
| 370 | |
Václav Kubernát | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 371 | namespace std { |
| 372 | std::ostream& operator<<(std::ostream& s, const std::set<std::string> set) |
| 373 | { |
| 374 | s << std::endl << "{"; |
| 375 | std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", ")); |
| 376 | s << "}" << std::endl; |
| 377 | return s; |
| 378 | } |
| 379 | } |
| 380 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 381 | TEST_CASE("yangschema") |
| 382 | { |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 383 | using namespace std::string_view_literals; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 384 | YangSchema ys; |
Václav Kubernát | b52dc25 | 2019-12-04 13:03:39 +0100 | [diff] [blame] | 385 | ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto, auto) { |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 386 | assert("example-schema"sv == modName); |
| 387 | return example_schema; |
| 388 | }); |
| 389 | ys.addSchemaString(second_schema); |
| 390 | |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 391 | schemaPath_ path{Scope::Absolute, {}}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 392 | ModuleNodePair node; |
| 393 | |
| 394 | SECTION("positive") |
| 395 | { |
| 396 | SECTION("isContainer") |
| 397 | { |
| 398 | SECTION("example-schema:a") |
| 399 | { |
| 400 | node.first = "example-schema"; |
| 401 | node.second = "a"; |
| 402 | } |
| 403 | |
| 404 | SECTION("example-schema:a/a2") |
| 405 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 406 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 407 | node.second = "a2"; |
| 408 | } |
| 409 | |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 410 | SECTION("example-schema:ethernet") |
| 411 | { |
| 412 | node.first = "example-schema"; |
| 413 | node.second = "ethernet"; |
| 414 | } |
| 415 | |
| 416 | SECTION("example-schema:loopback") |
| 417 | { |
| 418 | node.first = "example-schema"; |
| 419 | node.second = "loopback"; |
| 420 | } |
| 421 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 422 | REQUIRE(ys.isContainer(path, node)); |
| 423 | } |
| 424 | SECTION("isLeaf") |
| 425 | { |
| 426 | SECTION("example-schema:leafString") |
| 427 | { |
| 428 | node.first = "example-schema"; |
| 429 | node.second = "leafString"; |
| 430 | } |
| 431 | |
| 432 | SECTION("example-schema:a/leafa") |
| 433 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 434 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 435 | node.first = "example-schema"; |
| 436 | node.second = "leafa"; |
| 437 | } |
| 438 | |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 439 | SECTION("example-schema:carry") |
| 440 | { |
| 441 | node.first = "example-schema"; |
| 442 | node.second = "carry"; |
| 443 | } |
| 444 | |
| 445 | SECTION("example-schema:zero") |
| 446 | { |
| 447 | node.first = "example-schema"; |
| 448 | node.second = "zero"; |
| 449 | } |
| 450 | |
| 451 | SECTION("example-schema:direction") |
| 452 | { |
| 453 | node.first = "example-schema"; |
| 454 | node.second = "direction"; |
| 455 | } |
| 456 | |
| 457 | SECTION("example-schema:interrupt") |
| 458 | { |
| 459 | node.first = "example-schema"; |
| 460 | node.second = "interrupt"; |
| 461 | } |
| 462 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 463 | REQUIRE(ys.isLeaf(path, node)); |
| 464 | } |
| 465 | SECTION("isModule") |
| 466 | { |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 467 | REQUIRE(ys.isModule("example-schema")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 468 | } |
| 469 | SECTION("isList") |
| 470 | { |
| 471 | SECTION("example-schema:_list") |
| 472 | { |
| 473 | node.first = "example-schema"; |
| 474 | node.second = "_list"; |
| 475 | } |
| 476 | |
| 477 | SECTION("example-schema:twoKeyList") |
| 478 | { |
| 479 | node.first = "example-schema"; |
| 480 | node.second = "twoKeyList"; |
| 481 | } |
| 482 | |
| 483 | REQUIRE(ys.isList(path, node)); |
| 484 | } |
| 485 | SECTION("isPresenceContainer") |
| 486 | { |
| 487 | SECTION("example-schema:a/a2/a3") |
| 488 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 489 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
| 490 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a2"))); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 491 | node.second = "a3"; |
| 492 | } |
| 493 | |
| 494 | REQUIRE(ys.isPresenceContainer(path, node)); |
| 495 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 496 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 497 | SECTION("listHasKey") |
| 498 | { |
| 499 | std::string key; |
| 500 | |
| 501 | SECTION("_list") |
| 502 | { |
| 503 | node.first = "example-schema"; |
| 504 | node.second = "_list"; |
| 505 | SECTION("number") |
| 506 | key = "number"; |
| 507 | } |
| 508 | |
| 509 | SECTION("twoKeyList") |
| 510 | { |
| 511 | node.first = "example-schema"; |
| 512 | node.second = "twoKeyList"; |
| 513 | SECTION("number") |
| 514 | key = "number"; |
| 515 | SECTION("name") |
| 516 | key = "name"; |
| 517 | } |
| 518 | |
| 519 | REQUIRE(ys.listHasKey(path, node, key)); |
| 520 | } |
| 521 | SECTION("listKeys") |
| 522 | { |
| 523 | std::set<std::string> set; |
| 524 | |
| 525 | SECTION("_list") |
| 526 | { |
| 527 | set = {"number"}; |
| 528 | node.first = "example-schema"; |
| 529 | node.second = "_list"; |
| 530 | } |
| 531 | |
| 532 | SECTION("twoKeyList") |
| 533 | { |
| 534 | set = {"number", "name"}; |
| 535 | node.first = "example-schema"; |
| 536 | node.second = "twoKeyList"; |
| 537 | } |
| 538 | |
| 539 | REQUIRE(ys.listKeys(path, node) == set); |
| 540 | } |
| 541 | SECTION("leafType") |
| 542 | { |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 543 | yang::LeafDataType type; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 544 | |
| 545 | SECTION("leafString") |
| 546 | { |
| 547 | node.first = "example-schema"; |
| 548 | node.second = "leafString"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 549 | type = yang::String{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | SECTION("leafDecimal") |
| 553 | { |
| 554 | node.first = "example-schema"; |
| 555 | node.second = "leafDecimal"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 556 | type = yang::Decimal{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | SECTION("leafBool") |
| 560 | { |
| 561 | node.first = "example-schema"; |
| 562 | node.second = "leafBool"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 563 | type = yang::Bool{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 564 | } |
| 565 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 566 | SECTION("leafInt8") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 567 | { |
| 568 | node.first = "example-schema"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 569 | node.second = "leafInt8"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 570 | type = yang::Int8{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 571 | } |
| 572 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 573 | SECTION("leafUint8") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 574 | { |
| 575 | node.first = "example-schema"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 576 | node.second = "leafUint8"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 577 | type = yang::Uint8{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 578 | } |
| 579 | |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 580 | SECTION("leafInt16") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 581 | { |
| 582 | node.first = "example-schema"; |
| 583 | node.second = "leafInt16"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 584 | type = yang::Int16{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | SECTION("leafUint16") |
| 588 | { |
| 589 | node.first = "example-schema"; |
| 590 | node.second = "leafUint16"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 591 | type = yang::Uint16{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | SECTION("leafInt32") |
| 595 | { |
| 596 | node.first = "example-schema"; |
| 597 | node.second = "leafInt32"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 598 | type = yang::Int32{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | SECTION("leafUint32") |
| 602 | { |
| 603 | node.first = "example-schema"; |
| 604 | node.second = "leafUint32"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 605 | type = yang::Uint32{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | SECTION("leafInt64") |
| 609 | { |
| 610 | node.first = "example-schema"; |
| 611 | node.second = "leafInt64"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 612 | type = yang::Int64{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | SECTION("leafUint64") |
| 616 | { |
| 617 | node.first = "example-schema"; |
| 618 | node.second = "leafUint64"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 619 | type = yang::Uint64{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | SECTION("leafEnum") |
| 623 | { |
| 624 | node.first = "example-schema"; |
| 625 | node.second = "leafEnum"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 626 | type = createEnum({"lol", "data", "coze"}); |
| 627 | } |
| 628 | |
| 629 | SECTION("leafEnumTypedef") |
| 630 | { |
| 631 | node.first = "example-schema"; |
| 632 | node.second = "leafEnumTypedef"; |
| 633 | type = createEnum({"lol", "data", "coze"}); |
| 634 | } |
| 635 | |
| 636 | SECTION("leafEnumTypedefRestricted") |
| 637 | { |
| 638 | node.first = "example-schema"; |
| 639 | node.second = "leafEnumTypedefRestricted"; |
| 640 | type = createEnum({"data", "coze"}); |
| 641 | } |
| 642 | |
| 643 | SECTION("leafEnumTypedefRestricted2") |
| 644 | { |
| 645 | node.first = "example-schema"; |
| 646 | node.second = "leafEnumTypedefRestricted2"; |
| 647 | type = createEnum({"lol", "data"}); |
| 648 | } |
| 649 | |
| 650 | SECTION("pizzaSize") |
| 651 | { |
| 652 | node.first = "example-schema"; |
| 653 | node.second = "pizzaSize"; |
| 654 | |
| 655 | SECTION("bigPizzas disabled") |
| 656 | { |
| 657 | type = createEnum({"small", "medium"}); |
| 658 | } |
| 659 | SECTION("bigPizzas enabled") |
| 660 | { |
| 661 | ys.enableFeature("example-schema", "bigPizzas"); |
| 662 | type = createEnum({"small", "medium", "large"}); |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | SECTION("foodIdentLeaf") |
| 667 | { |
| 668 | node.first = "example-schema"; |
| 669 | node.second = "foodIdentLeaf"; |
| 670 | type = yang::IdentityRef{{{"second-schema", "pineapple"}, |
| 671 | {"example-schema", "food"}, |
| 672 | {"example-schema", "pizza"}, |
| 673 | {"example-schema", "hawaii"}, |
| 674 | {"example-schema", "fruit"}}}; |
| 675 | } |
| 676 | |
| 677 | SECTION("pizzaIdentLeaf") |
| 678 | { |
| 679 | node.first = "example-schema"; |
| 680 | node.second = "pizzaIdentLeaf"; |
| 681 | |
| 682 | type = yang::IdentityRef{{ |
| 683 | {"example-schema", "pizza"}, |
| 684 | {"example-schema", "hawaii"}, |
| 685 | }}; |
| 686 | } |
| 687 | |
| 688 | SECTION("foodDrinkIdentLeaf") |
| 689 | { |
| 690 | node.first = "example-schema"; |
| 691 | node.second = "foodDrinkIdentLeaf"; |
| 692 | |
| 693 | type = yang::IdentityRef{{ |
| 694 | {"example-schema", "food"}, |
| 695 | {"example-schema", "drink"}, |
| 696 | {"example-schema", "fruit"}, |
| 697 | {"example-schema", "hawaii"}, |
| 698 | {"example-schema", "pizza"}, |
| 699 | {"example-schema", "voda"}, |
| 700 | {"second-schema", "pineapple"}, |
| 701 | }}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 702 | } |
| 703 | |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 704 | SECTION("activeNumber") |
| 705 | { |
| 706 | node.first = "example-schema"; |
| 707 | node.second = "activeNumber"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 708 | type.emplace<yang::LeafRef>( |
| 709 | "/example-schema:_list/number", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 710 | std::make_unique<yang::TypeInfo>(ys.leafType("/example-schema:_list/number")) |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 711 | ); |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 712 | } |
| 713 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 714 | SECTION("activePort") |
| 715 | { |
| 716 | node.first = "example-schema"; |
| 717 | node.second = "activePort"; |
| 718 | |
| 719 | yang::Enum enums = [&ys]() { |
| 720 | SECTION("weird ports disabled") |
| 721 | { |
| 722 | return createEnum({"utf2", "utf3"}); |
| 723 | } |
| 724 | SECTION("weird ports enabled") |
| 725 | { |
| 726 | ys.enableFeature("example-schema", "weirdPortNames"); |
| 727 | return createEnum({"WEIRD", "utf2", "utf3"}); |
| 728 | } |
| 729 | __builtin_unreachable(); |
| 730 | }(); |
| 731 | |
| 732 | type = yang::Union{{ |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 733 | yang::TypeInfo{createEnum({"wlan0", "wlan1"})}, |
| 734 | yang::TypeInfo{yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 735 | "/example-schema:portSettings/port", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 736 | std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"})) |
| 737 | }}, |
| 738 | yang::TypeInfo{yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 739 | "/example-schema:activeMappedPort", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 740 | std::make_unique<yang::TypeInfo>(yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 741 | "/example-schema:portMapping/port", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 742 | std::make_unique<yang::TypeInfo>(enums) |
| 743 | }) |
| 744 | }}, |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 745 | }}; |
| 746 | } |
| 747 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 748 | REQUIRE(ys.leafType(path, node) == type); |
| 749 | } |
| 750 | SECTION("childNodes") |
| 751 | { |
| 752 | std::set<std::string> set; |
| 753 | |
| 754 | SECTION("<root>") |
| 755 | { |
| 756 | set = {"example-schema:a", "example-schema:b", "example-schema:leafString", |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 757 | "example-schema:leafDecimal", "example-schema:leafBool", |
| 758 | "example-schema:leafInt8", "example-schema:leafUint8", |
| 759 | "example-schema:leafInt16", "example-schema:leafUint16", |
| 760 | "example-schema:leafInt32", "example-schema:leafUint32", |
| 761 | "example-schema:leafInt64", "example-schema:leafUint64", |
| 762 | "example-schema:leafEnum", "example-schema:leafEnumTypedef", |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 763 | "example-schema:leafEnumTypedefRestricted", "example-schema:leafEnumTypedefRestricted2", |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 764 | "example-schema:foodIdentLeaf", "example-schema:pizzaIdentLeaf", "example-schema:foodDrinkIdentLeaf", |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 765 | "example-schema:_list", "example-schema:twoKeyList", "second-schema:bla", |
| 766 | "example-schema:carry", "example-schema:zero", "example-schema:direction", |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 767 | "example-schema:interrupt", |
Václav Kubernát | a38d417 | 2019-11-04 12:36:39 +0100 | [diff] [blame] | 768 | "example-schema:ethernet", "example-schema:loopback", |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 769 | "example-schema:pizzaSize", |
| 770 | "example-schema:length", "example-schema:wavelength", |
Václav Kubernát | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 771 | "example-schema:duration", "example-schema:another-duration", |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 772 | "example-schema:activeNumber", |
| 773 | "example-schema:numberOrString", |
| 774 | "example-schema:portSettings", |
| 775 | "example-schema:portMapping", |
| 776 | "example-schema:activeMappedPort", |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame^] | 777 | "example-schema:activePort", |
| 778 | "example-schema:clockSpeed", |
| 779 | "example-schema:systemStats"}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 780 | } |
| 781 | |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 782 | SECTION("example-schema:a") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 783 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 784 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 785 | set = {"a2", "leafa", "second-schema:augmentedContainer"}; |
| 786 | } |
| 787 | |
| 788 | SECTION("second-schema:bla") |
| 789 | { |
| 790 | path.m_nodes.push_back(schemaNode_(module_{"second-schema"}, container_("bla"))); |
| 791 | set = {"bla2"}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 792 | } |
| 793 | |
Václav Kubernát | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 794 | SECTION("example-schema:ethernet") |
| 795 | { |
| 796 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("ethernet"))); |
| 797 | set = {"ip"}; |
| 798 | } |
| 799 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 800 | REQUIRE(ys.childNodes(path, Recursion::NonRecursive) == set); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 801 | } |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 802 | SECTION("nodeType") |
| 803 | { |
| 804 | yang::NodeTypes expected; |
| 805 | SECTION("leafInt32") |
| 806 | { |
| 807 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32"))); |
| 808 | expected = yang::NodeTypes::Leaf; |
| 809 | } |
| 810 | |
| 811 | SECTION("a") |
| 812 | { |
| 813 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
| 814 | expected = yang::NodeTypes::Container; |
| 815 | } |
| 816 | |
| 817 | SECTION("a/a2/a3") |
| 818 | { |
| 819 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
| 820 | path.m_nodes.push_back(schemaNode_(container_("a2"))); |
| 821 | path.m_nodes.push_back(schemaNode_(container_("a3"))); |
| 822 | expected = yang::NodeTypes::PresenceContainer; |
| 823 | } |
| 824 | |
| 825 | SECTION("_list") |
| 826 | { |
| 827 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, list_("_list"))); |
| 828 | expected = yang::NodeTypes::List; |
| 829 | } |
| 830 | |
| 831 | REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 832 | } |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 833 | |
| 834 | SECTION("description") |
| 835 | { |
| 836 | std::optional<std::string> expected; |
| 837 | SECTION("leafInt32") |
| 838 | { |
| 839 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32"))); |
| 840 | expected = "A 32-bit integer leaf."; |
| 841 | } |
| 842 | |
| 843 | SECTION("leafString") |
| 844 | { |
| 845 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafString"))); |
| 846 | } |
| 847 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 848 | SECTION("numberOrString") |
| 849 | { |
| 850 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("numberOrString"))); |
| 851 | expected = "Can be an int32 or a string."; |
| 852 | } |
| 853 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 854 | REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 855 | } |
| 856 | |
| 857 | SECTION("units") |
| 858 | { |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 859 | yang::LeafDataType expectedType; |
| 860 | std::optional<std::string> expectedUnits; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 861 | SECTION("length") |
| 862 | { |
| 863 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("length"))); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 864 | expectedType.emplace<yang::Int32>(); |
| 865 | expectedUnits = "m"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | SECTION("wavelength") |
| 869 | { |
| 870 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("wavelength"))); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 871 | expectedType.emplace<yang::Decimal>(); |
| 872 | expectedUnits = "nm"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | SECTION("leafInt32") |
| 876 | { |
| 877 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32"))); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 878 | expectedType.emplace<yang::Int32>(); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | SECTION("duration") |
| 882 | { |
| 883 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("duration"))); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 884 | expectedType.emplace<yang::Int32>(); |
| 885 | expectedUnits = "s"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | SECTION("another-duration") |
| 889 | { |
| 890 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("another-duration"))); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 891 | expectedType.emplace<yang::Int32>(); |
| 892 | expectedUnits = "vt"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 893 | } |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 894 | REQUIRE(ys.leafType(pathToSchemaString(path, Prefixes::WhenNeeded)) == yang::TypeInfo{expectedType, expectedUnits}); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | SECTION("nodeType") |
| 898 | { |
| 899 | yang::NodeTypes expected; |
| 900 | SECTION("leafInt32") |
| 901 | { |
| 902 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, leaf_("leafInt32"))); |
| 903 | expected = yang::NodeTypes::Leaf; |
| 904 | } |
| 905 | |
| 906 | SECTION("a") |
| 907 | { |
| 908 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
| 909 | expected = yang::NodeTypes::Container; |
| 910 | } |
| 911 | |
| 912 | SECTION("a/a2/a3") |
| 913 | { |
| 914 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
| 915 | path.m_nodes.push_back(schemaNode_(container_("a2"))); |
| 916 | path.m_nodes.push_back(schemaNode_(container_("a3"))); |
| 917 | expected = yang::NodeTypes::PresenceContainer; |
| 918 | } |
| 919 | |
| 920 | SECTION("_list") |
| 921 | { |
| 922 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, list_("_list"))); |
| 923 | expected = yang::NodeTypes::List; |
| 924 | } |
| 925 | |
| 926 | REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 927 | } |
Václav Kubernát | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 928 | |
| 929 | SECTION("leafrefPath") |
| 930 | { |
| 931 | REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number"); |
| 932 | } |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame^] | 933 | |
| 934 | SECTION("isConfig") |
| 935 | { |
| 936 | REQUIRE(ys.isConfig("/example-schema:leafInt32")); |
| 937 | REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed")); |
| 938 | REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats")); |
| 939 | REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime")); |
| 940 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | SECTION("negative") |
| 944 | { |
| 945 | SECTION("nonexistent nodes") |
| 946 | { |
| 947 | SECTION("example-schema:coze") |
| 948 | { |
| 949 | node.first = "example-schema"; |
| 950 | node.second = "coze"; |
| 951 | } |
| 952 | |
| 953 | SECTION("example-schema:a/nevim") |
| 954 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 955 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 956 | node.second = "nevim"; |
| 957 | } |
| 958 | |
| 959 | SECTION("modul:a/nevim") |
| 960 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 961 | path.m_nodes.push_back(schemaNode_(module_{"modul"}, container_("a"))); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 962 | node.second = "nevim"; |
| 963 | } |
| 964 | |
| 965 | REQUIRE(!ys.isPresenceContainer(path, node)); |
| 966 | REQUIRE(!ys.isList(path, node)); |
| 967 | REQUIRE(!ys.isLeaf(path, node)); |
| 968 | REQUIRE(!ys.isContainer(path, node)); |
| 969 | } |
| 970 | |
| 971 | SECTION("\"is\" methods return false for existing nodes for different nodetypes") |
| 972 | { |
| 973 | SECTION("example-schema:a") |
| 974 | { |
| 975 | node.first = "example-schema"; |
| 976 | node.second = "a"; |
| 977 | } |
| 978 | |
| 979 | SECTION("example-schema:a/a2") |
| 980 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 981 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 982 | node.second = "a2"; |
| 983 | } |
| 984 | |
| 985 | REQUIRE(!ys.isPresenceContainer(path, node)); |
| 986 | REQUIRE(!ys.isList(path, node)); |
| 987 | REQUIRE(!ys.isLeaf(path, node)); |
| 988 | } |
| 989 | |
| 990 | SECTION("nodetype-specific methods called with different nodetypes") |
| 991 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 992 | path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a"))); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 993 | node.second = "a2"; |
| 994 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 995 | REQUIRE(!ys.listHasKey(path, node, "chacha")); |
| 996 | } |
| 997 | |
| 998 | SECTION("nonexistent module") |
| 999 | { |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 1000 | REQUIRE(!ys.isModule("notAModule")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1001 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 1002 | |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 1003 | SECTION("grouping is not a node") |
| 1004 | { |
| 1005 | SECTION("example-schema:arithmeticFlags") |
| 1006 | { |
| 1007 | node.first = "example-schema"; |
| 1008 | node.second = "arithmeticFlags"; |
| 1009 | } |
| 1010 | |
| 1011 | SECTION("example-schema:flags") |
| 1012 | { |
| 1013 | node.first = "example-schema"; |
| 1014 | node.second = "startAndStop"; |
| 1015 | } |
| 1016 | |
| 1017 | REQUIRE(!ys.isPresenceContainer(path, node)); |
| 1018 | REQUIRE(!ys.isList(path, node)); |
| 1019 | REQUIRE(!ys.isLeaf(path, node)); |
| 1020 | REQUIRE(!ys.isContainer(path, node)); |
| 1021 | } |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 1022 | |
| 1023 | SECTION("choice is not a node") |
| 1024 | { |
| 1025 | SECTION("example-schema:interface") |
| 1026 | { |
| 1027 | node.first = "example-schema"; |
| 1028 | node.second = "interface"; |
| 1029 | } |
| 1030 | |
| 1031 | REQUIRE(!ys.isPresenceContainer(path, node)); |
| 1032 | REQUIRE(!ys.isList(path, node)); |
| 1033 | REQUIRE(!ys.isLeaf(path, node)); |
| 1034 | REQUIRE(!ys.isContainer(path, node)); |
| 1035 | } |
| 1036 | |
| 1037 | SECTION("case is not a node") |
| 1038 | { |
| 1039 | SECTION("example-schema:caseLoopback") |
| 1040 | { |
| 1041 | node.first = "example-schema"; |
| 1042 | node.second = "caseLoopback"; |
| 1043 | } |
| 1044 | |
| 1045 | SECTION("example-schema:caseEthernet") |
| 1046 | { |
| 1047 | node.first = "example-schema"; |
| 1048 | node.second = "caseEthernet"; |
| 1049 | } |
| 1050 | |
| 1051 | REQUIRE(!ys.isPresenceContainer(path, node)); |
| 1052 | REQUIRE(!ys.isList(path, node)); |
| 1053 | REQUIRE(!ys.isLeaf(path, node)); |
| 1054 | REQUIRE(!ys.isContainer(path, node)); |
| 1055 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1056 | } |
| 1057 | } |