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