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 | |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 40 | const char* included_submodule = R"( |
| 41 | submodule 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át | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 54 | const char* example_schema = R"( |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 55 | module example-schema { |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 56 | yang-version 1.1; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 57 | namespace "http://example.com/example-sports"; |
| 58 | prefix coze; |
| 59 | |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 60 | include sub-module; |
| 61 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 62 | 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át | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 84 | 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á | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 118 | 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át | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 135 | description "A 32-bit integer leaf."; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 136 | type int32; |
| 137 | } |
| 138 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 139 | leaf leafUint32 { |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 140 | type uint32; |
| 141 | } |
| 142 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 143 | leaf leafInt64 { |
| 144 | type int64; |
| 145 | } |
| 146 | |
| 147 | leaf leafUint64 { |
| 148 | type uint64; |
Václav Kubernát | b1a75c6 | 2020-04-21 15:20:16 +0200 | [diff] [blame] | 149 | default 9001; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 152 | leaf leafEnum { |
| 153 | type enumeration { |
| 154 | enum lol; |
| 155 | enum data; |
| 156 | enum coze; |
| 157 | } |
| 158 | } |
| 159 | |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 160 | typedef enumTypedef { |
| 161 | type enumeration { |
| 162 | enum lol; |
| 163 | enum data; |
| 164 | enum coze; |
| 165 | } |
Václav Kubernát | b1a75c6 | 2020-04-21 15:20:16 +0200 | [diff] [blame] | 166 | default data; |
Václav Kubernát | 6a713d6 | 2018-10-03 18:47:34 +0200 | [diff] [blame] | 167 | } |
| 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át | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 191 | 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át | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 210 | 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át | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 233 | |
| 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át | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 255 | |
| 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át | a38d417 | 2019-11-04 12:36:39 +0100 | [diff] [blame] | 274 | 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át | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 286 | 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át | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 312 | leaf activeNumber { |
| 313 | type leafref { |
| 314 | path "/_list/number"; |
| 315 | } |
| 316 | } |
| 317 | |
Václav Kubernát | fa81c8c | 2020-02-13 17:22:46 +0100 | [diff] [blame] | 318 | rpc myRpc {} |
| 319 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 320 | 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 | } |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 337 | action shutdown { |
| 338 | output { |
| 339 | leaf success { |
| 340 | type boolean; |
| 341 | } |
| 342 | } |
| 343 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | feature weirdPortNames; |
| 347 | |
| 348 | list portMapping { |
| 349 | key "port"; |
| 350 | leaf port { |
| 351 | type enumeration { |
| 352 | enum WEIRD { |
| 353 | if-feature "weirdPortNames"; |
| 354 | } |
| 355 | enum utf2; |
| 356 | enum utf3; |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | leaf activeMappedPort { |
| 362 | type leafref { |
| 363 | path "../portMapping/port"; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | leaf activePort { |
| 368 | type union { |
| 369 | type enumeration { |
| 370 | enum wlan0; |
| 371 | enum wlan1; |
| 372 | } |
| 373 | type leafref { |
| 374 | path "../portSettings/port"; |
| 375 | } |
| 376 | type leafref { |
| 377 | path "../activeMappedPort"; |
| 378 | } |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 379 | type empty; |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 383 | leaf dummyLeaf { |
| 384 | type empty; |
| 385 | } |
| 386 | |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame] | 387 | leaf clockSpeed { |
| 388 | type int64; |
| 389 | config false; |
| 390 | } |
| 391 | |
| 392 | container systemStats { |
| 393 | config false; |
| 394 | leaf upTime { |
| 395 | type uint64; |
| 396 | } |
| 397 | } |
| 398 | |
Václav Kubernát | a1c4c9e | 2020-04-22 00:37:52 +0200 | [diff] [blame] | 399 | leaf obsoleteLeaf { |
| 400 | type int32; |
| 401 | status obsolete; |
| 402 | } |
| 403 | |
| 404 | leaf deprecatedLeaf { |
| 405 | type int32; |
| 406 | status deprecated; |
| 407 | } |
| 408 | |
| 409 | typedef deprecatedType { |
| 410 | type int32; |
| 411 | status deprecated; |
| 412 | } |
| 413 | |
| 414 | leaf obsoleteLeafWithDeprecatedType { |
| 415 | type deprecatedType; |
| 416 | status obsolete; |
| 417 | } |
| 418 | |
| 419 | typedef obsoleteType { |
| 420 | type int32; |
| 421 | status obsolete; |
| 422 | } |
| 423 | |
| 424 | leaf obsoleteLeafWithObsoleteType { |
| 425 | type deprecatedType; |
| 426 | status obsolete; |
| 427 | } |
| 428 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 429 | leaf-list addresses { |
| 430 | type string; |
| 431 | } |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame^] | 432 | |
| 433 | leaf flagBits { |
| 434 | type bits { |
| 435 | bit carry; |
| 436 | bit sign; |
| 437 | bit overflow; |
| 438 | } |
| 439 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 440 | })"; |
| 441 | |
| 442 | TEST_CASE("yangschema") |
| 443 | { |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 444 | using namespace std::string_literals; |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 445 | using namespace std::string_view_literals; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 446 | YangSchema ys; |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 447 | ys.registerModuleCallback([]([[maybe_unused]] auto modName, auto, auto subModule, auto) { |
| 448 | if (modName != "example-schema"sv) { |
| 449 | throw std::logic_error("unrecognized module "s + modName); |
| 450 | } |
| 451 | if (subModule == nullptr) { |
| 452 | return example_schema; |
| 453 | } |
| 454 | if (subModule == "sub-module"sv) { |
| 455 | return included_submodule; |
| 456 | } |
| 457 | |
| 458 | throw std::logic_error("unrecognized submodule "s + subModule); |
Václav Kubernát | 4f77a25 | 2019-02-19 16:51:30 +0100 | [diff] [blame] | 459 | }); |
| 460 | ys.addSchemaString(second_schema); |
| 461 | |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 462 | schemaPath_ path{Scope::Absolute, {}}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 463 | ModuleNodePair node; |
| 464 | |
| 465 | SECTION("positive") |
| 466 | { |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 467 | SECTION("isModule") |
| 468 | { |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 469 | REQUIRE(ys.isModule("example-schema")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 470 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 471 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 472 | SECTION("listHasKey") |
| 473 | { |
| 474 | std::string key; |
| 475 | |
| 476 | SECTION("_list") |
| 477 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 478 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 479 | SECTION("number") |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 480 | { |
| 481 | key = "number"; |
| 482 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | SECTION("twoKeyList") |
| 486 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 487 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 488 | SECTION("number") |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 489 | { |
| 490 | key = "number"; |
| 491 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 492 | SECTION("name") |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 493 | { |
| 494 | key = "name"; |
| 495 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 496 | } |
| 497 | |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 498 | REQUIRE(ys.listHasKey(path, key)); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 499 | } |
| 500 | SECTION("listKeys") |
| 501 | { |
| 502 | std::set<std::string> set; |
| 503 | |
| 504 | SECTION("_list") |
| 505 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 506 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"_list"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 507 | set = {"number"}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | SECTION("twoKeyList") |
| 511 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 512 | path.m_nodes.emplace_back(module_{"example-schema"}, list_{"twoKeyList"}); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 513 | set = {"number", "name"}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 516 | REQUIRE(ys.listKeys(path) == set); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 517 | } |
| 518 | SECTION("leafType") |
| 519 | { |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 520 | yang::LeafDataType type; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 521 | |
| 522 | SECTION("leafString") |
| 523 | { |
| 524 | node.first = "example-schema"; |
| 525 | node.second = "leafString"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 526 | type = yang::String{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | SECTION("leafDecimal") |
| 530 | { |
| 531 | node.first = "example-schema"; |
| 532 | node.second = "leafDecimal"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 533 | type = yang::Decimal{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | SECTION("leafBool") |
| 537 | { |
| 538 | node.first = "example-schema"; |
| 539 | node.second = "leafBool"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 540 | type = yang::Bool{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 541 | } |
| 542 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 543 | SECTION("leafInt8") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 544 | { |
| 545 | node.first = "example-schema"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 546 | node.second = "leafInt8"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 547 | type = yang::Int8{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 548 | } |
| 549 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 550 | SECTION("leafUint8") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 551 | { |
| 552 | node.first = "example-schema"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 553 | node.second = "leafUint8"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 554 | type = yang::Uint8{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 555 | } |
| 556 | |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 557 | SECTION("leafInt16") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 558 | { |
| 559 | node.first = "example-schema"; |
| 560 | node.second = "leafInt16"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 561 | type = yang::Int16{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | SECTION("leafUint16") |
| 565 | { |
| 566 | node.first = "example-schema"; |
| 567 | node.second = "leafUint16"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 568 | type = yang::Uint16{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | SECTION("leafInt32") |
| 572 | { |
| 573 | node.first = "example-schema"; |
| 574 | node.second = "leafInt32"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 575 | type = yang::Int32{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | SECTION("leafUint32") |
| 579 | { |
| 580 | node.first = "example-schema"; |
| 581 | node.second = "leafUint32"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 582 | type = yang::Uint32{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | SECTION("leafInt64") |
| 586 | { |
| 587 | node.first = "example-schema"; |
| 588 | node.second = "leafInt64"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 589 | type = yang::Int64{}; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | SECTION("leafUint64") |
| 593 | { |
| 594 | node.first = "example-schema"; |
| 595 | node.second = "leafUint64"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 596 | type = yang::Uint64{}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | SECTION("leafEnum") |
| 600 | { |
| 601 | node.first = "example-schema"; |
| 602 | node.second = "leafEnum"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 603 | type = createEnum({"lol", "data", "coze"}); |
| 604 | } |
| 605 | |
| 606 | SECTION("leafEnumTypedef") |
| 607 | { |
| 608 | node.first = "example-schema"; |
| 609 | node.second = "leafEnumTypedef"; |
| 610 | type = createEnum({"lol", "data", "coze"}); |
| 611 | } |
| 612 | |
| 613 | SECTION("leafEnumTypedefRestricted") |
| 614 | { |
| 615 | node.first = "example-schema"; |
| 616 | node.second = "leafEnumTypedefRestricted"; |
| 617 | type = createEnum({"data", "coze"}); |
| 618 | } |
| 619 | |
| 620 | SECTION("leafEnumTypedefRestricted2") |
| 621 | { |
| 622 | node.first = "example-schema"; |
| 623 | node.second = "leafEnumTypedefRestricted2"; |
| 624 | type = createEnum({"lol", "data"}); |
| 625 | } |
| 626 | |
| 627 | SECTION("pizzaSize") |
| 628 | { |
| 629 | node.first = "example-schema"; |
| 630 | node.second = "pizzaSize"; |
| 631 | |
| 632 | SECTION("bigPizzas disabled") |
| 633 | { |
| 634 | type = createEnum({"small", "medium"}); |
| 635 | } |
| 636 | SECTION("bigPizzas enabled") |
| 637 | { |
| 638 | ys.enableFeature("example-schema", "bigPizzas"); |
| 639 | type = createEnum({"small", "medium", "large"}); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | SECTION("foodIdentLeaf") |
| 644 | { |
| 645 | node.first = "example-schema"; |
| 646 | node.second = "foodIdentLeaf"; |
| 647 | type = yang::IdentityRef{{{"second-schema", "pineapple"}, |
| 648 | {"example-schema", "food"}, |
| 649 | {"example-schema", "pizza"}, |
| 650 | {"example-schema", "hawaii"}, |
| 651 | {"example-schema", "fruit"}}}; |
| 652 | } |
| 653 | |
| 654 | SECTION("pizzaIdentLeaf") |
| 655 | { |
| 656 | node.first = "example-schema"; |
| 657 | node.second = "pizzaIdentLeaf"; |
| 658 | |
| 659 | type = yang::IdentityRef{{ |
| 660 | {"example-schema", "pizza"}, |
| 661 | {"example-schema", "hawaii"}, |
| 662 | }}; |
| 663 | } |
| 664 | |
| 665 | SECTION("foodDrinkIdentLeaf") |
| 666 | { |
| 667 | node.first = "example-schema"; |
| 668 | node.second = "foodDrinkIdentLeaf"; |
| 669 | |
| 670 | type = yang::IdentityRef{{ |
| 671 | {"example-schema", "food"}, |
| 672 | {"example-schema", "drink"}, |
| 673 | {"example-schema", "fruit"}, |
| 674 | {"example-schema", "hawaii"}, |
| 675 | {"example-schema", "pizza"}, |
| 676 | {"example-schema", "voda"}, |
| 677 | {"second-schema", "pineapple"}, |
| 678 | }}; |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 679 | } |
| 680 | |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 681 | SECTION("activeNumber") |
| 682 | { |
| 683 | node.first = "example-schema"; |
| 684 | node.second = "activeNumber"; |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 685 | type.emplace<yang::LeafRef>( |
| 686 | "/example-schema:_list/number", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 687 | 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] | 688 | ); |
Václav Kubernát | b6d0275 | 2020-04-03 00:25:10 +0200 | [diff] [blame] | 689 | } |
| 690 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 691 | SECTION("activePort") |
| 692 | { |
| 693 | node.first = "example-schema"; |
| 694 | node.second = "activePort"; |
| 695 | |
Václav Kubernát | 1dc9e3e | 2020-06-09 15:22:39 +0200 | [diff] [blame] | 696 | yang::Enum enums({}); |
| 697 | SECTION("weird ports disabled") |
| 698 | { |
| 699 | enums = createEnum({"utf2", "utf3"}); |
| 700 | } |
| 701 | SECTION("weird ports enabled") |
| 702 | { |
| 703 | ys.enableFeature("example-schema", "weirdPortNames"); |
| 704 | enums = createEnum({"WEIRD", "utf2", "utf3"}); |
| 705 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 706 | |
| 707 | type = yang::Union{{ |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 708 | yang::TypeInfo{createEnum({"wlan0", "wlan1"})}, |
| 709 | yang::TypeInfo{yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 710 | "/example-schema:portSettings/port", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 711 | std::make_unique<yang::TypeInfo>(createEnum({"eth0", "eth1", "eth2"})) |
| 712 | }}, |
| 713 | yang::TypeInfo{yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 714 | "/example-schema:activeMappedPort", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 715 | std::make_unique<yang::TypeInfo>(yang::LeafRef{ |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 716 | "/example-schema:portMapping/port", |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 717 | std::make_unique<yang::TypeInfo>(enums) |
| 718 | }) |
| 719 | }}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 720 | yang::TypeInfo{yang::Empty{}}, |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 721 | }}; |
| 722 | } |
| 723 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 724 | SECTION("addresses") |
| 725 | { |
| 726 | node.first = "example-schema"; |
| 727 | node.second = "addresses"; |
| 728 | type.emplace<yang::String>(); |
| 729 | } |
| 730 | |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame^] | 731 | SECTION("flagBits") |
| 732 | { |
| 733 | node.first = "example-schema"; |
| 734 | node.second = "flagBits"; |
| 735 | type = yang::Bits{{"carry", "sign", "overflow"}}; |
| 736 | } |
| 737 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 738 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 739 | REQUIRE(ys.leafType(path, node) == type); |
| 740 | } |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 741 | SECTION("availableNodes") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 742 | { |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 743 | // TODO: merge "path" and "module" sections and add recursive versions to the path section |
| 744 | SECTION("paths") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 745 | { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 746 | std::set<ModuleNodePair> set; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 747 | |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 748 | using namespace std::string_literals; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 749 | SECTION("<root>") |
| 750 | { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 751 | set = {{"example-schema"s, "a"}, {"example-schema"s, "b"}, {"example-schema"s, "leafString"}, |
| 752 | {"example-schema"s, "leafDecimal"}, {"example-schema"s, "leafBool"}, |
| 753 | {"example-schema"s, "leafInt8"}, {"example-schema"s, "leafUint8"}, |
| 754 | {"example-schema"s, "leafInt16"}, {"example-schema"s, "leafUint16"}, |
| 755 | {"example-schema"s, "leafInt32"}, {"example-schema"s, "leafUint32"}, |
| 756 | {"example-schema"s, "leafInt64"}, {"example-schema"s, "leafUint64"}, |
| 757 | {"example-schema"s, "leafEnum"}, {"example-schema"s, "leafEnumTypedef"}, |
| 758 | {"example-schema"s, "leafEnumTypedefRestricted"}, {"example-schema"s, "leafEnumTypedefRestricted2"}, |
| 759 | {"example-schema"s, "foodIdentLeaf"}, {"example-schema"s, "pizzaIdentLeaf"}, {"example-schema"s, "foodDrinkIdentLeaf"}, |
| 760 | {"example-schema"s, "_list"}, {"example-schema"s, "twoKeyList"}, {"second-schema"s, "bla"}, |
| 761 | {"example-schema"s, "carry"}, {"example-schema"s, "zero"}, {"example-schema"s, "direction"}, |
| 762 | {"example-schema"s, "interrupt"}, |
| 763 | {"example-schema"s, "ethernet"}, {"example-schema"s, "loopback"}, |
| 764 | {"example-schema"s, "pizzaSize"}, |
| 765 | {"example-schema"s, "length"}, {"example-schema"s, "wavelength"}, |
| 766 | {"example-schema"s, "duration"}, {"example-schema"s, "another-duration"}, |
| 767 | {"example-schema"s, "activeNumber"}, |
| 768 | {"example-schema"s, "numberOrString"}, |
| 769 | {"example-schema"s, "portSettings"}, |
| 770 | {"example-schema"s, "portMapping"}, |
| 771 | {"example-schema"s, "activeMappedPort"}, |
| 772 | {"example-schema"s, "activePort"}, |
| 773 | {"example-schema"s, "clockSpeed"}, |
| 774 | {"example-schema"s, "deprecatedLeaf"}, |
| 775 | {"example-schema"s, "obsoleteLeaf"}, |
| 776 | {"example-schema"s, "obsoleteLeafWithDeprecatedType"}, |
| 777 | {"example-schema"s, "obsoleteLeafWithObsoleteType"}, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame] | 778 | {"example-schema"s, "myRpc"}, |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 779 | {"example-schema"s, "systemStats"}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 780 | {"example-schema"s, "dummyLeaf"}, |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 781 | {"example-schema"s, "addresses"}, |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame^] | 782 | {"example-schema"s, "subLeaf"}, |
| 783 | {"example-schema"s, "flagBits"}}; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | SECTION("example-schema:a") |
| 787 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 788 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 789 | set = { |
| 790 | {boost::none, "a2"}, |
| 791 | {boost::none, "leafa"}, |
| 792 | {"second-schema"s, "augmentedContainer"} |
| 793 | }; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | SECTION("example-schema:ethernet") |
| 797 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 798 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("ethernet")); |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 799 | set = {{boost::none, "ip"}}; |
| 800 | } |
| 801 | |
| 802 | SECTION("second-schema:bla") |
| 803 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 804 | path.m_nodes.emplace_back(module_{"second-schema"}, container_("bla")); |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 805 | set = {{boost::none, "bla2"}}; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | REQUIRE(ys.availableNodes(path, Recursion::NonRecursive) == set); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 809 | } |
| 810 | |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 811 | SECTION("modules") |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 812 | { |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 813 | std::string module; |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 814 | std::set<ModuleNodePair> expectedNonRecursive; |
| 815 | std::set<ModuleNodePair> expectedRecursive; |
| 816 | using namespace std::string_literals; |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 817 | SECTION("example-schema") |
| 818 | { |
| 819 | module = "example-schema"; |
| 820 | expectedNonRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 821 | {"example-schema"s, "_list"}, |
| 822 | {"example-schema"s, "a"}, |
| 823 | {"example-schema"s, "activeMappedPort"}, |
| 824 | {"example-schema"s, "activeNumber"}, |
| 825 | {"example-schema"s, "activePort"}, |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 826 | {"example-schema"s, "addresses"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 827 | {"example-schema"s, "another-duration"}, |
| 828 | {"example-schema"s, "b"}, |
| 829 | {"example-schema"s, "carry"}, |
| 830 | {"example-schema"s, "clockSpeed"}, |
| 831 | {"example-schema"s, "deprecatedLeaf"}, |
| 832 | {"example-schema"s, "direction"}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 833 | {"example-schema"s, "dummyLeaf"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 834 | {"example-schema"s, "duration"}, |
| 835 | {"example-schema"s, "ethernet"}, |
| 836 | {"example-schema"s, "foodDrinkIdentLeaf"}, |
| 837 | {"example-schema"s, "foodIdentLeaf"}, |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame^] | 838 | {"example-schema"s, "flagBits"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 839 | {"example-schema"s, "interrupt"}, |
| 840 | {"example-schema"s, "leafBool"}, |
| 841 | {"example-schema"s, "leafDecimal"}, |
| 842 | {"example-schema"s, "leafEnum"}, |
| 843 | {"example-schema"s, "leafEnumTypedef"}, |
| 844 | {"example-schema"s, "leafEnumTypedefRestricted"}, |
| 845 | {"example-schema"s, "leafEnumTypedefRestricted2"}, |
| 846 | {"example-schema"s, "leafInt16"}, |
| 847 | {"example-schema"s, "leafInt32"}, |
| 848 | {"example-schema"s, "leafInt64"}, |
| 849 | {"example-schema"s, "leafInt8"}, |
| 850 | {"example-schema"s, "leafString"}, |
| 851 | {"example-schema"s, "leafUint16"}, |
| 852 | {"example-schema"s, "leafUint32"}, |
| 853 | {"example-schema"s, "leafUint64"}, |
| 854 | {"example-schema"s, "leafUint8"}, |
| 855 | {"example-schema"s, "length"}, |
| 856 | {"example-schema"s, "loopback"}, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame] | 857 | {"example-schema"s, "myRpc"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 858 | {"example-schema"s, "numberOrString"}, |
| 859 | {"example-schema"s, "obsoleteLeaf"}, |
| 860 | {"example-schema"s, "obsoleteLeafWithDeprecatedType"}, |
| 861 | {"example-schema"s, "obsoleteLeafWithObsoleteType"}, |
| 862 | {"example-schema"s, "pizzaIdentLeaf"}, |
| 863 | {"example-schema"s, "pizzaSize"}, |
| 864 | {"example-schema"s, "portMapping"}, |
| 865 | {"example-schema"s, "portSettings"}, |
| 866 | {"example-schema"s, "systemStats"}, |
| 867 | {"example-schema"s, "twoKeyList"}, |
| 868 | {"example-schema"s, "wavelength"}, |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 869 | {"example-schema"s, "zero"}, |
| 870 | {"example-schema"s, "subLeaf"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 871 | }; |
| 872 | expectedRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 873 | {boost::none, "/example-schema:_list"}, |
| 874 | {boost::none, "/example-schema:_list/contInList"}, |
| 875 | {boost::none, "/example-schema:_list/number"}, |
| 876 | {boost::none, "/example-schema:a"}, |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 877 | {boost::none, "/example-schema:addresses"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 878 | {boost::none, "/example-schema:a/a2"}, |
| 879 | {boost::none, "/example-schema:a/a2/a3"}, |
| 880 | {boost::none, "/example-schema:a/leafa"}, |
| 881 | {boost::none, "/example-schema:a/second-schema:augmentedContainer"}, |
| 882 | {boost::none, "/example-schema:activeMappedPort"}, |
| 883 | {boost::none, "/example-schema:activeNumber"}, |
| 884 | {boost::none, "/example-schema:activePort"}, |
| 885 | {boost::none, "/example-schema:another-duration"}, |
| 886 | {boost::none, "/example-schema:b"}, |
| 887 | {boost::none, "/example-schema:b/b2"}, |
| 888 | {boost::none, "/example-schema:b/b2/b3"}, |
| 889 | {boost::none, "/example-schema:carry"}, |
| 890 | {boost::none, "/example-schema:clockSpeed"}, |
| 891 | {boost::none, "/example-schema:deprecatedLeaf"}, |
| 892 | {boost::none, "/example-schema:direction"}, |
| 893 | {boost::none, "/example-schema:duration"}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 894 | {boost::none, "/example-schema:dummyLeaf"}, |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame^] | 895 | {boost::none, "/example-schema:flagBits"}, |
| 896 | {boost::none, "/example-schema:foodDrinkIdentLeaf"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 897 | {boost::none, "/example-schema:foodDrinkIdentLeaf"}, |
| 898 | {boost::none, "/example-schema:foodIdentLeaf"}, |
| 899 | {boost::none, "/example-schema:interface/caseEthernet/ethernet"}, |
| 900 | {boost::none, "/example-schema:interface/caseEthernet/ethernet/ip"}, |
| 901 | {boost::none, "/example-schema:interface/caseLoopback/loopback"}, |
| 902 | {boost::none, "/example-schema:interface/caseLoopback/loopback/ip"}, |
| 903 | {boost::none, "/example-schema:interrupt"}, |
| 904 | {boost::none, "/example-schema:leafBool"}, |
| 905 | {boost::none, "/example-schema:leafDecimal"}, |
| 906 | {boost::none, "/example-schema:leafEnum"}, |
| 907 | {boost::none, "/example-schema:leafEnumTypedef"}, |
| 908 | {boost::none, "/example-schema:leafEnumTypedefRestricted"}, |
| 909 | {boost::none, "/example-schema:leafEnumTypedefRestricted2"}, |
| 910 | {boost::none, "/example-schema:leafInt16"}, |
| 911 | {boost::none, "/example-schema:leafInt32"}, |
| 912 | {boost::none, "/example-schema:leafInt64"}, |
| 913 | {boost::none, "/example-schema:leafInt8"}, |
| 914 | {boost::none, "/example-schema:leafString"}, |
| 915 | {boost::none, "/example-schema:leafUint16"}, |
| 916 | {boost::none, "/example-schema:leafUint32"}, |
| 917 | {boost::none, "/example-schema:leafUint64"}, |
| 918 | {boost::none, "/example-schema:leafUint8"}, |
| 919 | {boost::none, "/example-schema:length"}, |
Václav Kubernát | aaafeae | 2020-05-05 15:41:45 +0200 | [diff] [blame] | 920 | {boost::none, "/example-schema:myRpc"}, |
| 921 | {boost::none, "/example-schema:myRpc/input"}, |
| 922 | {boost::none, "/example-schema:myRpc/output"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 923 | {boost::none, "/example-schema:numberOrString"}, |
| 924 | {boost::none, "/example-schema:obsoleteLeaf"}, |
| 925 | {boost::none, "/example-schema:obsoleteLeafWithDeprecatedType"}, |
| 926 | {boost::none, "/example-schema:obsoleteLeafWithObsoleteType"}, |
| 927 | {boost::none, "/example-schema:pizzaIdentLeaf"}, |
| 928 | {boost::none, "/example-schema:pizzaSize"}, |
| 929 | {boost::none, "/example-schema:portMapping"}, |
| 930 | {boost::none, "/example-schema:portMapping/port"}, |
| 931 | {boost::none, "/example-schema:portSettings"}, |
| 932 | {boost::none, "/example-schema:portSettings/port"}, |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 933 | {boost::none, "/example-schema:portSettings/shutdown"}, |
| 934 | {boost::none, "/example-schema:portSettings/shutdown/input"}, |
| 935 | {boost::none, "/example-schema:portSettings/shutdown/output"}, |
| 936 | {boost::none, "/example-schema:portSettings/shutdown/output/success"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 937 | {boost::none, "/example-schema:systemStats"}, |
| 938 | {boost::none, "/example-schema:systemStats/upTime"}, |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 939 | {boost::none, "/example-schema:subLeaf"}, |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 940 | {boost::none, "/example-schema:twoKeyList"}, |
| 941 | {boost::none, "/example-schema:twoKeyList/name"}, |
| 942 | {boost::none, "/example-schema:twoKeyList/number"}, |
| 943 | {boost::none, "/example-schema:wavelength"}, |
| 944 | {boost::none, "/example-schema:zero"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 945 | }; |
| 946 | } |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 947 | SECTION("second-schema") |
| 948 | { |
| 949 | module = "second-schema"; |
| 950 | expectedNonRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 951 | {"second-schema"s, "bla"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 952 | }; |
| 953 | expectedRecursive = { |
Václav Kubernát | 95b0887 | 2020-04-28 01:04:17 +0200 | [diff] [blame] | 954 | {boost::none, "/second-schema:bla"}, |
| 955 | {boost::none, "/second-schema:bla/bla2"} |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 956 | }; |
| 957 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 958 | |
Václav Kubernát | 3a823f4 | 2020-04-29 23:40:21 +0200 | [diff] [blame] | 959 | REQUIRE(ys.availableNodes(module_{module}, Recursion::NonRecursive) == expectedNonRecursive); |
| 960 | REQUIRE(ys.availableNodes(module_{module}, Recursion::Recursive) == expectedRecursive); |
Václav Kubernát | 47a3f67 | 2019-11-08 15:42:43 +0100 | [diff] [blame] | 961 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 962 | } |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 963 | SECTION("nodeType") |
| 964 | { |
| 965 | yang::NodeTypes expected; |
| 966 | SECTION("leafInt32") |
| 967 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 968 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 969 | expected = yang::NodeTypes::Leaf; |
| 970 | } |
| 971 | |
| 972 | SECTION("a") |
| 973 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 974 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 975 | expected = yang::NodeTypes::Container; |
| 976 | } |
| 977 | |
| 978 | SECTION("a/a2/a3") |
| 979 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 980 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
| 981 | path.m_nodes.emplace_back(container_("a2")); |
| 982 | path.m_nodes.emplace_back(container_("a3")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 983 | expected = yang::NodeTypes::PresenceContainer; |
| 984 | } |
| 985 | |
| 986 | SECTION("_list") |
| 987 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 988 | path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list")); |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 989 | expected = yang::NodeTypes::List; |
| 990 | } |
| 991 | |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 992 | SECTION("subLeaf") |
| 993 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 994 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("subLeaf")); |
Václav Kubernát | 82d7463 | 2020-05-11 15:59:53 +0200 | [diff] [blame] | 995 | expected = yang::NodeTypes::Leaf; |
| 996 | } |
| 997 | |
Václav Kubernát | 34ee85a | 2020-02-18 17:12:12 +0100 | [diff] [blame] | 998 | REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 999 | } |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1000 | |
| 1001 | SECTION("description") |
| 1002 | { |
| 1003 | std::optional<std::string> expected; |
| 1004 | SECTION("leafInt32") |
| 1005 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1006 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1007 | expected = "A 32-bit integer leaf."; |
| 1008 | } |
| 1009 | |
| 1010 | SECTION("leafString") |
| 1011 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1012 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafString")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 1015 | SECTION("numberOrString") |
| 1016 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1017 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("numberOrString")); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 1018 | expected = "Can be an int32 or a string."; |
| 1019 | } |
| 1020 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1021 | REQUIRE(ys.description(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 1022 | } |
| 1023 | |
Václav Kubernát | a1c4c9e | 2020-04-22 00:37:52 +0200 | [diff] [blame] | 1024 | SECTION("status") |
| 1025 | { |
| 1026 | REQUIRE(ys.status("/example-schema:leafUint64") == yang::Status::Current); |
| 1027 | REQUIRE(ys.status("/example-schema:obsoleteLeaf") == yang::Status::Obsolete); |
| 1028 | REQUIRE(ys.status("/example-schema:deprecatedLeaf") == yang::Status::Deprecated); |
| 1029 | REQUIRE(ys.status("/example-schema:obsoleteLeafWithDeprecatedType") == yang::Status::Obsolete); |
| 1030 | REQUIRE(ys.status("/example-schema:obsoleteLeafWithObsoleteType") == yang::Status::Obsolete); |
| 1031 | } |
| 1032 | |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1033 | SECTION("units") |
| 1034 | { |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1035 | yang::LeafDataType expectedType; |
| 1036 | std::optional<std::string> expectedUnits; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1037 | SECTION("length") |
| 1038 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1039 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("length")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1040 | expectedType.emplace<yang::Int32>(); |
| 1041 | expectedUnits = "m"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | SECTION("wavelength") |
| 1045 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1046 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("wavelength")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1047 | expectedType.emplace<yang::Decimal>(); |
| 1048 | expectedUnits = "nm"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | SECTION("leafInt32") |
| 1052 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1053 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1054 | expectedType.emplace<yang::Int32>(); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | SECTION("duration") |
| 1058 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1059 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("duration")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1060 | expectedType.emplace<yang::Int32>(); |
| 1061 | expectedUnits = "s"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | SECTION("another-duration") |
| 1065 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1066 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("another-duration")); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1067 | expectedType.emplace<yang::Int32>(); |
| 1068 | expectedUnits = "vt"; |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1069 | } |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 1070 | auto nodeType = ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)); |
| 1071 | REQUIRE((nodeType == yang::NodeTypes::Leaf || nodeType == yang::NodeTypes::LeafList)); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 1072 | 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] | 1073 | } |
| 1074 | |
| 1075 | SECTION("nodeType") |
| 1076 | { |
| 1077 | yang::NodeTypes expected; |
| 1078 | SECTION("leafInt32") |
| 1079 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1080 | path.m_nodes.emplace_back(module_{"example-schema"}, leaf_("leafInt32")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1081 | expected = yang::NodeTypes::Leaf; |
| 1082 | } |
| 1083 | |
| 1084 | SECTION("a") |
| 1085 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1086 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1087 | expected = yang::NodeTypes::Container; |
| 1088 | } |
| 1089 | |
| 1090 | SECTION("a/a2/a3") |
| 1091 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1092 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
| 1093 | path.m_nodes.emplace_back(container_("a2")); |
| 1094 | path.m_nodes.emplace_back(container_("a3")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1095 | expected = yang::NodeTypes::PresenceContainer; |
| 1096 | } |
| 1097 | |
| 1098 | SECTION("_list") |
| 1099 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1100 | path.m_nodes.emplace_back(module_{"example-schema"}, list_("_list")); |
Václav Kubernát | 1e09bd6 | 2020-02-17 15:13:38 +0100 | [diff] [blame] | 1101 | expected = yang::NodeTypes::List; |
| 1102 | } |
| 1103 | |
| 1104 | REQUIRE(ys.nodeType(pathToSchemaString(path, Prefixes::WhenNeeded)) == expected); |
| 1105 | } |
Václav Kubernát | bd5e3c2 | 2020-02-19 15:22:00 +0100 | [diff] [blame] | 1106 | |
| 1107 | SECTION("leafrefPath") |
| 1108 | { |
| 1109 | REQUIRE(ys.leafrefPath("/example-schema:activeNumber") == "/example-schema:_list/number"); |
| 1110 | } |
Václav Kubernát | 0599e9f | 2020-04-21 09:51:33 +0200 | [diff] [blame] | 1111 | |
| 1112 | SECTION("isConfig") |
| 1113 | { |
| 1114 | REQUIRE(ys.isConfig("/example-schema:leafInt32")); |
| 1115 | REQUIRE_FALSE(ys.isConfig("/example-schema:clockSpeed")); |
| 1116 | REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats")); |
| 1117 | REQUIRE_FALSE(ys.isConfig("/example-schema:systemStats/upTime")); |
| 1118 | } |
Václav Kubernát | bd0d5c8 | 2020-04-21 10:22:03 +0200 | [diff] [blame] | 1119 | |
Václav Kubernát | b1a75c6 | 2020-04-21 15:20:16 +0200 | [diff] [blame] | 1120 | SECTION("defaultValue") |
| 1121 | { |
| 1122 | REQUIRE(ys.defaultValue("/example-schema:leafUint64") == "9001"); |
| 1123 | REQUIRE(ys.defaultValue("/example-schema:leafEnumTypedefRestricted") == "data"); |
| 1124 | REQUIRE(ys.defaultValue("/example-schema:leafInt32") == std::nullopt); |
| 1125 | } |
| 1126 | |
Václav Kubernát | 76ba4ec | 2020-05-18 13:26:56 +0200 | [diff] [blame] | 1127 | SECTION("leafTypeName") |
| 1128 | { |
| 1129 | REQUIRE(ys.leafTypeName("/example-schema:leafEnumTypedefRestricted") == "enumTypedef"); |
| 1130 | REQUIRE(ys.leafTypeName("/example-schema:leafInt32") == std::nullopt); |
| 1131 | } |
Václav Kubernát | a878960 | 2020-07-20 15:18:19 +0200 | [diff] [blame] | 1132 | |
| 1133 | SECTION("dataPathToSchemaPath") |
| 1134 | { |
| 1135 | REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']") == "/example-schema:portSettings"); |
| 1136 | REQUIRE(ys.dataPathToSchemaPath("/example-schema:portSettings[port='eth0']/shutdown") == "/example-schema:portSettings/shutdown"); |
| 1137 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | SECTION("negative") |
| 1141 | { |
| 1142 | SECTION("nonexistent nodes") |
| 1143 | { |
| 1144 | SECTION("example-schema:coze") |
| 1145 | { |
| 1146 | node.first = "example-schema"; |
| 1147 | node.second = "coze"; |
| 1148 | } |
| 1149 | |
| 1150 | SECTION("example-schema:a/nevim") |
| 1151 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1152 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1153 | node.second = "nevim"; |
| 1154 | } |
| 1155 | |
| 1156 | SECTION("modul:a/nevim") |
| 1157 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1158 | path.m_nodes.emplace_back(module_{"modul"}, container_("a")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1159 | node.second = "nevim"; |
| 1160 | } |
| 1161 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1162 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | SECTION("nodetype-specific methods called with different nodetypes") |
| 1166 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 1167 | path.m_nodes.emplace_back(module_{"example-schema"}, container_("a")); |
| 1168 | path.m_nodes.emplace_back(container_("a2")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1169 | |
Václav Kubernát | 912b949 | 2020-05-29 02:03:40 +0200 | [diff] [blame] | 1170 | REQUIRE(!ys.listHasKey(path, "chacha")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | SECTION("nonexistent module") |
| 1174 | { |
Václav Kubernát | 75877de | 2019-11-20 17:43:02 +0100 | [diff] [blame] | 1175 | REQUIRE(!ys.isModule("notAModule")); |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1176 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 1177 | |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 1178 | SECTION("grouping is not a node") |
| 1179 | { |
| 1180 | SECTION("example-schema:arithmeticFlags") |
| 1181 | { |
| 1182 | node.first = "example-schema"; |
| 1183 | node.second = "arithmeticFlags"; |
| 1184 | } |
| 1185 | |
| 1186 | SECTION("example-schema:flags") |
| 1187 | { |
| 1188 | node.first = "example-schema"; |
| 1189 | node.second = "startAndStop"; |
| 1190 | } |
| 1191 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1192 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 7d82da7 | 2019-04-11 15:16:38 +0200 | [diff] [blame] | 1193 | } |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 1194 | |
| 1195 | SECTION("choice is not a node") |
| 1196 | { |
| 1197 | SECTION("example-schema:interface") |
| 1198 | { |
| 1199 | node.first = "example-schema"; |
| 1200 | node.second = "interface"; |
| 1201 | } |
| 1202 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1203 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | SECTION("case is not a node") |
| 1207 | { |
| 1208 | SECTION("example-schema:caseLoopback") |
| 1209 | { |
| 1210 | node.first = "example-schema"; |
| 1211 | node.second = "caseLoopback"; |
| 1212 | } |
| 1213 | |
| 1214 | SECTION("example-schema:caseEthernet") |
| 1215 | { |
| 1216 | node.first = "example-schema"; |
| 1217 | node.second = "caseEthernet"; |
| 1218 | } |
| 1219 | |
Václav Kubernát | e811bfa | 2020-05-29 02:25:20 +0200 | [diff] [blame] | 1220 | REQUIRE_THROWS(ys.nodeType(path, node)); |
Václav Kubernát | 280df4a | 2019-11-01 14:46:34 +0100 | [diff] [blame] | 1221 | } |
Václav Kubernát | f44bdda | 2020-06-22 15:58:41 +0200 | [diff] [blame] | 1222 | |
| 1223 | SECTION("enableFeature - non existing module") |
| 1224 | { |
| 1225 | REQUIRE_THROWS_AS(ys.enableFeature("non-existing", "just-no"), std::runtime_error); |
| 1226 | } |
Václav Kubernát | 7aaf6dc | 2020-06-26 18:03:57 +0200 | [diff] [blame] | 1227 | |
| 1228 | SECTION("enableFeature - non existing feature") |
| 1229 | { |
| 1230 | REQUIRE_THROWS_AS(ys.enableFeature("example-schema", "just-no"), std::runtime_error); |
| 1231 | } |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 1232 | } |
| 1233 | } |