Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [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" |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 10 | #include "ast_commands.hpp" |
Václav Kubernát | 0af7257 | 2020-07-22 15:15:59 +0200 | [diff] [blame] | 11 | #include "leaf_data_helpers.hpp" |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 12 | #include "parser.hpp" |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 13 | #include "pretty_printers.hpp" |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 14 | #include "static_schema.hpp" |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 15 | |
| 16 | TEST_CASE("cd") |
| 17 | { |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 18 | auto schema = std::make_shared<StaticSchema>(); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 19 | schema->addModule("example"); |
| 20 | schema->addModule("second"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 21 | schema->addContainer("/", "example:a"); |
| 22 | schema->addContainer("/", "second:a"); |
| 23 | schema->addContainer("/", "example:b"); |
| 24 | schema->addContainer("/example:a", "example:a2"); |
| 25 | schema->addContainer("/example:b", "example:b2"); |
| 26 | schema->addContainer("/example:a/example:a2", "example:a3"); |
| 27 | schema->addContainer("/example:b/example:b2", "example:b3"); |
| 28 | schema->addList("/", "example:list", {"number"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 29 | schema->addLeaf("/example:list", "example:number", yang::Int32{}); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 30 | schema->addContainer("/example:list", "example:contInList"); |
| 31 | schema->addList("/", "example:twoKeyList", {"number", "name"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 32 | schema->addLeaf("/example:twoKeyList", "example:number", yang::Int32{}); |
| 33 | schema->addLeaf("/example:twoKeyList", "example:name", yang::String{}); |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 34 | schema->addRpc("/", "example:launch-nukes"); |
Václav Kubernát | 0af7257 | 2020-07-22 15:15:59 +0200 | [diff] [blame] | 35 | schema->addList("/", "example:ports", {"name"}); |
| 36 | schema->addLeaf("/example:ports", "example:name", createEnum({"A", "B", "C"})); |
Václav Kubernát | 0d47e5e | 2020-11-17 12:27:05 +0100 | [diff] [blame] | 37 | schema->addLeaf("/", "example:myLeaf", yang::Int32{}); |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 38 | Parser parser(schema); |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 39 | std::string input; |
Václav Kubernát | 2315c73 | 2018-05-16 20:25:55 +0200 | [diff] [blame] | 40 | std::ostringstream errorStream; |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 41 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 42 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 43 | SECTION("valid input") |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 44 | { |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 45 | cd_ expected; |
| 46 | |
| 47 | SECTION("container") |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 48 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 49 | SECTION("example:a") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 50 | { |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 51 | SECTION("trailing slash") |
| 52 | { |
| 53 | input = "cd example:a/"; |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 54 | } |
| 55 | SECTION("no trailing slash") |
| 56 | { |
| 57 | input = "cd example:a"; |
| 58 | } |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 59 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("a")); |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 60 | } |
| 61 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 62 | SECTION("second:a") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 63 | { |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 64 | SECTION("trailing slash") |
| 65 | { |
| 66 | input = "cd second:a/"; |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 67 | } |
| 68 | SECTION("no trailing slash") |
| 69 | { |
| 70 | input = "cd second:a"; |
| 71 | } |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 72 | expected.m_path.m_nodes.emplace_back(module_{"second"}, container_("a")); |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 75 | SECTION("example:b") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 76 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 77 | input = "cd example:b"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 78 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("b")); |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 81 | SECTION("example:a/a2") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 82 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 83 | input = "cd example:a/a2"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 84 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("a")); |
| 85 | expected.m_path.m_nodes.emplace_back(container_("a2")); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | SECTION("example:a/example:a2") |
| 89 | { |
| 90 | input = "cd example:a/example:a2"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 91 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("a")); |
| 92 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("a2")); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | SECTION("example:b/b2") |
| 96 | { |
| 97 | input = "cd example:b/b2"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 98 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("b")); |
| 99 | expected.m_path.m_nodes.emplace_back(container_("b2")); |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 100 | } |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 103 | SECTION("list elements") |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 104 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 105 | SECTION("example:list[number=1]") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 106 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 107 | input = "cd example:list[number=1]"; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 108 | auto keys = ListInstance{ |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 109 | {"number", int32_t{1}}}; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 110 | expected.m_path.m_nodes.emplace_back(module_{"example"}, listElement_("list", keys)); |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 113 | SECTION("example:list[number=1]/contInList") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 114 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 115 | input = "cd example:list[number=1]/contInList"; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 116 | auto keys = ListInstance{ |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 117 | {"number", int32_t{1}}}; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 118 | expected.m_path.m_nodes.emplace_back(module_{"example"}, listElement_("list", keys)); |
| 119 | expected.m_path.m_nodes.emplace_back(container_("contInList")); |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 122 | SECTION("example:twoKeyList[number=4][name='abcd']") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 123 | { |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 124 | input = "cd example:twoKeyList[number=4][name='abcd']"; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 125 | auto keys = ListInstance{ |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 126 | {"number", int32_t{4}}, |
| 127 | {"name", std::string{"abcd"}}}; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 128 | expected.m_path.m_nodes.emplace_back(module_{"example"}, listElement_("twoKeyList", keys)); |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 129 | } |
Václav Kubernát | 0af7257 | 2020-07-22 15:15:59 +0200 | [diff] [blame] | 130 | |
| 131 | SECTION("enum key type") |
| 132 | { |
| 133 | input = "cd example:ports[name=A]"; |
Václav Kubernát | b4e5b18 | 2020-11-16 19:55:09 +0100 | [diff] [blame] | 134 | auto keys = ListInstance{ |
Václav Kubernát | 0af7257 | 2020-07-22 15:15:59 +0200 | [diff] [blame] | 135 | {"name", enum_{"A"}}}; |
| 136 | expected.m_path.m_nodes.emplace_back(module_{"example"}, listElement_("ports", keys)); |
| 137 | } |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 138 | } |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 139 | |
| 140 | SECTION("whitespace handling") |
| 141 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 142 | SECTION(" cd example:a ") |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 143 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 144 | input = " cd example:a "; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 145 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("a")); |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 149 | SECTION("moving up") |
| 150 | { |
Václav Kubernát | c2bfe49 | 2020-06-15 13:19:07 +0200 | [diff] [blame] | 151 | SECTION("moving up when already in root") |
| 152 | { |
| 153 | input = "cd .."; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 154 | expected.m_path.m_nodes.emplace_back(nodeup_()); |
Václav Kubernát | c2bfe49 | 2020-06-15 13:19:07 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | SECTION("moving up TWICE when already in root") |
| 158 | { |
| 159 | input = "cd ../.."; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 160 | expected.m_path.m_nodes.emplace_back(nodeup_()); |
| 161 | expected.m_path.m_nodes.emplace_back(nodeup_()); |
Václav Kubernát | c2bfe49 | 2020-06-15 13:19:07 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 164 | SECTION("example:a/..") |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 165 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 166 | input = "cd example:a/.."; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 167 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("a")); |
| 168 | expected.m_path.m_nodes.emplace_back(nodeup_()); |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 169 | } |
| 170 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 171 | SECTION("example:a/../example:a") |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 172 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 173 | input = "cd example:a/../example:a"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 174 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("a")); |
| 175 | expected.m_path.m_nodes.emplace_back(nodeup_()); |
| 176 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("a")); |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 179 | SECTION("example:a/../example:a/a2") |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 180 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 181 | input = "cd example:a/../example:a/a2"; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 182 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("a")); |
| 183 | expected.m_path.m_nodes.emplace_back(nodeup_()); |
| 184 | expected.m_path.m_nodes.emplace_back(module_{"example"}, container_("a")); |
| 185 | expected.m_path.m_nodes.emplace_back(container_("a2")); |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 189 | command_ command = parser.parseCommand(input, errorStream); |
| 190 | REQUIRE(command.type() == typeid(cd_)); |
| 191 | REQUIRE(boost::get<cd_>(command) == expected); |
Václav Kubernát | 39f83f5 | 2021-02-19 02:52:08 +0100 | [diff] [blame] | 192 | // Converting the path back to a string should never result with a path with a trailing slash, even if the |
| 193 | // original input string has it. |
| 194 | REQUIRE(pathToDataString(boost::get<cd_>(command).m_path, Prefixes::WhenNeeded).back() != '/'); |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 195 | } |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 196 | SECTION("invalid input") |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 197 | { |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 198 | SECTION("missing space between a command and its arguments") |
| 199 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 200 | SECTION("cdexample:a") |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 201 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 202 | input = "cdexample:a"; |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 203 | } |
| 204 | } |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 205 | |
| 206 | SECTION("whitespace between module and nodename") |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 207 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 208 | SECTION("cd example: a") |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 209 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 210 | input = "cd example: a"; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 211 | } |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 212 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 213 | SECTION("cd example : a") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 214 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 215 | input = "cd example : a"; |
| 216 | } |
| 217 | |
| 218 | SECTION("cd example :a") |
| 219 | { |
| 220 | input = "cd example :a"; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | SECTION("entering modules") |
| 225 | { |
| 226 | SECTION("cd example") |
| 227 | { |
| 228 | input = "cd example"; |
| 229 | } |
| 230 | |
| 231 | SECTION("cd example:") |
| 232 | { |
| 233 | input = "cd example:"; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | SECTION("garbage arguments handling") |
| 238 | { |
| 239 | SECTION("cd example:a garbage") |
| 240 | { |
| 241 | input = "cd example:a garbage"; |
| 242 | } |
| 243 | SECTION("cd example:a/a2 garbage") |
| 244 | { |
| 245 | input = "cd example:a/a2 garbage"; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | SECTION("invalid node identifiers") |
| 250 | { |
| 251 | SECTION("example:nonexistent") |
| 252 | { |
| 253 | input = "cd example:nonexistent"; |
| 254 | } |
| 255 | |
| 256 | SECTION("example:nonexistent/lol") |
| 257 | { |
| 258 | input = "cd example:nonexistent/lol"; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | SECTION("invalid module identifiers") |
| 263 | { |
| 264 | SECTION("elpmaxe:nonexistent") |
| 265 | { |
| 266 | input = "cd elpmaxe:nonexistent"; |
| 267 | } |
| 268 | |
| 269 | SECTION("elpmaxe:nonexistent/example:lol") |
| 270 | { |
| 271 | input = "cd elpmaxe:nonexistent/example:lol"; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | SECTION("no top-level module") |
| 276 | { |
| 277 | SECTION("cd a") |
| 278 | { |
| 279 | input = "cd a"; |
| 280 | } |
| 281 | |
| 282 | SECTION("cd example:a/../a") |
| 283 | { |
| 284 | input = "cd example:a/../a"; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 285 | } |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 286 | } |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 287 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 288 | SECTION("invalid list key identifiers") |
| 289 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 290 | SECTION("example:list") |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 291 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 292 | input = "cd example:list"; |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 295 | SECTION("example:list[]") |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 296 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 297 | input = "cd example:list[]"; |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 298 | } |
| 299 | |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 300 | SECTION("example:twoKeyList[invalidKey='4']") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 301 | { |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 302 | input = "cd example:twoKeyList[invalidKey='4']"; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 303 | } |
| 304 | |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 305 | SECTION("example:twoKeyList[number=4][number=5]") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 306 | { |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 307 | input = "cd example:twoKeyList[number=4][number=5]"; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 310 | SECTION("example:twoKeyList[number=4][name='lol'][number=7]") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 311 | { |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 312 | input = "cd example:twoKeyList[number=4][name='lol'][number=7]"; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 315 | SECTION("example:twoKeyList[number=4]") |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 316 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 317 | input = "cd example:twoKeyList[number=4]"; |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 318 | } |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 319 | |
| 320 | SECTION("strings must be quoted") |
| 321 | { |
| 322 | input = "cd example:twoKeyList[number=4][name=abcd]"; |
| 323 | } |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 324 | } |
Václav Kubernát | 9fa5dca | 2020-06-01 03:56:41 +0200 | [diff] [blame] | 325 | |
| 326 | SECTION("no space between list prefix and suffix") |
| 327 | { |
| 328 | input = "cd example:list [number=10]"; |
| 329 | } |
| 330 | |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 331 | SECTION("cd into rpc") |
| 332 | { |
| 333 | input = "cd example:launch-nukes"; |
| 334 | } |
| 335 | |
Václav Kubernát | 0d47e5e | 2020-11-17 12:27:05 +0100 | [diff] [blame] | 336 | SECTION("cd into a leaf") |
| 337 | { |
| 338 | input = "cd example:myLeaf"; |
| 339 | } |
| 340 | |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 341 | REQUIRE_THROWS_AS(parser.parseCommand(input, errorStream), InvalidCommandException); |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 342 | } |
| 343 | } |