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"}); |
| 29 | schema->addContainer("example:list", "example:contInList"); |
| 30 | schema->addList("", "example:twoKeyList", {"number", "name"}); |
| 31 | Parser parser(schema); |
| 32 | std::string input; |
| 33 | std::ostringstream errorStream; |
| 34 | std::set<std::string> expected; |
| 35 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 36 | SECTION("node name completion") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 37 | { |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 38 | SECTION("ls ") |
| 39 | { |
| 40 | input = "ls "; |
| 41 | expected = {"example:ano", "example:anoda", "example:bota", "second:amelie", "example:list", "example:twoKeyList"}; |
| 42 | } |
| 43 | |
| 44 | SECTION("ls e") |
| 45 | { |
| 46 | input = "ls e"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 47 | expected = {"example:ano", "example:anoda", "example:bota", "example:list", "example:twoKeyList"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | SECTION("ls example:ano") |
| 51 | { |
| 52 | input = "ls example:ano"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 53 | expected = {"example:ano", "example:anoda"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | SECTION("ls example:ano/example:a") |
| 57 | { |
| 58 | input = "ls example:ano/example:a"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 59 | expected = {"example:a2"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | SECTION("ls x") |
| 63 | { |
| 64 | input = "ls x"; |
| 65 | expected = {}; |
| 66 | } |
| 67 | |
| 68 | SECTION("ls /") |
| 69 | { |
| 70 | input = "ls /"; |
| 71 | expected = {"example:ano", "example:anoda", "example:bota", "second:amelie", "example:list", "example:twoKeyList"}; |
| 72 | } |
| 73 | |
| 74 | SECTION("ls /e") |
| 75 | { |
| 76 | input = "ls /e"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 77 | expected = {"example:ano", "example:anoda", "example:bota", "example:list", "example:twoKeyList"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | SECTION("ls /s") |
| 81 | { |
| 82 | input = "ls /s"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 83 | expected = {"second:amelie"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | SECTION("ls /example:list[number=3]/") |
| 87 | { |
| 88 | input = "ls /example:list[number=3]/"; |
| 89 | expected = {"example:contInList"}; |
| 90 | } |
| 91 | |
| 92 | SECTION("ls /example:list[number=3]/c") |
| 93 | { |
| 94 | input = "ls /example:list[number=3]/e"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 95 | expected = {"example:contInList"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | SECTION("ls /example:list[number=3]/a") |
| 99 | { |
| 100 | input = "ls /example:list[number=3]/a"; |
| 101 | expected = {}; |
| 102 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 103 | } |
| 104 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 105 | SECTION("list keys completion") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 106 | { |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 107 | SECTION("cd example:lis") |
| 108 | { |
| 109 | input = "cd example:lis"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 110 | expected = {"example:list"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 111 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 112 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 113 | SECTION("cd example:list[") |
| 114 | { |
| 115 | input = "cd example:list["; |
| 116 | expected = {"number="}; |
| 117 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 118 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 119 | SECTION("cd example:list[numb") |
| 120 | { |
| 121 | input = "cd example:list[numb"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 122 | expected = {"number="}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 123 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 124 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 125 | SECTION("cd example:list[number") |
| 126 | { |
| 127 | input = "cd example:list[number"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 128 | expected = {"number="}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 129 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 130 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 131 | SECTION("cd example:list[number=12") |
| 132 | { |
| 133 | input = "cd example:list[number=12"; |
| 134 | expected = {"]/"}; |
| 135 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 136 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 137 | SECTION("cd example:list[number=12]") |
| 138 | { |
| 139 | input = "cd example:list[number=12]"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 140 | expected = {"]/"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 141 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 142 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 143 | SECTION("cd example:twoKeyList[") |
| 144 | { |
| 145 | input = "cd example:twoKeyList["; |
| 146 | expected = {"name=", "number="}; |
| 147 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 148 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 149 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][") |
| 150 | { |
| 151 | input = "cd example:twoKeyList[name=\"AHOJ\"]["; |
| 152 | expected = {"number="}; |
| 153 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 154 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 155 | SECTION("cd example:twoKeyList[number=42][") |
| 156 | { |
| 157 | input = "cd example:twoKeyList[number=42]["; |
| 158 | expected = {"name="}; |
| 159 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 160 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 161 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123") |
| 162 | { |
| 163 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123"; |
| 164 | expected = {"]/"}; |
| 165 | } |
| 166 | |
| 167 | SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123]") |
| 168 | { |
| 169 | input = "cd example:twoKeyList[name=\"AHOJ\"][number=123]"; |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 170 | expected = {"]/"}; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 171 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | REQUIRE(parser.completeCommand(input, errorStream) == expected); |
| 175 | } |