Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +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 | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 10 | #include "datastoreaccess_mock.hpp" |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 11 | #include "parser.hpp" |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 12 | #include "pretty_printers.hpp" |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 13 | #include "static_schema.hpp" |
| 14 | |
| 15 | TEST_CASE("path_completion") |
| 16 | { |
| 17 | auto schema = std::make_shared<StaticSchema>(); |
| 18 | schema->addModule("example"); |
| 19 | schema->addModule("second"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 20 | schema->addContainer("/", "example:ano"); |
| 21 | schema->addContainer("/", "example:anoda"); |
| 22 | schema->addList("/example:ano", "example:listInCont", {"number"}); |
| 23 | schema->addContainer("/", "second:amelie"); |
| 24 | schema->addContainer("/", "example:bota"); |
| 25 | schema->addContainer("/example:ano", "example:a2"); |
| 26 | schema->addContainer("/example:bota", "example:b2"); |
| 27 | schema->addContainer("/example:ano/example:a2", "example:a3"); |
| 28 | schema->addContainer("/example:bota/example:b2", "example:b3"); |
| 29 | schema->addList("/", "example:list", {"number"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 30 | schema->addLeaf("/example:list", "example:number", yang::Int32{}); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 31 | schema->addContainer("/example:list", "example:contInList"); |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 32 | schema->addList("/", "example:ovoce", {"name"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 33 | schema->addLeaf("/example:ovoce", "example:name", yang::String{}); |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 34 | schema->addList("/", "example:ovocezelenina", {"name"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 35 | schema->addLeaf("/example:ovocezelenina", "example:name", yang::String{}); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 36 | schema->addList("/", "example:twoKeyList", {"number", "name"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 37 | schema->addLeaf("/example:twoKeyList", "example:name", yang::String{}); |
| 38 | schema->addLeaf("/example:twoKeyList", "example:number", yang::Int32{}); |
| 39 | schema->addLeaf("/", "example:leafInt", yang::Int32{}); |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 40 | schema->addLeaf("/", "example:readonly", yang::Int32{}, yang::AccessType::ReadOnly); |
Václav Kubernát | 743d9eb | 2020-05-18 13:42:36 +0200 | [diff] [blame] | 41 | schema->addLeafList("/", "example:addresses", yang::String{}); |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 42 | schema->addRpc("/", "second:fire"); |
| 43 | schema->addLeaf("/second:fire", "second:whom", yang::String{}); |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 44 | schema->addContainer("/", "example:system"); |
| 45 | schema->addContainer("/example:system", "example:thing"); |
| 46 | schema->addContainer("/", "example:system-state"); |
Jan Kundrát | bb7aa85 | 2023-08-30 11:51:43 +0200 | [diff] [blame] | 47 | schema->addLeaf("/example:anoda", "example:iid", yang::InstanceIdentifier{}); |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 48 | auto mockDatastore = std::make_shared<MockDatastoreAccess>(); |
| 49 | |
| 50 | // The parser will use DataQuery for key value completion, but I'm not testing that here, so I don't return anything. |
| 51 | ALLOW_CALL(*mockDatastore, listInstances("/example:list")) |
| 52 | .RETURN(std::vector<ListInstance>{}); |
| 53 | ALLOW_CALL(*mockDatastore, listInstances("/example:twoKeyList")) |
| 54 | .RETURN(std::vector<ListInstance>{}); |
| 55 | |
| 56 | // DataQuery gets the schema from DatastoreAccess once |
| 57 | auto expectation = NAMED_REQUIRE_CALL(*mockDatastore, schema()) |
| 58 | .RETURN(schema); |
| 59 | auto dataQuery = std::make_shared<DataQuery>(*mockDatastore); |
| 60 | expectation.reset(); |
Václav Kubernát | 28cf336 | 2020-06-29 17:52:51 +0200 | [diff] [blame] | 61 | Parser parser(schema, WritableOps::No, dataQuery); |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 62 | std::string input; |
| 63 | std::ostringstream errorStream; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 64 | |
| 65 | std::set<std::string> expectedCompletions; |
| 66 | // GCC complains here with -Wmaybe-uninitialized if I don't assign |
| 67 | // something here. I suspect it's because of nested SECTIONs. -1 is an |
| 68 | // invalid value (as in, I'll never expect expectedContextLength to be -1), |
| 69 | // so let's go with that. |
| 70 | int expectedContextLength = -1; |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 71 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 72 | SECTION("node name completion") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 73 | { |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 74 | SECTION("ls ") |
| 75 | { |
| 76 | input = "ls "; |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 77 | expectedCompletions = {"example:addresses/", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list/", "example:ovoce/", "example:readonly ", "example:ovocezelenina/", "example:twoKeyList/", "second:amelie/", "second:fire/", "example:system/", "example:system-state/"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 78 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | SECTION("ls e") |
| 82 | { |
| 83 | input = "ls e"; |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 84 | expectedCompletions = {"example:addresses/", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list/", "example:ovoce/", "example:readonly ", "example:ovocezelenina/", "example:twoKeyList/", "example:system/", "example:system-state/"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 85 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | SECTION("ls example:ano") |
| 89 | { |
| 90 | input = "ls example:ano"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 91 | expectedCompletions = {"example:ano/", "example:anoda/"}; |
| 92 | expectedContextLength = 11; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 95 | SECTION("ls example:ano/a") |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 96 | { |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 97 | input = "ls example:ano/a"; |
| 98 | expectedCompletions = {"a2/"}; |
| 99 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | SECTION("ls x") |
| 103 | { |
| 104 | input = "ls x"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 105 | expectedCompletions = {}; |
| 106 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | SECTION("ls /") |
| 110 | { |
| 111 | input = "ls /"; |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 112 | expectedCompletions = {"example:addresses/", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list/", "example:ovoce/", "example:readonly ", "example:ovocezelenina/", "example:twoKeyList/", "second:amelie/", "second:fire/", "example:system/", "example:system-state/"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 113 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | SECTION("ls /e") |
| 117 | { |
| 118 | input = "ls /e"; |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 119 | expectedCompletions = {"example:addresses/", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list/", "example:ovoce/", "example:readonly ", "example:ovocezelenina/", "example:twoKeyList/", "example:system/", "example:system-state/"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 120 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 121 | } |
| 122 | |
Václav Kubernát | e69133a | 2019-11-01 19:01:34 +0100 | [diff] [blame] | 123 | SECTION("ls example:bota") |
| 124 | { |
| 125 | input = "ls example:bota"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 126 | expectedCompletions = {"example:bota/"}; |
| 127 | expectedContextLength = 12; |
Václav Kubernát | e69133a | 2019-11-01 19:01:34 +0100 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | SECTION("ls /example:bota") |
| 131 | { |
| 132 | input = "ls /example:bota"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 133 | expectedCompletions = {"example:bota/"}; |
| 134 | expectedContextLength = 12; |
Václav Kubernát | e69133a | 2019-11-01 19:01:34 +0100 | [diff] [blame] | 135 | } |
| 136 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 137 | SECTION("ls /s") |
| 138 | { |
| 139 | input = "ls /s"; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 140 | expectedCompletions = {"second:amelie/", "second:fire/"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 141 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 142 | } |
| 143 | |
Václav Kubernát | 743d9eb | 2020-05-18 13:42:36 +0200 | [diff] [blame] | 144 | SECTION("ls /example:list") |
| 145 | { |
| 146 | input = "ls /example:list"; |
| 147 | expectedCompletions = {"example:list/"}; |
| 148 | expectedContextLength = 12; |
| 149 | } |
| 150 | |
Václav Kubernát | 26be33a | 2020-02-13 13:30:14 +0100 | [diff] [blame] | 151 | SECTION("ls /example:list/") |
| 152 | { |
| 153 | input = "ls /example:list/"; |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 154 | expectedCompletions = {"contInList/", "number "}; |
Václav Kubernát | 26be33a | 2020-02-13 13:30:14 +0100 | [diff] [blame] | 155 | expectedContextLength = 0; |
| 156 | } |
| 157 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 158 | SECTION("ls /example:list[number=3]/") |
| 159 | { |
| 160 | input = "ls /example:list[number=3]/"; |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 161 | expectedCompletions = {"contInList/", "number "}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 162 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | SECTION("ls /example:list[number=3]/c") |
| 166 | { |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 167 | input = "ls /example:list[number=3]/c"; |
| 168 | expectedCompletions = {"contInList/"}; |
| 169 | expectedContextLength = 1; |
| 170 | } |
| 171 | |
| 172 | SECTION("ls /example:list[number=3]/n") |
| 173 | { |
| 174 | input = "ls /example:list[number=3]/n"; |
| 175 | expectedCompletions = {"number "}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 176 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | SECTION("ls /example:list[number=3]/a") |
| 180 | { |
| 181 | input = "ls /example:list[number=3]/a"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 182 | expectedCompletions = {}; |
| 183 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 184 | } |
Václav Kubernát | 26be33a | 2020-02-13 13:30:14 +0100 | [diff] [blame] | 185 | |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 186 | SECTION("ls /example:list/contInList/") |
Václav Kubernát | 26be33a | 2020-02-13 13:30:14 +0100 | [diff] [blame] | 187 | { |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 188 | input = "ls /example:list/contInList/"; |
Václav Kubernát | 26be33a | 2020-02-13 13:30:14 +0100 | [diff] [blame] | 189 | expectedCompletions = {}; |
| 190 | expectedContextLength = 0; |
| 191 | } |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 192 | |
| 193 | SECTION("ls /example:system-") |
| 194 | { |
| 195 | input = "ls /example:system-"; |
| 196 | expectedCompletions = {"example:system-state/"}; |
| 197 | expectedContextLength = 15; |
| 198 | } |
Jan Kundrát | bb7aa85 | 2023-08-30 11:51:43 +0200 | [diff] [blame] | 199 | |
| 200 | SECTION("set example:anoda/iid ") |
| 201 | { |
| 202 | input = "set example:anoda/iid "; |
| 203 | expectedCompletions = {"/"}; |
| 204 | expectedContextLength = 0; |
| 205 | } |
| 206 | |
| 207 | SECTION("set example:anoda/iid /") |
| 208 | { |
| 209 | input = "set example:anoda/iid /"; |
| 210 | expectedCompletions = { |
| 211 | "example:addresses", |
| 212 | "example:ano/", |
| 213 | "example:anoda/", |
| 214 | "example:bota/", |
| 215 | "example:leafInt ", |
| 216 | "example:list", |
| 217 | "example:ovoce", |
| 218 | "example:ovocezelenina", |
| 219 | "example:readonly ", |
| 220 | "example:system-state/", |
| 221 | "example:system/", |
| 222 | "example:twoKeyList", |
| 223 | "second:amelie/", |
| 224 | "second:fire/", |
| 225 | }; |
| 226 | expectedContextLength = 0; |
| 227 | } |
| 228 | |
| 229 | SECTION("set example:anoda/iid /example:read") |
| 230 | { |
| 231 | input = "set example:anoda/iid /example:read"; |
| 232 | expectedCompletions = {"example:readonly "}; |
| 233 | expectedContextLength = 12; |
| 234 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Václav Kubernát | 7eb4715 | 2020-11-12 16:57:03 +0100 | [diff] [blame] | 237 | SECTION("get completion") |
| 238 | { |
| 239 | SECTION("get /example:ano/l") |
| 240 | { |
| 241 | input = "get /example:ano/l"; |
| 242 | expectedCompletions = {"listInCont"}; |
| 243 | expectedContextLength = 1; |
| 244 | } |
Václav Kubernát | 85ba738 | 2020-11-18 18:11:18 +0100 | [diff] [blame] | 245 | |
| 246 | SECTION("get /example:list/") |
| 247 | { |
| 248 | input = "get /example:list/"; |
| 249 | expectedCompletions = {}; |
| 250 | // The expectedContextLength is 13, because the completion isn't actually generated after the slash. |
| 251 | expectedContextLength = 13; |
| 252 | } |
Václav Kubernát | e066fe2 | 2022-04-06 00:32:26 +0200 | [diff] [blame] | 253 | |
| 254 | SECTION("get -") |
| 255 | { |
| 256 | input = "get -"; |
| 257 | expectedCompletions = {"-datastore "}; |
| 258 | expectedContextLength = 0; |
| 259 | } |
| 260 | |
| 261 | SECTION("get --datastore ") |
| 262 | { |
| 263 | input = "get --datastore "; |
| 264 | expectedCompletions = {"operational", "running", "startup"}; |
| 265 | expectedContextLength = 0; |
| 266 | } |
| 267 | |
| 268 | SECTION("get --datastore running /second") |
| 269 | { |
| 270 | input = "get --datastore running /second"; |
| 271 | expectedCompletions = {"second:amelie/"}; |
| 272 | expectedContextLength = 6; |
| 273 | } |
Václav Kubernát | 7eb4715 | 2020-11-12 16:57:03 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Václav Kubernát | 3200b86 | 2020-12-03 02:34:55 +0100 | [diff] [blame] | 276 | SECTION("describe completion") |
| 277 | { |
| 278 | SECTION("path with list at the end") |
| 279 | { |
| 280 | input = "describe /example:list/"; |
| 281 | expectedCompletions = {"contInList/", "number "}; |
| 282 | expectedContextLength = 0; |
| 283 | } |
| 284 | } |
| 285 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 286 | SECTION("list keys completion") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 287 | { |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 288 | SECTION("cd example:lis") |
| 289 | { |
| 290 | input = "cd example:lis"; |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 291 | expectedCompletions = {"example:list"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 292 | expectedContextLength = 11; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 293 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 294 | |
Václav Kubernát | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 295 | SECTION("set example:list") |
| 296 | { |
| 297 | input = "set example:list"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 298 | expectedCompletions = {"example:list["}; |
| 299 | expectedContextLength = 12; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | SECTION("cd example:list") |
| 303 | { |
| 304 | input = "cd example:list"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 305 | expectedCompletions = {"example:list["}; |
| 306 | expectedContextLength = 12; |
Václav Kubernát | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 307 | } |
| 308 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 309 | SECTION("cd example:list[") |
| 310 | { |
| 311 | input = "cd example:list["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 312 | expectedCompletions = {"number="}; |
| 313 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 314 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 315 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 316 | SECTION("cd example:list[numb") |
| 317 | { |
| 318 | input = "cd example:list[numb"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 319 | expectedCompletions = {"number="}; |
| 320 | expectedContextLength = 4; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 321 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 322 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 323 | SECTION("cd example:list[number") |
| 324 | { |
| 325 | input = "cd example:list[number"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 326 | expectedCompletions = {"number="}; |
| 327 | expectedContextLength = 6; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 328 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 329 | |
Václav Kubernát | 117f7b5 | 2020-01-23 16:10:55 +0100 | [diff] [blame] | 330 | SECTION("cd example:list[number=") |
| 331 | { |
| 332 | input = "cd example:list[number="; |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 333 | expectedCompletions = {}; |
| 334 | expectedContextLength = 0; |
Václav Kubernát | 117f7b5 | 2020-01-23 16:10:55 +0100 | [diff] [blame] | 335 | } |
| 336 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 337 | SECTION("cd example:list[number=12") |
| 338 | { |
| 339 | input = "cd example:list[number=12"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 340 | expectedCompletions = {"]/"}; |
| 341 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 342 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 343 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 344 | SECTION("cd example:list[number=12]") |
| 345 | { |
| 346 | input = "cd example:list[number=12]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 347 | expectedCompletions = {"]/"}; |
| 348 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 349 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 350 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 351 | SECTION("cd example:twoKeyList[") |
| 352 | { |
| 353 | input = "cd example:twoKeyList["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 354 | expectedCompletions = {"name=", "number="}; |
| 355 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 356 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 357 | |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 358 | SECTION("cd example:twoKeyList[name=\"AHOJ\"") |
| 359 | { |
| 360 | input = "cd example:twoKeyList[name=\"AHOJ\""; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 361 | expectedCompletions = {"]["}; |
| 362 | expectedContextLength = 0; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | SECTION("cd example:twoKeyList[name=\"AHOJ\"]") |
| 366 | { |
| 367 | input = "cd example:twoKeyList[name=\"AHOJ\"]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 368 | expectedCompletions = {"]["}; |
| 369 | expectedContextLength = 1; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 370 | } |
| 371 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 372 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][") |
| 373 | { |
| 374 | input = "cd example:twoKeyList[name=\"AHOJ\"]["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 375 | expectedCompletions = {"number="}; |
| 376 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 377 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 378 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 379 | SECTION("cd example:twoKeyList[number=42][") |
| 380 | { |
| 381 | input = "cd example:twoKeyList[number=42]["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 382 | expectedCompletions = {"name="}; |
| 383 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 384 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 385 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 386 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123") |
| 387 | { |
| 388 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 389 | expectedCompletions = {"]/"}; |
| 390 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123]") |
| 394 | { |
| 395 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 396 | expectedCompletions = {"]/"}; |
| 397 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 398 | } |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 399 | |
| 400 | SECTION("cd example:ovoce") |
| 401 | { |
| 402 | input = "cd example:ovoce"; |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 403 | expectedCompletions = {"example:ovoce", "example:ovocezelenina"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 404 | expectedContextLength = 13; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 405 | } |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 406 | |
| 407 | SECTION("cd example:ovoceze") |
| 408 | { |
| 409 | input = "cd example:ovoceze"; |
| 410 | expectedCompletions = {"example:ovocezelenina"}; |
| 411 | expectedContextLength = 15; |
| 412 | } |
| 413 | |
| 414 | SECTION("cd example:ovocezelenina") |
| 415 | { |
| 416 | input = "cd example:ovocezelenina"; |
| 417 | expectedCompletions = {"example:ovocezelenina["}; |
| 418 | expectedContextLength = 21; |
| 419 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 420 | } |
| 421 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 422 | SECTION("no readonly data leafs in set") |
| 423 | { |
| 424 | input = "set example:read"; |
| 425 | expectedContextLength = 12; |
| 426 | } |
| 427 | |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame] | 428 | SECTION("clear completions when no longer inputting path") |
| 429 | { |
| 430 | input = "set example:leafInt "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 431 | expectedCompletions = {}; |
| 432 | expectedContextLength = 0; |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 435 | SECTION("rpc input nodes NOT completed for prepare command") |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 436 | { |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 437 | input = "prepare example:fire/"; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 438 | expectedCompletions = {}; |
| 439 | expectedContextLength = 13; |
| 440 | } |
| 441 | |
| 442 | SECTION("rpc input nodes completed for set command") |
| 443 | { |
| 444 | parser.changeNode({{}, {{module_{"second"}, rpcNode_{"fire"}}}}); |
| 445 | input = "set "; |
| 446 | expectedCompletions = {"whom "}; |
| 447 | expectedContextLength = 0; |
| 448 | } |
| 449 | |
| 450 | SECTION("completion for other stuff while inside an rpc") |
| 451 | { |
| 452 | parser.changeNode({{}, {{module_{"second"}, rpcNode_{"fire"}}}}); |
| 453 | input = "set ../"; |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 454 | expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list", "example:ovoce", "example:ovocezelenina", "example:twoKeyList", "second:amelie/", "second:fire/", "example:system/", "example:system-state/"}; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 455 | expectedContextLength = 0; |
| 456 | } |
| 457 | |
Václav Kubernát | 3102968 | 2020-10-29 08:23:04 +0100 | [diff] [blame] | 458 | SECTION("rpc nodes not completed for the get command") |
| 459 | { |
| 460 | input = "get "; |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 461 | expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list", "example:ovoce", "example:ovocezelenina", "example:readonly ", "example:twoKeyList", "second:amelie/", "example:system/", "example:system-state/"}; |
Václav Kubernát | 3102968 | 2020-10-29 08:23:04 +0100 | [diff] [blame] | 462 | expectedContextLength = 0; |
| 463 | } |
| 464 | |
Václav Kubernát | 0d47e5e | 2020-11-17 12:27:05 +0100 | [diff] [blame] | 465 | SECTION("leafs not completed for cd") |
| 466 | { |
| 467 | input = "cd "; |
Václav Kubernát | ce108db | 2021-01-25 10:05:40 +0100 | [diff] [blame] | 468 | expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/","example:list", "example:ovoce", "example:ovocezelenina", "example:twoKeyList", "second:amelie/", "example:system/", "example:system-state/"}; |
Václav Kubernát | 0d47e5e | 2020-11-17 12:27:05 +0100 | [diff] [blame] | 469 | expectedContextLength = 0; |
| 470 | } |
| 471 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 472 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 473 | } |