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 | |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 9 | #include "trompeloeil_doctest.h" |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 10 | #include "ast_commands.hpp" |
| 11 | #include "parser.hpp" |
| 12 | #include "static_schema.hpp" |
| 13 | |
| 14 | TEST_CASE("path_completion") |
| 15 | { |
| 16 | auto schema = std::make_shared<StaticSchema>(); |
| 17 | schema->addModule("example"); |
| 18 | schema->addModule("second"); |
| 19 | schema->addContainer("", "example:ano"); |
| 20 | schema->addContainer("", "example:anoda"); |
| 21 | schema->addList("example:ano", "example:listInCont", {"number"}); |
| 22 | schema->addContainer("", "second:amelie"); |
| 23 | schema->addContainer("", "example:bota"); |
| 24 | schema->addContainer("example:ano", "example:a2"); |
| 25 | schema->addContainer("example:bota", "example:b2"); |
| 26 | schema->addContainer("example:ano/example:a2", "example:a3"); |
| 27 | schema->addContainer("example:bota/example:b2", "example:b3"); |
| 28 | schema->addList("", "example:list", {"number"}); |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 29 | schema->addList("", "example:ovoce", {"name"}); |
| 30 | schema->addList("", "example:ovocezelenina", {"name"}); |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 31 | schema->addContainer("example:list", "example:contInList"); |
| 32 | schema->addList("", "example:twoKeyList", {"number", "name"}); |
| 33 | Parser parser(schema); |
| 34 | std::string input; |
| 35 | std::ostringstream errorStream; |
| 36 | std::set<std::string> expected; |
| 37 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 38 | SECTION("node name completion") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 39 | { |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 40 | SECTION("ls ") |
| 41 | { |
| 42 | input = "ls "; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 43 | expected = {"example:ano", "example:anoda", "example:bota", "second:amelie", "example:list", "example:twoKeyList", "example:ovoce", "example:ovocezelenina"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | SECTION("ls e") |
| 47 | { |
| 48 | input = "ls e"; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 49 | expected = {"example:ano", "example:anoda", "example:bota", "example:list", "example:twoKeyList", "example:ovoce", "example:ovocezelenina"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | SECTION("ls example:ano") |
| 53 | { |
| 54 | input = "ls example:ano"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 55 | expected = {"example:ano", "example:anoda"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | SECTION("ls example:ano/example:a") |
| 59 | { |
| 60 | input = "ls example:ano/example:a"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 61 | expected = {"example:a2"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | SECTION("ls x") |
| 65 | { |
| 66 | input = "ls x"; |
| 67 | expected = {}; |
| 68 | } |
| 69 | |
| 70 | SECTION("ls /") |
| 71 | { |
| 72 | input = "ls /"; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 73 | expected = {"example:ano", "example:anoda", "example:bota", "second:amelie", "example:list", "example:twoKeyList", "example:ovoce", "example:ovocezelenina"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | SECTION("ls /e") |
| 77 | { |
| 78 | input = "ls /e"; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 79 | expected = {"example:ano", "example:anoda", "example:bota", "example:list", "example:twoKeyList", "example:ovoce", "example:ovocezelenina"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | SECTION("ls /s") |
| 83 | { |
| 84 | input = "ls /s"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 85 | expected = {"second:amelie"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | SECTION("ls /example:list[number=3]/") |
| 89 | { |
| 90 | input = "ls /example:list[number=3]/"; |
| 91 | expected = {"example:contInList"}; |
| 92 | } |
| 93 | |
| 94 | SECTION("ls /example:list[number=3]/c") |
| 95 | { |
| 96 | input = "ls /example:list[number=3]/e"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 97 | expected = {"example:contInList"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | SECTION("ls /example:list[number=3]/a") |
| 101 | { |
| 102 | input = "ls /example:list[number=3]/a"; |
| 103 | expected = {}; |
| 104 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 107 | SECTION("list keys completion") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 108 | { |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 109 | SECTION("cd example:lis") |
| 110 | { |
| 111 | input = "cd example:lis"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 112 | expected = {"example:list"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 113 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 114 | |
Václav Kubernát | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 115 | SECTION("set example:list") |
| 116 | { |
| 117 | input = "set example:list"; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 118 | expected = {"example:list["}; |
| 119 | } |
| 120 | |
| 121 | SECTION("cd example:list") |
| 122 | { |
| 123 | input = "cd example:list"; |
| 124 | expected = {"example:list["}; |
Václav Kubernát | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 127 | SECTION("cd example:list[") |
| 128 | { |
| 129 | input = "cd example:list["; |
| 130 | expected = {"number="}; |
| 131 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 132 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 133 | SECTION("cd example:list[numb") |
| 134 | { |
| 135 | input = "cd example:list[numb"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 136 | expected = {"number="}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 137 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 138 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 139 | SECTION("cd example:list[number") |
| 140 | { |
| 141 | input = "cd example:list[number"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 142 | expected = {"number="}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 143 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 144 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 145 | SECTION("cd example:list[number=12") |
| 146 | { |
| 147 | input = "cd example:list[number=12"; |
| 148 | expected = {"]/"}; |
| 149 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 150 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 151 | SECTION("cd example:list[number=12]") |
| 152 | { |
| 153 | input = "cd example:list[number=12]"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 154 | expected = {"]/"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 155 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 156 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 157 | SECTION("cd example:twoKeyList[") |
| 158 | { |
| 159 | input = "cd example:twoKeyList["; |
| 160 | expected = {"name=", "number="}; |
| 161 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 162 | |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 163 | SECTION("cd example:twoKeyList[name=\"AHOJ\"") |
| 164 | { |
| 165 | input = "cd example:twoKeyList[name=\"AHOJ\""; |
| 166 | expected = {"]["}; |
| 167 | } |
| 168 | |
| 169 | SECTION("cd example:twoKeyList[name=\"AHOJ\"]") |
| 170 | { |
| 171 | input = "cd example:twoKeyList[name=\"AHOJ\"]"; |
| 172 | expected = {"]["}; |
| 173 | } |
| 174 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 175 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][") |
| 176 | { |
| 177 | input = "cd example:twoKeyList[name=\"AHOJ\"]["; |
| 178 | expected = {"number="}; |
| 179 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 180 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 181 | SECTION("cd example:twoKeyList[number=42][") |
| 182 | { |
| 183 | input = "cd example:twoKeyList[number=42]["; |
| 184 | expected = {"name="}; |
| 185 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 186 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 187 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123") |
| 188 | { |
| 189 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123"; |
| 190 | expected = {"]/"}; |
| 191 | } |
| 192 | |
| 193 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123]") |
| 194 | { |
| 195 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123]"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 196 | expected = {"]/"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 197 | } |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 198 | |
| 199 | SECTION("cd example:ovoce") |
| 200 | { |
| 201 | input = "cd example:ovoce"; |
| 202 | expected = {"example:ovoce", "example:ovocezelenina"}; |
| 203 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | REQUIRE(parser.completeCommand(input, errorStream) == expected); |
| 207 | } |