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