Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +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 | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 9 | #include "trompeloeil_doctest.hpp" |
Jan Kundrát | 76b3ddc | 2019-07-03 10:31:27 +0200 | [diff] [blame] | 10 | #include <boost/core/demangle.hpp> |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 11 | #include "ast_commands.hpp" |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 12 | #include "leaf_data_helpers.hpp" |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 13 | #include "parser.hpp" |
Václav Kubernát | ed824d0 | 2020-06-09 15:48:30 +0200 | [diff] [blame] | 14 | #include "pretty_printers.hpp" |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 15 | #include "static_schema.hpp" |
Václav Kubernát | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 16 | #include "utils.hpp" |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 17 | |
| 18 | TEST_CASE("leaf editing") |
| 19 | { |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 20 | auto schema = std::make_shared<StaticSchema>(); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 21 | schema->addModule("mod"); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 22 | schema->addModule("pizza-module"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 23 | schema->addContainer("/", "mod:contA"); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 24 | schema->addLeaf("/", "mod:leafString", yang::String{}); |
| 25 | schema->addLeaf("/", "mod:leafDecimal", yang::Decimal{}); |
| 26 | schema->addLeaf("/", "mod:leafBool", yang::Bool{}); |
| 27 | schema->addLeaf("/", "mod:leafInt8", yang::Int8{}); |
| 28 | schema->addLeaf("/", "mod:leafInt16", yang::Int16{}); |
| 29 | schema->addLeaf("/", "mod:leafInt32", yang::Int32{}); |
| 30 | schema->addLeaf("/", "mod:leafInt64", yang::Int64{}); |
| 31 | schema->addLeaf("/", "mod:leafUint8", yang::Uint8{}); |
| 32 | schema->addLeaf("/", "mod:leafUint16", yang::Uint16{}); |
| 33 | schema->addLeaf("/", "mod:leafUint32", yang::Uint32{}); |
| 34 | schema->addLeaf("/", "mod:leafUint64", yang::Uint64{}); |
| 35 | schema->addLeaf("/", "mod:leafBinary", yang::Binary{}); |
Václav Kubernát | 222ecff | 2020-05-14 23:14:35 +0200 | [diff] [blame] | 36 | schema->addIdentity(std::nullopt, identityRef_{"mod", "food"}); |
| 37 | schema->addIdentity(std::nullopt, identityRef_{"mod", "vehicle"}); |
| 38 | schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "pizza"}); |
| 39 | schema->addIdentity(identityRef_{"mod", "food"}, identityRef_{"mod", "spaghetti"}); |
| 40 | schema->addIdentity(identityRef_{"mod", "pizza"}, identityRef_{"pizza-module", "hawaii"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 41 | schema->addLeaf("/", "mod:foodIdentRef", yang::IdentityRef{schema->validIdentities("mod", "food")}); |
| 42 | schema->addLeaf("/", "mod:pizzaIdentRef", yang::IdentityRef{schema->validIdentities("mod", "pizza")}); |
| 43 | schema->addLeaf("/mod:contA", "mod:identInCont", yang::IdentityRef{schema->validIdentities("mod", "pizza")}); |
| 44 | schema->addLeaf("/", "mod:leafEnum", createEnum({"lol", "data", "coze"})); |
| 45 | schema->addLeaf("/mod:contA", "mod:leafInCont", yang::String{}); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 46 | schema->addList("/", "mod:list", {"number"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 47 | schema->addLeaf("/mod:list", "mod:number", yang::Int32{}); |
| 48 | schema->addLeaf("/mod:list", "mod:leafInList", yang::String{}); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 49 | schema->addLeaf("/", "mod:refToString", yang::LeafRef{"/mod:leafString", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafString"))}); |
| 50 | schema->addLeaf("/", "mod:refToInt8", yang::LeafRef{"/mod:leafInt8", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafInt8"))}); |
| 51 | schema->addLeaf("/", "mod:refToLeafInCont", yang::LeafRef{"/mod:contA/identInCont", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:contA/mod:identInCont"))}); |
| 52 | schema->addLeaf("/", "mod:intOrString", yang::Union{{yang::TypeInfo{yang::Int32{}}, yang::TypeInfo{yang::String{}}}}); |
| 53 | schema->addLeaf("/", "mod:twoInts", yang::Union{{yang::TypeInfo{yang::Uint8{}}, yang::TypeInfo{yang::Int16{}}}}); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 54 | schema->addLeaf("/", "mod:unionStringEnumLeafref", yang::Union{{ |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 55 | yang::LeafDataType{yang::String{}}, |
| 56 | yang::LeafDataType{createEnum({"foo", "bar"})}, |
| 57 | yang::LeafDataType{yang::LeafRef{"/mod:leafEnum", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:leafEnum"))}} |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 58 | }}); |
| 59 | |
| 60 | schema->addList("/", "mod:portSettings", {"port"}); |
| 61 | schema->addLeaf("/mod:portSettings", "mod:port", createEnum({"eth0", "eth1", "eth2"})); |
| 62 | schema->addList("/", "mod:portMapping", {"port"}); |
| 63 | schema->addLeaf("/mod:portMapping", "mod:port", createEnum({"utf1", "utf2", "utf3"})); |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 64 | schema->addLeaf("/", "mod:activeMappedPort", yang::LeafRef{"/mod:portMapping/mod:port", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:portMapping/mod:port"))}); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 65 | schema->addLeaf("/", "mod:activePort", yang::Union{{ |
Václav Kubernát | 13b23d7 | 2020-04-16 21:49:51 +0200 | [diff] [blame] | 66 | yang::TypeInfo{createEnum({"wlan0", "wlan1"})}, |
| 67 | yang::TypeInfo{yang::LeafRef{"/mod:portSettings/mod:port", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:portSettings/mod:port"))}}, |
| 68 | yang::TypeInfo{yang::LeafRef{"/mod:activeMappedPort", std::make_unique<yang::TypeInfo>(schema->leafType("/mod:activeMappedPort"))}}, |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 69 | yang::TypeInfo{yang::Empty{}}, |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 70 | }}); |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 71 | schema->addLeaf("/", "mod:dummy", yang::Empty{}); |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 72 | schema->addLeaf("/", "mod:readonly", yang::Int32{}, yang::AccessType::ReadOnly); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 73 | |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 74 | schema->addLeaf("/", "mod:flags", yang::Bits{{"carry", "sign"}}); |
Jan Kundrát | bb7aa85 | 2023-08-30 11:51:43 +0200 | [diff] [blame] | 75 | schema->addLeaf("/", "mod:iid", yang::InstanceIdentifier{}); |
| 76 | schema->addLeaf("/mod:contA", "mod:x", yang::String{}); |
| 77 | schema->addLeaf("/mod:contA", "mod:iid", yang::InstanceIdentifier{}); |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 78 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 79 | Parser parser(schema); |
| 80 | std::string input; |
| 81 | std::ostringstream errorStream; |
| 82 | |
| 83 | SECTION("valid input") |
| 84 | { |
| 85 | set_ expected; |
Jan Kundrát | 03c77a1 | 2023-08-28 14:23:05 +0200 | [diff] [blame] | 86 | dataPath_ cwd; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 87 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 88 | SECTION("set mod:leafString \"some_data\"") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 89 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 90 | input = "set mod:leafString \'some_data\'"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 91 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafString")); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 92 | expected.m_data = std::string("some_data"); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Jan Kundrát | 03c77a1 | 2023-08-28 14:23:05 +0200 | [diff] [blame] | 95 | SECTION("cd mod:contA; set leafInCont 'x'") |
| 96 | { |
| 97 | input = "set leafInCont 'x'"; |
| 98 | cwd.m_nodes.emplace_back(module_{"mod"}, container_{"contA"}); |
| 99 | expected.m_path.m_nodes.emplace_back(leaf_("leafInCont")); |
| 100 | expected.m_data = std::string("x"); |
| 101 | } |
| 102 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 103 | SECTION("set mod:contA/leafInCont 'more_data'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 104 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 105 | input = "set mod:contA/leafInCont 'more_data'"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 106 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA")); |
| 107 | expected.m_path.m_nodes.emplace_back(leaf_("leafInCont")); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 108 | expected.m_data = std::string("more_data"); |
| 109 | } |
| 110 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 111 | SECTION("set mod:contA/leafInCont \"data with' a quote\"") |
Václav Kubernát | c18ffac | 2020-01-10 16:06:06 +0100 | [diff] [blame] | 112 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 113 | input = "set mod:contA/leafInCont \"data with' a quote\""; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 114 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA")); |
| 115 | expected.m_path.m_nodes.emplace_back(leaf_("leafInCont")); |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 116 | expected.m_data = std::string("data with' a quote"); |
| 117 | } |
| 118 | |
| 119 | SECTION("set mod:contA/leafInCont 'data with\" a quote'") |
| 120 | { |
| 121 | input = "set mod:contA/leafInCont 'data with\" a quote'"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 122 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA")); |
| 123 | expected.m_path.m_nodes.emplace_back(leaf_("leafInCont")); |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 124 | expected.m_data = std::string("data with\" a quote"); |
| 125 | } |
| 126 | |
| 127 | SECTION("set mod:contA/leafInCont 'more d\tata'") // spaces in string |
| 128 | { |
| 129 | input = "set mod:contA/leafInCont 'more d\tata'"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 130 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA")); |
| 131 | expected.m_path.m_nodes.emplace_back(leaf_("leafInCont")); |
Václav Kubernát | c18ffac | 2020-01-10 16:06:06 +0100 | [diff] [blame] | 132 | expected.m_data = std::string("more d\tata"); |
| 133 | } |
| 134 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 135 | SECTION("set mod:list[number=1]/leafInList \"another_data\"") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 136 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 137 | input = "set mod:list[number=1]/leafInList \"another_data\""; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 138 | auto keys = ListInstance{ |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 139 | {"number", int32_t{1}}}; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 140 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, listElement_("list", keys)); |
| 141 | expected.m_path.m_nodes.emplace_back(leaf_("leafInList")); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 142 | expected.m_data = std::string("another_data"); |
| 143 | } |
| 144 | |
| 145 | SECTION("data types") |
| 146 | { |
| 147 | SECTION("string") |
| 148 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 149 | input = "set mod:leafString \"somedata\""; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 150 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafString")); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 151 | expected.m_data = std::string("somedata"); |
| 152 | } |
| 153 | |
Václav Kubernát | b8bad06 | 2021-02-04 00:02:45 +0100 | [diff] [blame] | 154 | SECTION("more spaces before value") |
| 155 | { |
| 156 | input = "set mod:leafString \"somedata\""; |
| 157 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafString")); |
| 158 | expected.m_data = std::string("somedata"); |
| 159 | } |
| 160 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 161 | SECTION("int8") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 162 | { |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 163 | input = "set mod:leafInt8 2"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 164 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt8")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 165 | expected.m_data = int8_t{2}; |
| 166 | } |
| 167 | |
| 168 | SECTION("negative int8") |
| 169 | { |
| 170 | input = "set mod:leafInt8 -10"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 171 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt8")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 172 | expected.m_data = int8_t{-10}; |
| 173 | } |
| 174 | |
| 175 | SECTION("uint8") |
| 176 | { |
| 177 | input = "set mod:leafUint8 2"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 178 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint8")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 179 | expected.m_data = uint8_t{2}; |
| 180 | } |
| 181 | |
| 182 | SECTION("int16") |
| 183 | { |
| 184 | input = "set mod:leafInt16 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 185 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt16")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 186 | expected.m_data = int16_t{30'000}; |
| 187 | } |
| 188 | |
| 189 | SECTION("uint16") |
| 190 | { |
| 191 | input = "set mod:leafUint16 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 192 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint16")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 193 | expected.m_data = uint16_t{30'000}; |
| 194 | } |
| 195 | |
| 196 | SECTION("int32") |
| 197 | { |
| 198 | input = "set mod:leafInt32 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 199 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt32")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 200 | expected.m_data = int32_t{30'000}; |
| 201 | } |
| 202 | |
| 203 | SECTION("uint32") |
| 204 | { |
| 205 | input = "set mod:leafUint32 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 206 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint32")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 207 | expected.m_data = uint32_t{30'000}; |
| 208 | } |
| 209 | |
| 210 | SECTION("int32") |
| 211 | { |
| 212 | input = "set mod:leafInt32 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 213 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt32")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 214 | expected.m_data = int32_t{30'000}; |
| 215 | } |
| 216 | |
| 217 | SECTION("uint64") |
| 218 | { |
| 219 | input = "set mod:leafUint64 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 220 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint64")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 221 | expected.m_data = uint64_t{30'000}; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | SECTION("decimal") |
| 225 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 226 | input = "set mod:leafDecimal 3.14159"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 227 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafDecimal")); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 228 | expected.m_data = 3.14159; |
| 229 | } |
| 230 | |
| 231 | SECTION("enum") |
| 232 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 233 | input = "set mod:leafEnum coze"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 234 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafEnum")); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 235 | expected.m_data = enum_("coze"); |
| 236 | } |
| 237 | |
| 238 | SECTION("bool") |
| 239 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 240 | input = "set mod:leafBool true"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 241 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafBool")); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 242 | expected.m_data = true; |
| 243 | } |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 244 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 245 | SECTION("union") |
| 246 | { |
| 247 | SECTION("int") |
| 248 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 249 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("intOrString")); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 250 | input = "set mod:intOrString 90"; |
| 251 | expected.m_data = int32_t{90}; |
| 252 | } |
| 253 | SECTION("string") |
| 254 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 255 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("intOrString")); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 256 | input = "set mod:intOrString \"test\""; |
| 257 | expected.m_data = std::string{"test"}; |
| 258 | } |
| 259 | |
| 260 | SECTION("union with two integral types") |
| 261 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 262 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("twoInts")); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 263 | SECTION("uint8") |
| 264 | { |
| 265 | input = "set mod:twoInts 100"; |
| 266 | expected.m_data = uint8_t{100}; |
| 267 | } |
| 268 | SECTION("int16") |
| 269 | { |
| 270 | input = "set mod:twoInts 6666"; |
| 271 | expected.m_data = int16_t{6666}; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | SECTION("union with enum and leafref to enum") |
| 276 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 277 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("unionStringEnumLeafref")); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 278 | SECTION("string") |
| 279 | { |
| 280 | input = "set mod:unionStringEnumLeafref \"AHOJ\""; |
| 281 | expected.m_data = std::string{"AHOJ"}; |
| 282 | } |
| 283 | SECTION("enum") |
| 284 | { |
| 285 | input = "set mod:unionStringEnumLeafref bar"; |
| 286 | expected.m_data = enum_("bar"); |
| 287 | } |
| 288 | SECTION("enum leafref") |
| 289 | { |
| 290 | input = "set mod:unionStringEnumLeafref coze"; |
| 291 | expected.m_data = enum_("coze"); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | SECTION("activePort") |
| 296 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 297 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("activePort")); |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 298 | input = "set mod:activePort "; |
| 299 | SECTION("1. anonymous enum") |
| 300 | { |
| 301 | SECTION("wlan0") |
| 302 | { |
| 303 | input += "wlan0"; |
| 304 | expected.m_data = enum_("wlan0"); |
| 305 | } |
| 306 | SECTION("wlan1") |
| 307 | { |
| 308 | input += "wlan1"; |
| 309 | expected.m_data = enum_("wlan1"); |
| 310 | } |
| 311 | } |
| 312 | SECTION("2. leafref to enum") |
| 313 | { |
| 314 | SECTION("eth0") |
| 315 | { |
| 316 | input += "eth0"; |
| 317 | expected.m_data = enum_("eth0"); |
| 318 | } |
| 319 | SECTION("eth1") |
| 320 | { |
| 321 | input += "eth1"; |
| 322 | expected.m_data = enum_("eth1"); |
| 323 | } |
| 324 | SECTION("eth2") |
| 325 | { |
| 326 | input += "eth2"; |
| 327 | expected.m_data = enum_("eth2"); |
| 328 | } |
| 329 | } |
| 330 | SECTION("3. leafref to leafref") |
| 331 | { |
| 332 | SECTION("utf1") |
| 333 | { |
| 334 | input += "utf1"; |
| 335 | expected.m_data = enum_("utf1"); |
| 336 | } |
| 337 | SECTION("utf2") |
| 338 | { |
| 339 | input += "utf2"; |
| 340 | expected.m_data = enum_("utf2"); |
| 341 | } |
| 342 | SECTION("utf3") |
| 343 | { |
| 344 | input += "utf3"; |
| 345 | expected.m_data = enum_("utf3"); |
| 346 | } |
| 347 | } |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 348 | SECTION("4. empty") |
| 349 | { |
| 350 | expected.m_data = empty_{}; |
| 351 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 355 | SECTION("binary") |
| 356 | { |
| 357 | SECTION("zero ending '='") |
| 358 | { |
| 359 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++"; |
| 360 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++"}; |
| 361 | } |
| 362 | |
| 363 | SECTION("one ending '='") |
| 364 | { |
| 365 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++="; |
| 366 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++="}; |
| 367 | } |
| 368 | |
| 369 | SECTION("two ending '='") |
| 370 | { |
| 371 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++=="; |
| 372 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++=="}; |
| 373 | } |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 374 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafBinary")); |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 375 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 376 | |
| 377 | SECTION("identityRef") |
| 378 | { |
| 379 | SECTION("foodIdentRef") |
| 380 | { |
| 381 | input = "set mod:foodIdentRef "; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 382 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("foodIdentRef")); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 383 | |
| 384 | SECTION("food") |
| 385 | { |
| 386 | input += "food"; |
| 387 | expected.m_data = identityRef_("food"); |
| 388 | } |
| 389 | SECTION("mod:food") |
| 390 | { |
| 391 | input += "mod:food"; |
| 392 | expected.m_data = identityRef_("mod", "food"); |
| 393 | } |
| 394 | SECTION("pizza") |
| 395 | { |
| 396 | input += "pizza"; |
| 397 | expected.m_data = identityRef_("pizza"); |
| 398 | } |
| 399 | SECTION("mod:pizza") |
| 400 | { |
| 401 | input += "mod:pizza"; |
| 402 | expected.m_data = identityRef_("mod", "pizza"); |
| 403 | } |
| 404 | SECTION("pizza-module:hawaii") |
| 405 | { |
| 406 | input += "pizza-module:hawaii"; |
| 407 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 408 | } |
| 409 | } |
| 410 | SECTION("pizzaIdentRef") |
| 411 | { |
| 412 | input = "set mod:pizzaIdentRef "; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 413 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("pizzaIdentRef")); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 414 | SECTION("pizza") |
| 415 | { |
| 416 | input += "pizza"; |
| 417 | expected.m_data = identityRef_("pizza"); |
| 418 | } |
| 419 | SECTION("mod:pizza") |
| 420 | { |
| 421 | input += "mod:pizza"; |
| 422 | expected.m_data = identityRef_("mod", "pizza"); |
| 423 | } |
| 424 | SECTION("pizza-module:hawaii") |
| 425 | { |
| 426 | input += "pizza-module:hawaii"; |
| 427 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 428 | } |
| 429 | } |
| 430 | SECTION("mod:contA/identInCont") |
| 431 | { |
| 432 | input = "set mod:contA/identInCont "; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 433 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA")); |
| 434 | expected.m_path.m_nodes.emplace_back(leaf_("identInCont")); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 435 | SECTION("pizza") |
| 436 | { |
| 437 | input += "pizza"; |
| 438 | expected.m_data = identityRef_("pizza"); |
| 439 | } |
| 440 | SECTION("mod:pizza") |
| 441 | { |
| 442 | input += "mod:pizza"; |
| 443 | expected.m_data = identityRef_("mod", "pizza"); |
| 444 | } |
| 445 | SECTION("pizza-module:hawaii") |
| 446 | { |
| 447 | input += "pizza-module:hawaii"; |
| 448 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 449 | } |
| 450 | } |
| 451 | } |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 452 | SECTION("leafRef") |
| 453 | { |
| 454 | SECTION("refToString") |
| 455 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 456 | input = "set mod:refToString \"blabal\""; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 457 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("refToString")); |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 458 | expected.m_data = std::string("blabal"); |
| 459 | } |
| 460 | |
| 461 | SECTION("refToInt8") |
| 462 | { |
| 463 | input = "set mod:refToInt8 42"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 464 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("refToInt8")); |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 465 | expected.m_data = int8_t{42}; |
| 466 | } |
Václav Kubernát | 2d7b05c | 2020-04-05 14:02:37 +0200 | [diff] [blame] | 467 | |
| 468 | SECTION("refToLeafInCont") |
| 469 | { |
| 470 | input = "set mod:refToLeafInCont pizza"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 471 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("refToLeafInCont")); |
Václav Kubernát | 2d7b05c | 2020-04-05 14:02:37 +0200 | [diff] [blame] | 472 | expected.m_data = identityRef_{"pizza"}; |
| 473 | } |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 474 | } |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 475 | SECTION("empty") |
| 476 | { |
| 477 | input = "set mod:dummy "; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 478 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("dummy")); |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 479 | expected.m_data = empty_{}; |
| 480 | } |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 481 | |
| 482 | SECTION("bits") |
| 483 | { |
| 484 | input = "set mod:flags "; |
| 485 | decltype(bits_::m_bits) bits; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 486 | SECTION("<nothing>") |
| 487 | { |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 488 | bits = {}; |
| 489 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 490 | SECTION("carry") |
| 491 | { |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 492 | input += "carry"; |
| 493 | bits = {"carry"}; |
| 494 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 495 | SECTION("sign") |
| 496 | { |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 497 | input += "sign"; |
| 498 | bits = {"sign"}; |
| 499 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 500 | SECTION("carry sign") |
| 501 | { |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 502 | input += "carry sign"; |
| 503 | bits = {"carry", "sign"}; |
| 504 | } |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 505 | SECTION("sign carry") |
| 506 | { |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 507 | input += "sign carry"; |
| 508 | bits = {"sign", "carry"}; |
| 509 | } |
| 510 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("flags")); |
| 511 | expected.m_data = bits_{bits}; |
| 512 | } |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Jan Kundrát | bb7aa85 | 2023-08-30 11:51:43 +0200 | [diff] [blame] | 515 | SECTION("instance-identifier") { |
| 516 | SECTION("toplevel") |
| 517 | { |
| 518 | input = "set mod:iid /mod:leafUint32"; |
| 519 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_{"iid"}); |
| 520 | expected.m_data = instanceIdentifier_{"/mod:leafUint32"}; |
| 521 | } |
| 522 | |
| 523 | SECTION("deep to toplevel") |
| 524 | { |
| 525 | input = "set mod:contA/iid /mod:leafUint32"; |
| 526 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_{"contA"}); |
| 527 | expected.m_path.m_nodes.emplace_back(leaf_{"iid"}); |
| 528 | expected.m_data = instanceIdentifier_{"/mod:leafUint32"}; |
| 529 | } |
| 530 | |
| 531 | SECTION("deep to deep unprefixed") |
| 532 | { |
| 533 | input = "set mod:contA/iid /mod:contA/x"; |
| 534 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_{"contA"}); |
| 535 | expected.m_path.m_nodes.emplace_back(leaf_{"iid"}); |
| 536 | expected.m_data = instanceIdentifier_{"/mod:contA/x"}; |
| 537 | } |
| 538 | |
| 539 | SECTION("deep to deep mod-prefixed") |
| 540 | { |
| 541 | input = "set mod:contA/iid /mod:contA/mod:x"; |
| 542 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_{"contA"}); |
| 543 | expected.m_path.m_nodes.emplace_back(leaf_{"iid"}); |
| 544 | expected.m_data = instanceIdentifier_{"/mod:contA/mod:x"}; |
| 545 | } |
| 546 | |
| 547 | SECTION("absolute when nested") |
| 548 | { |
| 549 | cwd.m_nodes.emplace_back(module_{"mod"}, container_{"contA"}); |
| 550 | input = "set iid /mod:contA/x"; |
| 551 | expected.m_path.m_nodes.emplace_back(leaf_{"iid"}); |
| 552 | expected.m_data = instanceIdentifier_{"/mod:contA/x"}; |
| 553 | } |
| 554 | } |
| 555 | |
Jan Kundrát | 03c77a1 | 2023-08-28 14:23:05 +0200 | [diff] [blame] | 556 | parser.changeNode(cwd); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 557 | command_ command = parser.parseCommand(input, errorStream); |
| 558 | REQUIRE(command.type() == typeid(set_)); |
| 559 | REQUIRE(boost::get<set_>(command) == expected); |
| 560 | } |
| 561 | |
| 562 | SECTION("invalid input") |
| 563 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 564 | std::string expectedError; |
Jan Kundrát | 03c77a1 | 2023-08-28 14:23:05 +0200 | [diff] [blame] | 565 | dataPath_ cwd; |
| 566 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 567 | SECTION("missing space between a command and its arguments") |
| 568 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 569 | SECTION("setmod:leafString some_data") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 570 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 571 | input = "setmod:leafString 'some_data'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
| 575 | SECTION("missing space between arguments") |
| 576 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 577 | SECTION("set mod:leafString'lol'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 578 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 579 | input = "set mod:leafString'lol'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
| 583 | SECTION("non-leaf identifiers") |
| 584 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 585 | SECTION("set mod:nonexistent 'blabla'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 586 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 587 | input = "set mod:nonexistent 'blabla'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 588 | } |
| 589 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 590 | SECTION("set mod:contA 'abde'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 591 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 592 | input = "set mod:contA 'abde'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 596 | SECTION("wrong types") |
| 597 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 598 | expectedError = "leaf data type mismatch"; |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 599 | SECTION("set mod:leafBool 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 600 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 601 | input = "set mod:leafBool 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 602 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 603 | SECTION("set mod:leafUint8 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 604 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 605 | input = "set mod:leafUint8 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 606 | } |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 607 | SECTION("set mod:leafUint8 -5") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 608 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 609 | input = "set mod:leafUint8 -5"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 610 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 611 | SECTION("set mod:leafInt8 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 612 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 613 | input = "set mod:leafInt8 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 614 | } |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 615 | SECTION("set mod:leafInt8 130") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 616 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 617 | input = "set mod:leafInt8 130"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 618 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 619 | SECTION("set mod:leafUint16 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 620 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 621 | input = "set mod:leafUint16 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 622 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 623 | SECTION("set mod:leafInt16 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 624 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 625 | input = "set mod:leafInt16 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 626 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 627 | SECTION("set mod:leafUint32 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 628 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 629 | input = "set mod:leafUint32 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 630 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 631 | SECTION("set mod:leafInt32 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 632 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 633 | input = "set mod:leafInt32 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 634 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 635 | SECTION("set mod:leafUint64 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 636 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 637 | input = "set mod:leafUint64 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 638 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 639 | SECTION("set mod:leafInt64 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 640 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 641 | input = "set mod:leafInt64 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 642 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 643 | SECTION("set mod:leafEnum 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 644 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 645 | input = "set mod:leafEnum 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 646 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 647 | SECTION("set mod:refToInt8 'blabla'") |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 648 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 649 | input = "set mod:refToInt8 'blabla'"; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 650 | } |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 651 | } |
| 652 | |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 653 | SECTION("wrong base64 strings") |
| 654 | { |
| 655 | SECTION("invalid character") |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 656 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 657 | input = "set mod:leafBinary dbahj-"; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 658 | } |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 659 | SECTION("equal sign in the middle") |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 660 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 661 | input = "set mod:leafBinary db=ahj"; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 662 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 663 | SECTION("enclosing in quotes") |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 664 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 665 | input = "set mod:leafBinary 'dbahj'"; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 666 | } |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 667 | } |
| 668 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 669 | SECTION("non-existing identity") |
| 670 | { |
| 671 | input = "set mod:foodIdentRef identityBLABLA"; |
| 672 | } |
| 673 | |
Václav Kubernát | f365ecf | 2020-06-09 16:22:43 +0200 | [diff] [blame] | 674 | SECTION("identity with non-existing module") |
| 675 | { |
| 676 | expectedError = "Invalid module name"; |
| 677 | input = "set mod:foodIdentRef xd:haha"; |
| 678 | } |
| 679 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 680 | SECTION("setting identities with wrong bases") |
| 681 | { |
| 682 | SECTION("set mod:foodIdentRef mod:vehicle") |
| 683 | { |
| 684 | input = "set mod:foodIdentRef mod:vehicle"; |
| 685 | } |
| 686 | SECTION("set mod:pizzaIdentRef mod:food") |
| 687 | { |
| 688 | input = "set mod:pizzaIdentRef mod:food"; |
| 689 | } |
| 690 | } |
| 691 | SECTION("setting different module identities without prefix") |
| 692 | { |
| 693 | input = "set mod:pizzaIdentRef hawaii"; |
| 694 | } |
| 695 | SECTION("identity prefix without name") |
| 696 | { |
| 697 | input = "set mod:contA/identInCont pizza-module:"; |
| 698 | } |
| 699 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 700 | SECTION("set a union path to a wrong type") |
| 701 | { |
| 702 | input = "set mod:intOrString true"; |
| 703 | } |
| 704 | |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 705 | SECTION("no space for empty data") |
| 706 | { |
| 707 | input = "set mod:dummy"; |
| 708 | } |
| 709 | |
Václav Kubernát | 0d42c51 | 2020-05-20 21:18:39 +0200 | [diff] [blame] | 710 | SECTION("empty path") |
| 711 | { |
| 712 | input = "set "; |
| 713 | } |
| 714 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 715 | SECTION("setting readonly data") |
| 716 | { |
| 717 | input = "set mod:readonly 123"; |
| 718 | } |
| 719 | |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 720 | SECTION("nonexistent bits") |
| 721 | { |
| 722 | input = "set mod:flags daw"; |
| 723 | } |
| 724 | |
| 725 | SECTION("same bit more than once") |
| 726 | { |
| 727 | input = "set mod:flags carry carry"; |
| 728 | } |
| 729 | |
Jan Kundrát | bb7aa85 | 2023-08-30 11:51:43 +0200 | [diff] [blame] | 730 | SECTION("instance-identifier non-existing node") |
| 731 | { |
| 732 | input = "set mod:iid /mod:404"; |
| 733 | } |
| 734 | |
| 735 | SECTION("instance-identifier non-existing node without leading slash") |
| 736 | { |
| 737 | input = "set mod:iid mod:404"; |
| 738 | } |
| 739 | |
| 740 | SECTION("instance-identifier node without leading slash") |
| 741 | { |
| 742 | input = "set mod:iid mod:leafUint32"; |
| 743 | } |
| 744 | |
| 745 | SECTION("instance-identifier to pseudo-relative unprefixed") |
| 746 | { |
| 747 | cwd.m_nodes.emplace_back(module_{"mod"}, container_{"contA"}); |
| 748 | input = "set iid x"; |
| 749 | } |
| 750 | |
| 751 | SECTION("instance-identifier to pseudo-relative prefixed") |
| 752 | { |
| 753 | cwd.m_nodes.emplace_back(module_{"mod"}, container_{"contA"}); |
| 754 | input = "set iid mod:x"; |
| 755 | } |
| 756 | |
| 757 | SECTION("instance-identifier without leading slash when nested") |
| 758 | { |
| 759 | cwd.m_nodes.emplace_back(module_{"mod"}, container_{"contA"}); |
| 760 | input = "set iid mod:contA/x"; |
| 761 | } |
| 762 | |
Jan Kundrát | 03c77a1 | 2023-08-28 14:23:05 +0200 | [diff] [blame] | 763 | parser.changeNode(cwd); |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 764 | REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException); |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 765 | REQUIRE(errorStream.str().find(expectedError) != std::string::npos); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 766 | } |
Jan Kundrát | b7206ad | 2020-06-18 21:08:14 +0200 | [diff] [blame] | 767 | |
| 768 | SECTION("deleting a leaf") |
| 769 | { |
| 770 | delete_ expected; |
| 771 | input = "delete mod:leafString"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 772 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafString")); |
Jan Kundrát | b7206ad | 2020-06-18 21:08:14 +0200 | [diff] [blame] | 773 | |
| 774 | command_ command = parser.parseCommand(input, errorStream); |
| 775 | REQUIRE(command.type() == typeid(delete_)); |
| 776 | REQUIRE(boost::get<delete_>(command) == expected); |
| 777 | } |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 778 | } |