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"}}); |
| 75 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 76 | Parser parser(schema); |
| 77 | std::string input; |
| 78 | std::ostringstream errorStream; |
| 79 | |
| 80 | SECTION("valid input") |
| 81 | { |
| 82 | set_ expected; |
| 83 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 84 | SECTION("set mod:leafString \"some_data\"") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 85 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 86 | input = "set mod:leafString \'some_data\'"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 87 | 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] | 88 | expected.m_data = std::string("some_data"); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 89 | } |
| 90 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 91 | SECTION("set mod:contA/leafInCont 'more_data'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 92 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 93 | input = "set mod:contA/leafInCont 'more_data'"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 94 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA")); |
| 95 | expected.m_path.m_nodes.emplace_back(leaf_("leafInCont")); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 96 | expected.m_data = std::string("more_data"); |
| 97 | } |
| 98 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 99 | SECTION("set mod:contA/leafInCont \"data with' a quote\"") |
Václav Kubernát | c18ffac | 2020-01-10 16:06:06 +0100 | [diff] [blame] | 100 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 101 | input = "set mod:contA/leafInCont \"data with' a quote\""; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 102 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA")); |
| 103 | expected.m_path.m_nodes.emplace_back(leaf_("leafInCont")); |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 104 | expected.m_data = std::string("data with' a quote"); |
| 105 | } |
| 106 | |
| 107 | SECTION("set mod:contA/leafInCont 'data with\" a quote'") |
| 108 | { |
| 109 | input = "set mod:contA/leafInCont 'data with\" a quote'"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 110 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA")); |
| 111 | expected.m_path.m_nodes.emplace_back(leaf_("leafInCont")); |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 112 | expected.m_data = std::string("data with\" a quote"); |
| 113 | } |
| 114 | |
| 115 | SECTION("set mod:contA/leafInCont 'more d\tata'") // spaces in string |
| 116 | { |
| 117 | input = "set mod:contA/leafInCont 'more d\tata'"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 118 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA")); |
| 119 | expected.m_path.m_nodes.emplace_back(leaf_("leafInCont")); |
Václav Kubernát | c18ffac | 2020-01-10 16:06:06 +0100 | [diff] [blame] | 120 | expected.m_data = std::string("more d\tata"); |
| 121 | } |
| 122 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 123 | SECTION("set mod:list[number=1]/leafInList \"another_data\"") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 124 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 125 | input = "set mod:list[number=1]/leafInList \"another_data\""; |
Václav Kubernát | c15fe82 | 2020-06-04 11:28:39 +0200 | [diff] [blame] | 126 | auto keys = ListInstance { |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 127 | {"number", int32_t{1}}}; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 128 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, listElement_("list", keys)); |
| 129 | expected.m_path.m_nodes.emplace_back(leaf_("leafInList")); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 130 | expected.m_data = std::string("another_data"); |
| 131 | } |
| 132 | |
| 133 | SECTION("data types") |
| 134 | { |
| 135 | SECTION("string") |
| 136 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 137 | input = "set mod:leafString \"somedata\""; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 138 | 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] | 139 | expected.m_data = std::string("somedata"); |
| 140 | } |
| 141 | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 142 | SECTION("int8") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 143 | { |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 144 | input = "set mod:leafInt8 2"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 145 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt8")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 146 | expected.m_data = int8_t{2}; |
| 147 | } |
| 148 | |
| 149 | SECTION("negative int8") |
| 150 | { |
| 151 | input = "set mod:leafInt8 -10"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 152 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt8")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 153 | expected.m_data = int8_t{-10}; |
| 154 | } |
| 155 | |
| 156 | SECTION("uint8") |
| 157 | { |
| 158 | input = "set mod:leafUint8 2"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 159 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint8")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 160 | expected.m_data = uint8_t{2}; |
| 161 | } |
| 162 | |
| 163 | SECTION("int16") |
| 164 | { |
| 165 | input = "set mod:leafInt16 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 166 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt16")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 167 | expected.m_data = int16_t{30'000}; |
| 168 | } |
| 169 | |
| 170 | SECTION("uint16") |
| 171 | { |
| 172 | input = "set mod:leafUint16 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 173 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint16")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 174 | expected.m_data = uint16_t{30'000}; |
| 175 | } |
| 176 | |
| 177 | SECTION("int32") |
| 178 | { |
| 179 | input = "set mod:leafInt32 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 180 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt32")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 181 | expected.m_data = int32_t{30'000}; |
| 182 | } |
| 183 | |
| 184 | SECTION("uint32") |
| 185 | { |
| 186 | input = "set mod:leafUint32 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 187 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint32")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 188 | expected.m_data = uint32_t{30'000}; |
| 189 | } |
| 190 | |
| 191 | SECTION("int32") |
| 192 | { |
| 193 | input = "set mod:leafInt32 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 194 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafInt32")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 195 | expected.m_data = int32_t{30'000}; |
| 196 | } |
| 197 | |
| 198 | SECTION("uint64") |
| 199 | { |
| 200 | input = "set mod:leafUint64 30000"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 201 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafUint64")); |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 202 | expected.m_data = uint64_t{30'000}; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | SECTION("decimal") |
| 206 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 207 | input = "set mod:leafDecimal 3.14159"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 208 | 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] | 209 | expected.m_data = 3.14159; |
| 210 | } |
| 211 | |
| 212 | SECTION("enum") |
| 213 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 214 | input = "set mod:leafEnum coze"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 215 | 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] | 216 | expected.m_data = enum_("coze"); |
| 217 | } |
| 218 | |
| 219 | SECTION("bool") |
| 220 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 221 | input = "set mod:leafBool true"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 222 | 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] | 223 | expected.m_data = true; |
| 224 | } |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 225 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 226 | SECTION("union") |
| 227 | { |
| 228 | SECTION("int") |
| 229 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 230 | 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] | 231 | input = "set mod:intOrString 90"; |
| 232 | expected.m_data = int32_t{90}; |
| 233 | } |
| 234 | SECTION("string") |
| 235 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 236 | 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] | 237 | input = "set mod:intOrString \"test\""; |
| 238 | expected.m_data = std::string{"test"}; |
| 239 | } |
| 240 | |
| 241 | SECTION("union with two integral types") |
| 242 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 243 | 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] | 244 | SECTION("uint8") |
| 245 | { |
| 246 | input = "set mod:twoInts 100"; |
| 247 | expected.m_data = uint8_t{100}; |
| 248 | } |
| 249 | SECTION("int16") |
| 250 | { |
| 251 | input = "set mod:twoInts 6666"; |
| 252 | expected.m_data = int16_t{6666}; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | SECTION("union with enum and leafref to enum") |
| 257 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 258 | 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] | 259 | SECTION("string") |
| 260 | { |
| 261 | input = "set mod:unionStringEnumLeafref \"AHOJ\""; |
| 262 | expected.m_data = std::string{"AHOJ"}; |
| 263 | } |
| 264 | SECTION("enum") |
| 265 | { |
| 266 | input = "set mod:unionStringEnumLeafref bar"; |
| 267 | expected.m_data = enum_("bar"); |
| 268 | } |
| 269 | SECTION("enum leafref") |
| 270 | { |
| 271 | input = "set mod:unionStringEnumLeafref coze"; |
| 272 | expected.m_data = enum_("coze"); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | SECTION("activePort") |
| 277 | { |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 278 | 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] | 279 | input = "set mod:activePort "; |
| 280 | SECTION("1. anonymous enum") |
| 281 | { |
| 282 | SECTION("wlan0") |
| 283 | { |
| 284 | input += "wlan0"; |
| 285 | expected.m_data = enum_("wlan0"); |
| 286 | } |
| 287 | SECTION("wlan1") |
| 288 | { |
| 289 | input += "wlan1"; |
| 290 | expected.m_data = enum_("wlan1"); |
| 291 | } |
| 292 | } |
| 293 | SECTION("2. leafref to enum") |
| 294 | { |
| 295 | SECTION("eth0") |
| 296 | { |
| 297 | input += "eth0"; |
| 298 | expected.m_data = enum_("eth0"); |
| 299 | } |
| 300 | SECTION("eth1") |
| 301 | { |
| 302 | input += "eth1"; |
| 303 | expected.m_data = enum_("eth1"); |
| 304 | } |
| 305 | SECTION("eth2") |
| 306 | { |
| 307 | input += "eth2"; |
| 308 | expected.m_data = enum_("eth2"); |
| 309 | } |
| 310 | } |
| 311 | SECTION("3. leafref to leafref") |
| 312 | { |
| 313 | SECTION("utf1") |
| 314 | { |
| 315 | input += "utf1"; |
| 316 | expected.m_data = enum_("utf1"); |
| 317 | } |
| 318 | SECTION("utf2") |
| 319 | { |
| 320 | input += "utf2"; |
| 321 | expected.m_data = enum_("utf2"); |
| 322 | } |
| 323 | SECTION("utf3") |
| 324 | { |
| 325 | input += "utf3"; |
| 326 | expected.m_data = enum_("utf3"); |
| 327 | } |
| 328 | } |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 329 | SECTION("4. empty") |
| 330 | { |
| 331 | expected.m_data = empty_{}; |
| 332 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 333 | } |
| 334 | } |
| 335 | |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 336 | SECTION("binary") |
| 337 | { |
| 338 | SECTION("zero ending '='") |
| 339 | { |
| 340 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++"; |
| 341 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++"}; |
| 342 | } |
| 343 | |
| 344 | SECTION("one ending '='") |
| 345 | { |
| 346 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++="; |
| 347 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++="}; |
| 348 | } |
| 349 | |
| 350 | SECTION("two ending '='") |
| 351 | { |
| 352 | input = "set mod:leafBinary This/IsABase64EncodedSomething++/342431++=="; |
| 353 | expected.m_data = binary_{"This/IsABase64EncodedSomething++/342431++=="}; |
| 354 | } |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 355 | 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] | 356 | } |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 357 | |
| 358 | SECTION("identityRef") |
| 359 | { |
| 360 | SECTION("foodIdentRef") |
| 361 | { |
| 362 | input = "set mod:foodIdentRef "; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 363 | 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] | 364 | |
| 365 | SECTION("food") |
| 366 | { |
| 367 | input += "food"; |
| 368 | expected.m_data = identityRef_("food"); |
| 369 | } |
| 370 | SECTION("mod:food") |
| 371 | { |
| 372 | input += "mod:food"; |
| 373 | expected.m_data = identityRef_("mod", "food"); |
| 374 | } |
| 375 | SECTION("pizza") |
| 376 | { |
| 377 | input += "pizza"; |
| 378 | expected.m_data = identityRef_("pizza"); |
| 379 | } |
| 380 | SECTION("mod:pizza") |
| 381 | { |
| 382 | input += "mod:pizza"; |
| 383 | expected.m_data = identityRef_("mod", "pizza"); |
| 384 | } |
| 385 | SECTION("pizza-module:hawaii") |
| 386 | { |
| 387 | input += "pizza-module:hawaii"; |
| 388 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 389 | } |
| 390 | } |
| 391 | SECTION("pizzaIdentRef") |
| 392 | { |
| 393 | input = "set mod:pizzaIdentRef "; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 394 | 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] | 395 | SECTION("pizza") |
| 396 | { |
| 397 | input += "pizza"; |
| 398 | expected.m_data = identityRef_("pizza"); |
| 399 | } |
| 400 | SECTION("mod:pizza") |
| 401 | { |
| 402 | input += "mod:pizza"; |
| 403 | expected.m_data = identityRef_("mod", "pizza"); |
| 404 | } |
| 405 | SECTION("pizza-module:hawaii") |
| 406 | { |
| 407 | input += "pizza-module:hawaii"; |
| 408 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 409 | } |
| 410 | } |
| 411 | SECTION("mod:contA/identInCont") |
| 412 | { |
| 413 | input = "set mod:contA/identInCont "; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 414 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, container_("contA")); |
| 415 | expected.m_path.m_nodes.emplace_back(leaf_("identInCont")); |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 416 | SECTION("pizza") |
| 417 | { |
| 418 | input += "pizza"; |
| 419 | expected.m_data = identityRef_("pizza"); |
| 420 | } |
| 421 | SECTION("mod:pizza") |
| 422 | { |
| 423 | input += "mod:pizza"; |
| 424 | expected.m_data = identityRef_("mod", "pizza"); |
| 425 | } |
| 426 | SECTION("pizza-module:hawaii") |
| 427 | { |
| 428 | input += "pizza-module:hawaii"; |
| 429 | expected.m_data = identityRef_("pizza-module", "hawaii"); |
| 430 | } |
| 431 | } |
| 432 | } |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 433 | SECTION("leafRef") |
| 434 | { |
| 435 | SECTION("refToString") |
| 436 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 437 | input = "set mod:refToString \"blabal\""; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 438 | 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] | 439 | expected.m_data = std::string("blabal"); |
| 440 | } |
| 441 | |
| 442 | SECTION("refToInt8") |
| 443 | { |
| 444 | input = "set mod:refToInt8 42"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 445 | 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] | 446 | expected.m_data = int8_t{42}; |
| 447 | } |
Václav Kubernát | 2d7b05c | 2020-04-05 14:02:37 +0200 | [diff] [blame] | 448 | |
| 449 | SECTION("refToLeafInCont") |
| 450 | { |
| 451 | input = "set mod:refToLeafInCont pizza"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 452 | 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] | 453 | expected.m_data = identityRef_{"pizza"}; |
| 454 | } |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 455 | } |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 456 | SECTION("empty") |
| 457 | { |
| 458 | input = "set mod:dummy "; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 459 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("dummy")); |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 460 | expected.m_data = empty_{}; |
| 461 | } |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 462 | |
| 463 | SECTION("bits") |
| 464 | { |
| 465 | input = "set mod:flags "; |
| 466 | decltype(bits_::m_bits) bits; |
| 467 | SECTION("<nothing>") { |
| 468 | bits = {}; |
| 469 | } |
| 470 | SECTION("carry") { |
| 471 | input += "carry"; |
| 472 | bits = {"carry"}; |
| 473 | } |
| 474 | SECTION("sign") { |
| 475 | input += "sign"; |
| 476 | bits = {"sign"}; |
| 477 | } |
| 478 | SECTION("carry sign") { |
| 479 | input += "carry sign"; |
| 480 | bits = {"carry", "sign"}; |
| 481 | } |
| 482 | SECTION("sign carry") { |
| 483 | input += "sign carry"; |
| 484 | bits = {"sign", "carry"}; |
| 485 | } |
| 486 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("flags")); |
| 487 | expected.m_data = bits_{bits}; |
| 488 | } |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | command_ command = parser.parseCommand(input, errorStream); |
| 492 | REQUIRE(command.type() == typeid(set_)); |
| 493 | REQUIRE(boost::get<set_>(command) == expected); |
| 494 | } |
| 495 | |
| 496 | SECTION("invalid input") |
| 497 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 498 | std::string expectedError; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 499 | SECTION("missing space between a command and its arguments") |
| 500 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 501 | SECTION("setmod:leafString some_data") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 502 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 503 | input = "setmod:leafString 'some_data'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
| 507 | SECTION("missing space between arguments") |
| 508 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 509 | SECTION("set mod:leafString'lol'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 510 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 511 | input = "set mod:leafString'lol'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
| 515 | SECTION("non-leaf identifiers") |
| 516 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 517 | SECTION("set mod:nonexistent 'blabla'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 518 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 519 | input = "set mod:nonexistent 'blabla'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 520 | } |
| 521 | |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 522 | SECTION("set mod:contA 'abde'") |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 523 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 524 | input = "set mod:contA 'abde'"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 528 | SECTION("wrong types") |
| 529 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 530 | expectedError = "leaf data type mismatch"; |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 531 | SECTION("set mod:leafBool 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 532 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 533 | input = "set mod:leafBool 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 534 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 535 | SECTION("set mod:leafUint8 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 536 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 537 | input = "set mod:leafUint8 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 538 | } |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 539 | SECTION("set mod:leafUint8 -5") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 540 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 541 | input = "set mod:leafUint8 -5"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 542 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 543 | SECTION("set mod:leafInt8 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 544 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 545 | input = "set mod:leafInt8 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 546 | } |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 547 | SECTION("set mod:leafInt8 130") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 548 | { |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 549 | input = "set mod:leafInt8 130"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 550 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 551 | SECTION("set mod:leafUint16 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 552 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 553 | input = "set mod:leafUint16 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 554 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 555 | SECTION("set mod:leafInt16 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 556 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 557 | input = "set mod:leafInt16 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 558 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 559 | SECTION("set mod:leafUint32 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 560 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 561 | input = "set mod:leafUint32 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 562 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 563 | SECTION("set mod:leafInt32 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 564 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 565 | input = "set mod:leafInt32 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 566 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 567 | SECTION("set mod:leafUint64 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 568 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 569 | input = "set mod:leafUint64 'blabla'"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 570 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 571 | SECTION("set mod:leafInt64 'blabla'") |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 572 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 573 | input = "set mod:leafInt64 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 574 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 575 | SECTION("set mod:leafEnum 'blabla'") |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 576 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 577 | input = "set mod:leafEnum 'blabla'"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 578 | } |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 579 | SECTION("set mod:refToInt8 'blabla'") |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 580 | { |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 581 | input = "set mod:refToInt8 'blabla'"; |
Václav Kubernát | 6a8d1d9 | 2019-04-24 20:30:36 +0200 | [diff] [blame] | 582 | } |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 583 | } |
| 584 | |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 585 | SECTION("wrong base64 strings") |
| 586 | { |
| 587 | SECTION("invalid character") |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 588 | input = "set mod:leafBinary dbahj-"; |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 589 | SECTION("equal sign in the middle") |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 590 | input = "set mod:leafBinary db=ahj"; |
Václav Kubernát | 1bbac7c | 2020-01-15 17:45:41 +0100 | [diff] [blame] | 591 | SECTION("enclosing in quotes") |
| 592 | input = "set mod:leafBinary 'dbahj'"; |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 593 | } |
| 594 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 595 | SECTION("non-existing identity") |
| 596 | { |
| 597 | input = "set mod:foodIdentRef identityBLABLA"; |
| 598 | } |
| 599 | |
Václav Kubernát | f365ecf | 2020-06-09 16:22:43 +0200 | [diff] [blame] | 600 | SECTION("identity with non-existing module") |
| 601 | { |
| 602 | expectedError = "Invalid module name"; |
| 603 | input = "set mod:foodIdentRef xd:haha"; |
| 604 | } |
| 605 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 606 | SECTION("setting identities with wrong bases") |
| 607 | { |
| 608 | SECTION("set mod:foodIdentRef mod:vehicle") |
| 609 | { |
| 610 | input = "set mod:foodIdentRef mod:vehicle"; |
| 611 | } |
| 612 | SECTION("set mod:pizzaIdentRef mod:food") |
| 613 | { |
| 614 | input = "set mod:pizzaIdentRef mod:food"; |
| 615 | } |
| 616 | } |
| 617 | SECTION("setting different module identities without prefix") |
| 618 | { |
| 619 | input = "set mod:pizzaIdentRef hawaii"; |
| 620 | } |
| 621 | SECTION("identity prefix without name") |
| 622 | { |
| 623 | input = "set mod:contA/identInCont pizza-module:"; |
| 624 | } |
| 625 | |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame] | 626 | SECTION("set a union path to a wrong type") |
| 627 | { |
| 628 | input = "set mod:intOrString true"; |
| 629 | } |
| 630 | |
Jan Kundrát | 379bb57 | 2020-05-07 03:23:13 +0200 | [diff] [blame] | 631 | SECTION("no space for empty data") |
| 632 | { |
| 633 | input = "set mod:dummy"; |
| 634 | } |
| 635 | |
Václav Kubernát | 0d42c51 | 2020-05-20 21:18:39 +0200 | [diff] [blame] | 636 | SECTION("empty path") |
| 637 | { |
| 638 | input = "set "; |
| 639 | } |
| 640 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 641 | SECTION("setting readonly data") |
| 642 | { |
| 643 | input = "set mod:readonly 123"; |
| 644 | } |
| 645 | |
Václav Kubernát | dab73ca | 2020-10-26 23:44:43 +0100 | [diff] [blame] | 646 | SECTION("nonexistent bits") |
| 647 | { |
| 648 | input = "set mod:flags daw"; |
| 649 | } |
| 650 | |
| 651 | SECTION("same bit more than once") |
| 652 | { |
| 653 | input = "set mod:flags carry carry"; |
| 654 | } |
| 655 | |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 656 | REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException); |
Václav Kubernát | 777704d | 2020-01-15 18:48:06 +0100 | [diff] [blame] | 657 | REQUIRE(errorStream.str().find(expectedError) != std::string::npos); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 658 | } |
Jan Kundrát | b7206ad | 2020-06-18 21:08:14 +0200 | [diff] [blame] | 659 | |
| 660 | SECTION("deleting a leaf") |
| 661 | { |
| 662 | delete_ expected; |
| 663 | input = "delete mod:leafString"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 664 | expected.m_path.m_nodes.emplace_back(module_{"mod"}, leaf_("leafString")); |
Jan Kundrát | b7206ad | 2020-06-18 21:08:14 +0200 | [diff] [blame] | 665 | |
| 666 | command_ command = parser.parseCommand(input, errorStream); |
| 667 | REQUIRE(command.type() == typeid(delete_)); |
| 668 | REQUIRE(boost::get<delete_>(command) == expected); |
| 669 | } |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 670 | } |