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