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 | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 14 | #include "static_schema.hpp" |
Václav Kubernát | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 15 | #include "utils.hpp" |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 16 | |
Jan Kundrát | 76b3ddc | 2019-07-03 10:31:27 +0200 | [diff] [blame] | 17 | std::ostream& operator<<(std::ostream& s, const set_ cmd) |
| 18 | { |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 19 | return s << "Command SET {path: " << pathToSchemaString(cmd.m_path, Prefixes::Always) << ", type " << boost::core::demangle(cmd.m_data.type().name()) << ", data: " << leafDataToString(cmd.m_data) << "}"; |
Jan Kundrát | 76b3ddc | 2019-07-03 10:31:27 +0200 | [diff] [blame] | 20 | } |
| 21 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 22 | TEST_CASE("leaf editing") |
| 23 | { |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 24 | auto schema = std::make_shared<StaticSchema>(); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 25 | schema->addModule("mod"); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 26 | schema->addModule("pizza-module"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 27 | schema->addContainer("/", "mod:contA"); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 28 | schema->addLeaf("/", "mod:leafString", yang::String{}); |
| 29 | schema->addLeaf("/", "mod:leafDecimal", yang::Decimal{}); |
| 30 | schema->addLeaf("/", "mod:leafBool", yang::Bool{}); |
| 31 | schema->addLeaf("/", "mod:leafInt8", yang::Int8{}); |
| 32 | schema->addLeaf("/", "mod:leafInt16", yang::Int16{}); |
| 33 | schema->addLeaf("/", "mod:leafInt32", yang::Int32{}); |
| 34 | schema->addLeaf("/", "mod:leafInt64", yang::Int64{}); |
| 35 | schema->addLeaf("/", "mod:leafUint8", yang::Uint8{}); |
| 36 | schema->addLeaf("/", "mod:leafUint16", yang::Uint16{}); |
| 37 | schema->addLeaf("/", "mod:leafUint32", yang::Uint32{}); |
| 38 | schema->addLeaf("/", "mod:leafUint64", yang::Uint64{}); |
| 39 | schema->addLeaf("/", "mod:leafBinary", yang::Binary{}); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 40 | schema->addIdentity(std::nullopt, ModuleValuePair{"mod", "food"}); |
| 41 | schema->addIdentity(std::nullopt, ModuleValuePair{"mod", "vehicle"}); |
| 42 | schema->addIdentity(ModuleValuePair{"mod", "food"}, ModuleValuePair{"mod", "pizza"}); |
| 43 | schema->addIdentity(ModuleValuePair{"mod", "food"}, ModuleValuePair{"mod", "spaghetti"}); |
| 44 | schema->addIdentity(ModuleValuePair{"mod", "pizza"}, ModuleValuePair{"pizza-module", "hawaii"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 45 | schema->addLeaf("/", "mod:foodIdentRef", yang::IdentityRef{schema->validIdentities("mod", "food")}); |
| 46 | schema->addLeaf("/", "mod:pizzaIdentRef", yang::IdentityRef{schema->validIdentities("mod", "pizza")}); |
| 47 | schema->addLeaf("/mod:contA", "mod:identInCont", yang::IdentityRef{schema->validIdentities("mod", "pizza")}); |
| 48 | schema->addLeaf("/", "mod:leafEnum", createEnum({"lol", "data", "coze"})); |
| 49 | schema->addLeaf("/mod:contA", "mod:leafInCont", yang::String{}); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 50 | schema->addList("/", "mod:list", {"number"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 51 | schema->addLeaf("/mod:list", "mod:number", yang::Int32{}); |
| 52 | schema->addLeaf("/mod:list", "mod:leafInList", yang::String{}); |
| 53 | schema->addLeaf("/", "mod:refToString", yang::LeafRef{"/mod:leafString", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:leafString"))}); |
| 54 | schema->addLeaf("/", "mod:refToInt8", yang::LeafRef{"/mod:leafInt8", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:leafInt8"))}); |
Václav Kubernát | 2d7b05c | 2020-04-05 14:02:37 +0200 | [diff] [blame^] | 55 | schema->addLeaf("/", "mod:refToLeafInCont", yang::LeafRef{"/mod:contA/identInCont", std::make_unique<yang::LeafDataType>(schema->leafType("/mod:contA/mod:identInCont"))}); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 56 | Parser parser(schema); |
| 57 | std::string input; |
| 58 | std::ostringstream errorStream; |
| 59 | |
| 60 | SECTION("valid input") |
| 61 | { |
| 62 | set_ expected; |
| 63 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 64 | SECTION("set mod:leafString \"some_data\"") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 65 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 66 | input = "set mod:leafString \'some_data\'"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 67 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 68 | expected.m_data = std::string("some_data"); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 71 | SECTION("set mod:contA/leafInCont 'more_data'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 72 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 73 | input = "set mod:contA/leafInCont 'more_data'"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 74 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")}); |
| 75 | expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 76 | expected.m_data = std::string("more_data"); |
| 77 | } |
| 78 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 79 | SECTION("set mod:contA/leafInCont \"data with' a quote\"") |
Václav Kubernát | c18ffac | 2020-01-10 16:06:06 +0100 | [diff] [blame] | 80 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 81 | input = "set mod:contA/leafInCont \"data with' a quote\""; |
| 82 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")}); |
| 83 | expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")}); |
| 84 | expected.m_data = std::string("data with' a quote"); |
| 85 | } |
| 86 | |
| 87 | SECTION("set mod:contA/leafInCont 'data with\" a quote'") |
| 88 | { |
| 89 | input = "set mod:contA/leafInCont 'data with\" a quote'"; |
| 90 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")}); |
| 91 | expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")}); |
| 92 | expected.m_data = std::string("data with\" a quote"); |
| 93 | } |
| 94 | |
| 95 | SECTION("set mod:contA/leafInCont 'more d\tata'") // spaces in string |
| 96 | { |
| 97 | input = "set mod:contA/leafInCont 'more d\tata'"; |
Václav Kubernát | c18ffac | 2020-01-10 16:06:06 +0100 | [diff] [blame] | 98 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")}); |
| 99 | expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")}); |
| 100 | expected.m_data = std::string("more d\tata"); |
| 101 | } |
| 102 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 103 | SECTION("set mod:list[number=1]/leafInList \"another_data\"") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 104 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 105 | input = "set mod:list[number=1]/leafInList \"another_data\""; |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 106 | auto keys = std::map<std::string, leaf_data_>{ |
| 107 | {"number", int32_t{1}}}; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 108 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)}); |
| 109 | expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInList")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 110 | expected.m_data = std::string("another_data"); |
| 111 | } |
| 112 | |
| 113 | SECTION("data types") |
| 114 | { |
| 115 | SECTION("string") |
| 116 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 117 | input = "set mod:leafString \"somedata\""; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 118 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 119 | expected.m_data = std::string("somedata"); |
| 120 | } |
| 121 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 122 | SECTION("int8") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 123 | { |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 124 | input = "set mod:leafInt8 2"; |
| 125 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")}); |
| 126 | expected.m_data = int8_t{2}; |
| 127 | } |
| 128 | |
| 129 | SECTION("negative int8") |
| 130 | { |
| 131 | input = "set mod:leafInt8 -10"; |
| 132 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt8")}); |
| 133 | expected.m_data = int8_t{-10}; |
| 134 | } |
| 135 | |
| 136 | SECTION("uint8") |
| 137 | { |
| 138 | input = "set mod:leafUint8 2"; |
| 139 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint8")}); |
| 140 | expected.m_data = uint8_t{2}; |
| 141 | } |
| 142 | |
| 143 | SECTION("int16") |
| 144 | { |
| 145 | input = "set mod:leafInt16 30000"; |
| 146 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt16")}); |
| 147 | expected.m_data = int16_t{30'000}; |
| 148 | } |
| 149 | |
| 150 | SECTION("uint16") |
| 151 | { |
| 152 | input = "set mod:leafUint16 30000"; |
| 153 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint16")}); |
| 154 | expected.m_data = uint16_t{30'000}; |
| 155 | } |
| 156 | |
| 157 | SECTION("int32") |
| 158 | { |
| 159 | input = "set mod:leafInt32 30000"; |
| 160 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")}); |
| 161 | expected.m_data = int32_t{30'000}; |
| 162 | } |
| 163 | |
| 164 | SECTION("uint32") |
| 165 | { |
| 166 | input = "set mod:leafUint32 30000"; |
| 167 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint32")}); |
| 168 | expected.m_data = uint32_t{30'000}; |
| 169 | } |
| 170 | |
| 171 | SECTION("int32") |
| 172 | { |
| 173 | input = "set mod:leafInt32 30000"; |
| 174 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt32")}); |
| 175 | expected.m_data = int32_t{30'000}; |
| 176 | } |
| 177 | |
| 178 | SECTION("uint64") |
| 179 | { |
| 180 | input = "set mod:leafUint64 30000"; |
| 181 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafUint64")}); |
| 182 | expected.m_data = uint64_t{30'000}; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | SECTION("decimal") |
| 186 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 187 | input = "set mod:leafDecimal 3.14159"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 188 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafDecimal")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 189 | expected.m_data = 3.14159; |
| 190 | } |
| 191 | |
| 192 | SECTION("enum") |
| 193 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 194 | input = "set mod:leafEnum coze"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 195 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafEnum")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 196 | expected.m_data = enum_("coze"); |
| 197 | } |
| 198 | |
| 199 | SECTION("bool") |
| 200 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 201 | input = "set mod:leafBool true"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 202 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBool")}); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 203 | expected.m_data = true; |
| 204 | } |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 205 | |
| 206 | SECTION("binary") |
| 207 | { |
| 208 | SECTION("zero ending '='") |
| 209 | { |
| 210 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++"; |
| 211 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++"}; |
| 212 | } |
| 213 | |
| 214 | SECTION("one ending '='") |
| 215 | { |
| 216 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++="; |
| 217 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++="}; |
| 218 | } |
| 219 | |
| 220 | SECTION("two ending '='") |
| 221 | { |
| 222 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++=="; |
| 223 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++=="}; |
| 224 | } |
| 225 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBinary")}); |
| 226 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 227 | |
| 228 | SECTION("identityRef") |
| 229 | { |
| 230 | SECTION("foodIdentRef") |
| 231 | { |
| 232 | input = "set mod:foodIdentRef "; |
| 233 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("foodIdentRef")}); |
| 234 | |
| 235 | SECTION("food") |
| 236 | { |
| 237 | input += "food"; |
| 238 | expected.m_data = identityRef_("food"); |
| 239 | } |
| 240 | SECTION("mod:food") |
| 241 | { |
| 242 | input += "mod:food"; |
| 243 | expected.m_data = identityRef_("mod", "food"); |
| 244 | } |
| 245 | SECTION("pizza") |
| 246 | { |
| 247 | input += "pizza"; |
| 248 | expected.m_data = identityRef_("pizza"); |
| 249 | } |
| 250 | SECTION("mod:pizza") |
| 251 | { |
| 252 | input += "mod:pizza"; |
| 253 | expected.m_data = identityRef_("mod", "pizza"); |
| 254 | } |
| 255 | SECTION("pizza-module:hawaii") |
| 256 | { |
| 257 | input += "pizza-module:hawaii"; |
| 258 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 259 | } |
| 260 | } |
| 261 | SECTION("pizzaIdentRef") |
| 262 | { |
| 263 | input = "set mod:pizzaIdentRef "; |
| 264 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("pizzaIdentRef")}); |
| 265 | SECTION("pizza") |
| 266 | { |
| 267 | input += "pizza"; |
| 268 | expected.m_data = identityRef_("pizza"); |
| 269 | } |
| 270 | SECTION("mod:pizza") |
| 271 | { |
| 272 | input += "mod:pizza"; |
| 273 | expected.m_data = identityRef_("mod", "pizza"); |
| 274 | } |
| 275 | SECTION("pizza-module:hawaii") |
| 276 | { |
| 277 | input += "pizza-module:hawaii"; |
| 278 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 279 | } |
| 280 | } |
| 281 | SECTION("mod:contA/identInCont") |
| 282 | { |
| 283 | input = "set mod:contA/identInCont "; |
| 284 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")}); |
| 285 | expected.m_path.m_nodes.push_back(dataNode_(leaf_("identInCont"))); |
| 286 | SECTION("pizza") |
| 287 | { |
| 288 | input += "pizza"; |
| 289 | expected.m_data = identityRef_("pizza"); |
| 290 | } |
| 291 | SECTION("mod:pizza") |
| 292 | { |
| 293 | input += "mod:pizza"; |
| 294 | expected.m_data = identityRef_("mod", "pizza"); |
| 295 | } |
| 296 | SECTION("pizza-module:hawaii") |
| 297 | { |
| 298 | input += "pizza-module:hawaii"; |
| 299 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 300 | } |
| 301 | } |
| 302 | } |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 303 | SECTION("leafRef") |
| 304 | { |
| 305 | SECTION("refToString") |
| 306 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 307 | input = "set mod:refToString \"blabal\""; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 308 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToString")}); |
| 309 | expected.m_data = std::string("blabal"); |
| 310 | } |
| 311 | |
| 312 | SECTION("refToInt8") |
| 313 | { |
| 314 | input = "set mod:refToInt8 42"; |
| 315 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToInt8")}); |
| 316 | expected.m_data = int8_t{42}; |
| 317 | } |
Václav Kubernát | 2d7b05c | 2020-04-05 14:02:37 +0200 | [diff] [blame^] | 318 | |
| 319 | SECTION("refToLeafInCont") |
| 320 | { |
| 321 | input = "set mod:refToLeafInCont pizza"; |
| 322 | expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("refToLeafInCont")}); |
| 323 | expected.m_data = identityRef_{"pizza"}; |
| 324 | } |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 325 | } |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | command_ command = parser.parseCommand(input, errorStream); |
| 329 | REQUIRE(command.type() == typeid(set_)); |
| 330 | REQUIRE(boost::get<set_>(command) == expected); |
| 331 | } |
| 332 | |
| 333 | SECTION("invalid input") |
| 334 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 335 | std::string expectedError; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 336 | SECTION("missing space between a command and its arguments") |
| 337 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 338 | SECTION("setmod:leafString some_data") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 339 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 340 | input = "setmod:leafString 'some_data'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
| 344 | SECTION("missing space between arguments") |
| 345 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 346 | SECTION("set mod:leafString'lol'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 347 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 348 | input = "set mod:leafString'lol'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | |
| 352 | SECTION("non-leaf identifiers") |
| 353 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 354 | SECTION("set mod:nonexistent 'blabla'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 355 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 356 | input = "set mod:nonexistent 'blabla'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 357 | } |
| 358 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 359 | SECTION("set mod:contA 'abde'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 360 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 361 | input = "set mod:contA 'abde'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 365 | SECTION("wrong types") |
| 366 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 367 | expectedError = "leaf data type mismatch"; |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 368 | SECTION("set mod:leafBool 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 369 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 370 | input = "set mod:leafBool 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 371 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 372 | SECTION("set mod:leafUint8 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 373 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 374 | input = "set mod:leafUint8 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 375 | } |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 376 | SECTION("set mod:leafUint8 -5") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 377 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 378 | input = "set mod:leafUint8 -5"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 379 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 380 | SECTION("set mod:leafInt8 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 381 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 382 | input = "set mod:leafInt8 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 383 | } |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 384 | SECTION("set mod:leafInt8 130") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 385 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 386 | input = "set mod:leafInt8 130"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 387 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 388 | SECTION("set mod:leafUint16 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 389 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 390 | input = "set mod:leafUint16 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 391 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 392 | SECTION("set mod:leafInt16 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 393 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 394 | input = "set mod:leafInt16 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 395 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 396 | SECTION("set mod:leafUint32 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 397 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 398 | input = "set mod:leafUint32 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 399 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 400 | SECTION("set mod:leafInt32 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 401 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 402 | input = "set mod:leafInt32 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 403 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 404 | SECTION("set mod:leafUint64 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 405 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 406 | input = "set mod:leafUint64 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 407 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 408 | SECTION("set mod:leafInt64 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 409 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 410 | input = "set mod:leafInt64 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 411 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 412 | SECTION("set mod:leafEnum 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 413 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 414 | input = "set mod:leafEnum 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 415 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 416 | SECTION("set mod:refToInt8 'blabla'") |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 417 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 418 | input = "set mod:refToInt8 'blabla'"; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 419 | } |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 420 | } |
| 421 | |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 422 | SECTION("wrong base64 strings") |
| 423 | { |
| 424 | SECTION("invalid character") |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 425 | input = "set mod:leafBinary dbahj-"; |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 426 | SECTION("equal sign in the middle") |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 427 | input = "set mod:leafBinary db=ahj"; |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 428 | SECTION("enclosing in quotes") |
| 429 | input = "set mod:leafBinary 'dbahj'"; |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 430 | } |
| 431 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 432 | SECTION("non-existing identity") |
| 433 | { |
| 434 | input = "set mod:foodIdentRef identityBLABLA"; |
| 435 | } |
| 436 | |
| 437 | SECTION("setting identities with wrong bases") |
| 438 | { |
| 439 | SECTION("set mod:foodIdentRef mod:vehicle") |
| 440 | { |
| 441 | input = "set mod:foodIdentRef mod:vehicle"; |
| 442 | } |
| 443 | SECTION("set mod:pizzaIdentRef mod:food") |
| 444 | { |
| 445 | input = "set mod:pizzaIdentRef mod:food"; |
| 446 | } |
| 447 | } |
| 448 | SECTION("setting different module identities without prefix") |
| 449 | { |
| 450 | input = "set mod:pizzaIdentRef hawaii"; |
| 451 | } |
| 452 | SECTION("identity prefix without name") |
| 453 | { |
| 454 | input = "set mod:contA/identInCont pizza-module:"; |
| 455 | } |
| 456 | |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 457 | REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException); |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 458 | REQUIRE(errorStream.str().find(expectedError) != std::string::npos); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 459 | } |
| 460 | } |