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 | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 208 | SECTION("list keys completion") |
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:lis") |
| 211 | { |
| 212 | input = "cd example:lis"; |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 213 | expectedCompletions = {"example:list"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 214 | expectedContextLength = 11; |
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 | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 217 | SECTION("set example:list") |
| 218 | { |
| 219 | input = "set example:list"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 220 | expectedCompletions = {"example:list["}; |
| 221 | expectedContextLength = 12; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | SECTION("cd example:list") |
| 225 | { |
| 226 | input = "cd example:list"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 227 | expectedCompletions = {"example:list["}; |
| 228 | expectedContextLength = 12; |
Václav Kubernát | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 229 | } |
| 230 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 231 | SECTION("cd example:list[") |
| 232 | { |
| 233 | input = "cd example:list["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 234 | expectedCompletions = {"number="}; |
| 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[numb") |
| 239 | { |
| 240 | input = "cd example:list[numb"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 241 | expectedCompletions = {"number="}; |
| 242 | expectedContextLength = 4; |
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:list[number") |
| 246 | { |
| 247 | input = "cd example:list[number"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 248 | expectedCompletions = {"number="}; |
| 249 | expectedContextLength = 6; |
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 | 117f7b5 | 2020-01-23 16:10:55 +0100 | [diff] [blame] | 252 | SECTION("cd example:list[number=") |
| 253 | { |
| 254 | input = "cd example:list[number="; |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 255 | expectedCompletions = {}; |
| 256 | expectedContextLength = 0; |
Václav Kubernát | 117f7b5 | 2020-01-23 16:10:55 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 259 | SECTION("cd example:list[number=12") |
| 260 | { |
| 261 | input = "cd example:list[number=12"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 262 | expectedCompletions = {"]/"}; |
| 263 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 264 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 265 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 266 | SECTION("cd example:list[number=12]") |
| 267 | { |
| 268 | input = "cd example:list[number=12]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 269 | expectedCompletions = {"]/"}; |
| 270 | expectedContextLength = 1; |
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[") |
| 274 | { |
| 275 | input = "cd example:twoKeyList["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 276 | expectedCompletions = {"name=", "number="}; |
| 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 | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 280 | SECTION("cd example:twoKeyList[name=\"AHOJ\"") |
| 281 | { |
| 282 | input = "cd example:twoKeyList[name=\"AHOJ\""; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 283 | expectedCompletions = {"]["}; |
| 284 | expectedContextLength = 0; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | SECTION("cd example:twoKeyList[name=\"AHOJ\"]") |
| 288 | { |
| 289 | input = "cd example:twoKeyList[name=\"AHOJ\"]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 290 | expectedCompletions = {"]["}; |
| 291 | expectedContextLength = 1; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 294 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][") |
| 295 | { |
| 296 | input = "cd example:twoKeyList[name=\"AHOJ\"]["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 297 | expectedCompletions = {"number="}; |
| 298 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 299 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 300 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 301 | SECTION("cd example:twoKeyList[number=42][") |
| 302 | { |
| 303 | input = "cd example:twoKeyList[number=42]["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 304 | expectedCompletions = {"name="}; |
| 305 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 306 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 307 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 308 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123") |
| 309 | { |
| 310 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 311 | expectedCompletions = {"]/"}; |
| 312 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123]") |
| 316 | { |
| 317 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 318 | expectedCompletions = {"]/"}; |
| 319 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 320 | } |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 321 | |
| 322 | SECTION("cd example:ovoce") |
| 323 | { |
| 324 | input = "cd example:ovoce"; |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 325 | expectedCompletions = {"example:ovoce", "example:ovocezelenina"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 326 | expectedContextLength = 13; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 327 | } |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 328 | |
| 329 | SECTION("cd example:ovoceze") |
| 330 | { |
| 331 | input = "cd example:ovoceze"; |
| 332 | expectedCompletions = {"example:ovocezelenina"}; |
| 333 | expectedContextLength = 15; |
| 334 | } |
| 335 | |
| 336 | SECTION("cd example:ovocezelenina") |
| 337 | { |
| 338 | input = "cd example:ovocezelenina"; |
| 339 | expectedCompletions = {"example:ovocezelenina["}; |
| 340 | expectedContextLength = 21; |
| 341 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 342 | } |
| 343 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 344 | SECTION("no readonly data leafs in set") |
| 345 | { |
| 346 | input = "set example:read"; |
| 347 | expectedContextLength = 12; |
| 348 | } |
| 349 | |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame] | 350 | SECTION("clear completions when no longer inputting path") |
| 351 | { |
| 352 | input = "set example:leafInt "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 353 | expectedCompletions = {}; |
| 354 | expectedContextLength = 0; |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 357 | SECTION("rpc input nodes NOT completed for prepare command") |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 358 | { |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 359 | input = "prepare example:fire/"; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 360 | expectedCompletions = {}; |
| 361 | expectedContextLength = 13; |
| 362 | } |
| 363 | |
| 364 | SECTION("rpc input nodes completed for set command") |
| 365 | { |
| 366 | parser.changeNode({{}, {{module_{"second"}, rpcNode_{"fire"}}}}); |
| 367 | input = "set "; |
| 368 | expectedCompletions = {"whom "}; |
| 369 | expectedContextLength = 0; |
| 370 | } |
| 371 | |
| 372 | SECTION("completion for other stuff while inside an rpc") |
| 373 | { |
| 374 | parser.changeNode({{}, {{module_{"second"}, rpcNode_{"fire"}}}}); |
| 375 | input = "set ../"; |
| 376 | expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list", "example:ovoce", "example:ovocezelenina", "example:twoKeyList", "second:amelie/", "second:fire/"}; |
| 377 | expectedContextLength = 0; |
| 378 | } |
| 379 | |
Václav Kubernát | 3102968 | 2020-10-29 08:23:04 +0100 | [diff] [blame] | 380 | SECTION("rpc nodes not completed for the get command") |
| 381 | { |
| 382 | input = "get "; |
| 383 | expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list", "example:ovoce", "example:ovocezelenina", "example:readonly ", "example:twoKeyList", "second:amelie/"}; |
| 384 | expectedContextLength = 0; |
| 385 | } |
| 386 | |
Václav Kubernát | 0d47e5e | 2020-11-17 12:27:05 +0100 | [diff] [blame] | 387 | SECTION("leafs not completed for cd") |
| 388 | { |
| 389 | input = "cd "; |
| 390 | expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/","example:list", "example:ovoce", "example:ovocezelenina", "example:twoKeyList", "second:amelie/"}; |
| 391 | expectedContextLength = 0; |
| 392 | } |
| 393 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 394 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 395 | } |