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