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