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 | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 190 | SECTION("list keys completion") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 191 | { |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 192 | SECTION("cd example:lis") |
| 193 | { |
| 194 | input = "cd example:lis"; |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 195 | expectedCompletions = {"example:list"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 196 | expectedContextLength = 11; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 197 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 198 | |
Václav Kubernát | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 199 | SECTION("set example:list") |
| 200 | { |
| 201 | input = "set example:list"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 202 | expectedCompletions = {"example:list["}; |
| 203 | expectedContextLength = 12; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | SECTION("cd example:list") |
| 207 | { |
| 208 | input = "cd example:list"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 209 | expectedCompletions = {"example:list["}; |
| 210 | expectedContextLength = 12; |
Václav Kubernát | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 213 | SECTION("cd example:list[") |
| 214 | { |
| 215 | input = "cd example:list["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 216 | expectedCompletions = {"number="}; |
| 217 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 218 | } |
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:list[numb") |
| 221 | { |
| 222 | input = "cd example:list[numb"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 223 | expectedCompletions = {"number="}; |
| 224 | expectedContextLength = 4; |
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 | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 227 | SECTION("cd example:list[number") |
| 228 | { |
| 229 | input = "cd example:list[number"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 230 | expectedCompletions = {"number="}; |
| 231 | expectedContextLength = 6; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 232 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 233 | |
Václav Kubernát | 117f7b5 | 2020-01-23 16:10:55 +0100 | [diff] [blame] | 234 | SECTION("cd example:list[number=") |
| 235 | { |
| 236 | input = "cd example:list[number="; |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 237 | expectedCompletions = {}; |
| 238 | expectedContextLength = 0; |
Václav Kubernát | 117f7b5 | 2020-01-23 16:10:55 +0100 | [diff] [blame] | 239 | } |
| 240 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 241 | SECTION("cd example:list[number=12") |
| 242 | { |
| 243 | input = "cd example:list[number=12"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 244 | expectedCompletions = {"]/"}; |
| 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[number=12]") |
| 249 | { |
| 250 | input = "cd example:list[number=12]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 251 | expectedCompletions = {"]/"}; |
| 252 | expectedContextLength = 1; |
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:twoKeyList[") |
| 256 | { |
| 257 | input = "cd example:twoKeyList["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 258 | expectedCompletions = {"name=", "number="}; |
| 259 | expectedContextLength = 0; |
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 | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 262 | SECTION("cd example:twoKeyList[name=\"AHOJ\"") |
| 263 | { |
| 264 | input = "cd example:twoKeyList[name=\"AHOJ\""; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 265 | expectedCompletions = {"]["}; |
| 266 | expectedContextLength = 0; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | SECTION("cd example:twoKeyList[name=\"AHOJ\"]") |
| 270 | { |
| 271 | input = "cd example:twoKeyList[name=\"AHOJ\"]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 272 | expectedCompletions = {"]["}; |
| 273 | expectedContextLength = 1; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 276 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][") |
| 277 | { |
| 278 | input = "cd example:twoKeyList[name=\"AHOJ\"]["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 279 | expectedCompletions = {"number="}; |
| 280 | expectedContextLength = 0; |
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[number=42][") |
| 284 | { |
| 285 | input = "cd example:twoKeyList[number=42]["; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 286 | expectedCompletions = {"name="}; |
| 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 | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 290 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123") |
| 291 | { |
| 292 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 293 | expectedCompletions = {"]/"}; |
| 294 | expectedContextLength = 0; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123]") |
| 298 | { |
| 299 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123]"; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 300 | expectedCompletions = {"]/"}; |
| 301 | expectedContextLength = 1; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 302 | } |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 303 | |
| 304 | SECTION("cd example:ovoce") |
| 305 | { |
| 306 | input = "cd example:ovoce"; |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 307 | expectedCompletions = {"example:ovoce", "example:ovocezelenina"}; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 308 | expectedContextLength = 13; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 309 | } |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 310 | |
| 311 | SECTION("cd example:ovoceze") |
| 312 | { |
| 313 | input = "cd example:ovoceze"; |
| 314 | expectedCompletions = {"example:ovocezelenina"}; |
| 315 | expectedContextLength = 15; |
| 316 | } |
| 317 | |
| 318 | SECTION("cd example:ovocezelenina") |
| 319 | { |
| 320 | input = "cd example:ovocezelenina"; |
| 321 | expectedCompletions = {"example:ovocezelenina["}; |
| 322 | expectedContextLength = 21; |
| 323 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 326 | SECTION("no readonly data leafs in set") |
| 327 | { |
| 328 | input = "set example:read"; |
| 329 | expectedContextLength = 12; |
| 330 | } |
| 331 | |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame] | 332 | SECTION("clear completions when no longer inputting path") |
| 333 | { |
| 334 | input = "set example:leafInt "; |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 335 | expectedCompletions = {}; |
| 336 | expectedContextLength = 0; |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 339 | SECTION("rpc input nodes NOT completed for prepare command") |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 340 | { |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 341 | input = "prepare example:fire/"; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 342 | expectedCompletions = {}; |
| 343 | expectedContextLength = 13; |
| 344 | } |
| 345 | |
| 346 | SECTION("rpc input nodes completed for set command") |
| 347 | { |
| 348 | parser.changeNode({{}, {{module_{"second"}, rpcNode_{"fire"}}}}); |
| 349 | input = "set "; |
| 350 | expectedCompletions = {"whom "}; |
| 351 | expectedContextLength = 0; |
| 352 | } |
| 353 | |
| 354 | SECTION("completion for other stuff while inside an rpc") |
| 355 | { |
| 356 | parser.changeNode({{}, {{module_{"second"}, rpcNode_{"fire"}}}}); |
| 357 | input = "set ../"; |
| 358 | expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list", "example:ovoce", "example:ovocezelenina", "example:twoKeyList", "second:amelie/", "second:fire/"}; |
| 359 | expectedContextLength = 0; |
| 360 | } |
| 361 | |
Václav Kubernát | 3102968 | 2020-10-29 08:23:04 +0100 | [diff] [blame] | 362 | SECTION("rpc nodes not completed for the get command") |
| 363 | { |
| 364 | input = "get "; |
| 365 | expectedCompletions = {"example:addresses", "example:ano/", "example:anoda/", "example:bota/", "example:leafInt ", "example:list", "example:ovoce", "example:ovocezelenina", "example:readonly ", "example:twoKeyList", "second:amelie/"}; |
| 366 | expectedContextLength = 0; |
| 367 | } |
| 368 | |
Václav Kubernát | 1ed4aa3 | 2020-01-23 13:13:28 +0100 | [diff] [blame] | 369 | REQUIRE(parser.completeCommand(input, errorStream) == (Completions{expectedCompletions, expectedContextLength})); |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 370 | } |