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 | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 41 | auto mockDatastore = std::make_shared<MockDatastoreAccess>(); |
| 42 | |
| 43 | // The parser will use DataQuery for key value completion, but I'm not testing that here, so I don't return anything. |
| 44 | ALLOW_CALL(*mockDatastore, listInstances("/example:list")) |
| 45 | .RETURN(std::vector<ListInstance>{}); |
| 46 | ALLOW_CALL(*mockDatastore, listInstances("/example:twoKeyList")) |
| 47 | .RETURN(std::vector<ListInstance>{}); |
| 48 | |
| 49 | // DataQuery gets the schema from DatastoreAccess once |
| 50 | auto expectation = NAMED_REQUIRE_CALL(*mockDatastore, schema()) |
| 51 | .RETURN(schema); |
| 52 | auto dataQuery = std::make_shared<DataQuery>(*mockDatastore); |
| 53 | expectation.reset(); |
| 54 | Parser parser(schema, dataQuery); |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 55 | std::string input; |
| 56 | std::ostringstream errorStream; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 57 | |
| 58 | std::set<std::string> expectedCompletions; |
| 59 | // GCC complains here with -Wmaybe-uninitialized if I don't assign |
| 60 | // something here. I suspect it's because of nested SECTIONs. -1 is an |
| 61 | // invalid value (as in, I'll never expect expectedContextLength to be -1), |
| 62 | // so let's go with that. |
| 63 | int expectedContextLength = -1; |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 64 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 65 | SECTION("node name completion") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 66 | { |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 67 | SECTION("ls ") |
| 68 | { |
| 69 | input = "ls "; |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 70 | expectedCompletions = {"example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list", "example:ovoce", "example:readonly ", "example:ovocezelenina", "example:twoKeyList", "second:amelie/"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 71 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | SECTION("ls e") |
| 75 | { |
| 76 | input = "ls e"; |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 77 | expectedCompletions = {"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] | 78 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | SECTION("ls example:ano") |
| 82 | { |
| 83 | input = "ls example:ano"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 84 | expectedCompletions = {"example:ano/", "example:anoda/"}; |
| 85 | expectedContextLength = 11; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 88 | SECTION("ls example:ano/a") |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 89 | { |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 90 | input = "ls example:ano/a"; |
| 91 | expectedCompletions = {"a2/"}; |
| 92 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | SECTION("ls x") |
| 96 | { |
| 97 | input = "ls x"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 98 | expectedCompletions = {}; |
| 99 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | SECTION("ls /") |
| 103 | { |
| 104 | input = "ls /"; |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 105 | expectedCompletions = {"example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list", "example:ovoce", "example:readonly ", "example:ovocezelenina", "example:twoKeyList", "second:amelie/"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 106 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | SECTION("ls /e") |
| 110 | { |
| 111 | input = "ls /e"; |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 112 | expectedCompletions = {"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] | 113 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Václav Kubernát | e69133a | 2019-11-01 19:01:34 +0100 | [diff] [blame] | 116 | SECTION("ls example:bota") |
| 117 | { |
| 118 | input = "ls example:bota"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 119 | expectedCompletions = {"example:bota/"}; |
| 120 | expectedContextLength = 12; |
Václav Kubernát | e69133a | 2019-11-01 19:01:34 +0100 | [diff] [blame] | 121 | } |
| 122 | |
| 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 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 130 | SECTION("ls /s") |
| 131 | { |
| 132 | input = "ls /s"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 133 | expectedCompletions = {"second:amelie/"}; |
| 134 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 135 | } |
| 136 | |
Václav Kubernát | 26be33a | 2020-02-13 13:30:14 +0100 | [diff] [blame] | 137 | SECTION("ls /example:list/") |
| 138 | { |
| 139 | input = "ls /example:list/"; |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 140 | expectedCompletions = {"contInList/", "number "}; |
Václav Kubernát | 26be33a | 2020-02-13 13:30:14 +0100 | [diff] [blame] | 141 | expectedContextLength = 0; |
| 142 | } |
| 143 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 144 | SECTION("ls /example:list[number=3]/") |
| 145 | { |
| 146 | input = "ls /example:list[number=3]/"; |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 147 | expectedCompletions = {"contInList/", "number "}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 148 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | SECTION("ls /example:list[number=3]/c") |
| 152 | { |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 153 | input = "ls /example:list[number=3]/c"; |
| 154 | expectedCompletions = {"contInList/"}; |
| 155 | expectedContextLength = 1; |
| 156 | } |
| 157 | |
| 158 | SECTION("ls /example:list[number=3]/n") |
| 159 | { |
| 160 | input = "ls /example:list[number=3]/n"; |
| 161 | expectedCompletions = {"number "}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 162 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | SECTION("ls /example:list[number=3]/a") |
| 166 | { |
| 167 | input = "ls /example:list[number=3]/a"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 168 | expectedCompletions = {}; |
| 169 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 170 | } |
Václav Kubernát | 26be33a | 2020-02-13 13:30:14 +0100 | [diff] [blame] | 171 | |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 172 | SECTION("ls /example:list/contInList/") |
Václav Kubernát | 26be33a | 2020-02-13 13:30:14 +0100 | [diff] [blame] | 173 | { |
Václav Kubernát | e2d629f | 2020-04-28 11:01:54 +0200 | [diff] [blame] | 174 | input = "ls /example:list/contInList/"; |
Václav Kubernát | 26be33a | 2020-02-13 13:30:14 +0100 | [diff] [blame] | 175 | expectedCompletions = {}; |
| 176 | expectedContextLength = 0; |
| 177 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 178 | } |
| 179 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 180 | SECTION("list keys completion") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 181 | { |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 182 | SECTION("cd example:lis") |
| 183 | { |
| 184 | input = "cd example:lis"; |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 185 | expectedCompletions = {"example:list"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 186 | expectedContextLength = 11; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 187 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 188 | |
Václav Kubernát | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 189 | SECTION("set example:list") |
| 190 | { |
| 191 | input = "set example:list"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 192 | expectedCompletions = {"example:list["}; |
| 193 | expectedContextLength = 12; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | SECTION("cd example:list") |
| 197 | { |
| 198 | input = "cd example:list"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 199 | expectedCompletions = {"example:list["}; |
| 200 | expectedContextLength = 12; |
Václav Kubernát | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 203 | SECTION("cd example:list[") |
| 204 | { |
| 205 | input = "cd example:list["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 206 | expectedCompletions = {"number="}; |
| 207 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 208 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 209 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 210 | SECTION("cd example:list[numb") |
| 211 | { |
| 212 | input = "cd example:list[numb"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 213 | expectedCompletions = {"number="}; |
| 214 | expectedContextLength = 4; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 215 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 216 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 217 | SECTION("cd example:list[number") |
| 218 | { |
| 219 | input = "cd example:list[number"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 220 | expectedCompletions = {"number="}; |
| 221 | expectedContextLength = 6; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 222 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 223 | |
Václav Kubernát | 117f7b5 | 2020-01-23 16:10:55 +0100 | [diff] [blame] | 224 | SECTION("cd example:list[number=") |
| 225 | { |
| 226 | input = "cd example:list[number="; |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 227 | expectedCompletions = {}; |
| 228 | expectedContextLength = 0; |
Václav Kubernát | 117f7b5 | 2020-01-23 16:10:55 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 231 | SECTION("cd example:list[number=12") |
| 232 | { |
| 233 | input = "cd example:list[number=12"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 234 | expectedCompletions = {"]/"}; |
| 235 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 236 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 237 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 238 | SECTION("cd example:list[number=12]") |
| 239 | { |
| 240 | input = "cd example:list[number=12]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 241 | expectedCompletions = {"]/"}; |
| 242 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 243 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 244 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 245 | SECTION("cd example:twoKeyList[") |
| 246 | { |
| 247 | input = "cd example:twoKeyList["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 248 | expectedCompletions = {"name=", "number="}; |
| 249 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 250 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 251 | |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 252 | SECTION("cd example:twoKeyList[name=\"AHOJ\"") |
| 253 | { |
| 254 | input = "cd example:twoKeyList[name=\"AHOJ\""; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 255 | expectedCompletions = {"]["}; |
| 256 | expectedContextLength = 0; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | SECTION("cd example:twoKeyList[name=\"AHOJ\"]") |
| 260 | { |
| 261 | input = "cd example:twoKeyList[name=\"AHOJ\"]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 262 | expectedCompletions = {"]["}; |
| 263 | expectedContextLength = 1; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 266 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][") |
| 267 | { |
| 268 | input = "cd example:twoKeyList[name=\"AHOJ\"]["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 269 | expectedCompletions = {"number="}; |
| 270 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 271 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 272 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 273 | SECTION("cd example:twoKeyList[number=42][") |
| 274 | { |
| 275 | input = "cd example:twoKeyList[number=42]["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 276 | expectedCompletions = {"name="}; |
| 277 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 278 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 279 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 280 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123") |
| 281 | { |
| 282 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 283 | expectedCompletions = {"]/"}; |
| 284 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123]") |
| 288 | { |
| 289 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 290 | expectedCompletions = {"]/"}; |
| 291 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 292 | } |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 293 | |
| 294 | SECTION("cd example:ovoce") |
| 295 | { |
| 296 | input = "cd example:ovoce"; |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 297 | expectedCompletions = {"example:ovoce", "example:ovocezelenina"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 298 | expectedContextLength = 13; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 299 | } |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 300 | |
| 301 | SECTION("cd example:ovoceze") |
| 302 | { |
| 303 | input = "cd example:ovoceze"; |
| 304 | expectedCompletions = {"example:ovocezelenina"}; |
| 305 | expectedContextLength = 15; |
| 306 | } |
| 307 | |
| 308 | SECTION("cd example:ovocezelenina") |
| 309 | { |
| 310 | input = "cd example:ovocezelenina"; |
| 311 | expectedCompletions = {"example:ovocezelenina["}; |
| 312 | expectedContextLength = 21; |
| 313 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 314 | } |
| 315 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 316 | SECTION("no readonly data leafs in set") |
| 317 | { |
| 318 | input = "set example:read"; |
| 319 | expectedContextLength = 12; |
| 320 | } |
| 321 | |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame] | 322 | SECTION("clear completions when no longer inputting path") |
| 323 | { |
| 324 | input = "set example:leafInt "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 325 | expectedCompletions = {}; |
| 326 | expectedContextLength = 0; |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame] | 327 | } |
| 328 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 329 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 330 | } |