blob: 6744aed7c71119eb2d5036b3341af5c1a632288d [file] [log] [blame]
Václav Kubernát4108e0d2018-10-29 13:32:22 +01001/*
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áta33cf082019-03-28 11:55:57 +01009#include "trompeloeil_doctest.h"
Václav Kubernát4108e0d2018-10-29 13:32:22 +010010#include "parser.hpp"
11#include "static_schema.hpp"
12
13TEST_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át4c325482019-04-11 17:51:55 +020028 schema->addList("", "example:ovoce", {"name"});
29 schema->addList("", "example:ovocezelenina", {"name"});
Václav Kubernát4108e0d2018-10-29 13:32:22 +010030 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át329c6c32019-02-06 16:41:53 +010037 SECTION("node name completion")
Václav Kubernát4108e0d2018-10-29 13:32:22 +010038 {
Václav Kubernát329c6c32019-02-06 16:41:53 +010039 SECTION("ls ")
40 {
41 input = "ls ";
Václav Kubernát4c325482019-04-11 17:51:55 +020042 expected = {"example:ano", "example:anoda", "example:bota", "second:amelie", "example:list", "example:twoKeyList", "example:ovoce", "example:ovocezelenina"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010043 }
44
45 SECTION("ls e")
46 {
47 input = "ls e";
Václav Kubernát4c325482019-04-11 17:51:55 +020048 expected = {"example:ano", "example:anoda", "example:bota", "example:list", "example:twoKeyList", "example:ovoce", "example:ovocezelenina"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010049 }
50
51 SECTION("ls example:ano")
52 {
53 input = "ls example:ano";
Václav Kubernáta395d332019-02-13 16:49:20 +010054 expected = {"example:ano", "example:anoda"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010055 }
56
57 SECTION("ls example:ano/example:a")
58 {
59 input = "ls example:ano/example:a";
Václav Kubernáta395d332019-02-13 16:49:20 +010060 expected = {"example:a2"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010061 }
62
63 SECTION("ls x")
64 {
65 input = "ls x";
66 expected = {};
67 }
68
69 SECTION("ls /")
70 {
71 input = "ls /";
Václav Kubernát4c325482019-04-11 17:51:55 +020072 expected = {"example:ano", "example:anoda", "example:bota", "second:amelie", "example:list", "example:twoKeyList", "example:ovoce", "example:ovocezelenina"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010073 }
74
75 SECTION("ls /e")
76 {
77 input = "ls /e";
Václav Kubernát4c325482019-04-11 17:51:55 +020078 expected = {"example:ano", "example:anoda", "example:bota", "example:list", "example:twoKeyList", "example:ovoce", "example:ovocezelenina"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010079 }
80
81 SECTION("ls /s")
82 {
83 input = "ls /s";
Václav Kubernáta395d332019-02-13 16:49:20 +010084 expected = {"second:amelie"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010085 }
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áta395d332019-02-13 16:49:20 +010096 expected = {"example:contInList"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010097 }
98
99 SECTION("ls /example:list[number=3]/a")
100 {
101 input = "ls /example:list[number=3]/a";
102 expected = {};
103 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100104 }
105
Václav Kubernát329c6c32019-02-06 16:41:53 +0100106 SECTION("list keys completion")
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100107 {
Václav Kubernát329c6c32019-02-06 16:41:53 +0100108 SECTION("cd example:lis")
109 {
110 input = "cd example:lis";
Václav Kubernáta395d332019-02-13 16:49:20 +0100111 expected = {"example:list"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100112 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100113
Václav Kubernát51853b22019-04-16 21:53:44 +0200114 SECTION("set example:list")
115 {
116 input = "set example:list";
Václav Kubernát4c325482019-04-11 17:51:55 +0200117 expected = {"example:list["};
118 }
119
120 SECTION("cd example:list")
121 {
122 input = "cd example:list";
123 expected = {"example:list["};
Václav Kubernát51853b22019-04-16 21:53:44 +0200124 }
125
Václav Kubernát329c6c32019-02-06 16:41:53 +0100126 SECTION("cd example:list[")
127 {
128 input = "cd example:list[";
129 expected = {"number="};
130 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100131
Václav Kubernát329c6c32019-02-06 16:41:53 +0100132 SECTION("cd example:list[numb")
133 {
134 input = "cd example:list[numb";
Václav Kubernáta395d332019-02-13 16:49:20 +0100135 expected = {"number="};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100136 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100137
Václav Kubernát329c6c32019-02-06 16:41:53 +0100138 SECTION("cd example:list[number")
139 {
140 input = "cd example:list[number";
Václav Kubernáta395d332019-02-13 16:49:20 +0100141 expected = {"number="};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100142 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100143
Václav Kubernát329c6c32019-02-06 16:41:53 +0100144 SECTION("cd example:list[number=12")
145 {
146 input = "cd example:list[number=12";
147 expected = {"]/"};
148 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100149
Václav Kubernát329c6c32019-02-06 16:41:53 +0100150 SECTION("cd example:list[number=12]")
151 {
152 input = "cd example:list[number=12]";
Václav Kubernáta395d332019-02-13 16:49:20 +0100153 expected = {"]/"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100154 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100155
Václav Kubernát329c6c32019-02-06 16:41:53 +0100156 SECTION("cd example:twoKeyList[")
157 {
158 input = "cd example:twoKeyList[";
159 expected = {"name=", "number="};
160 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100161
Václav Kubernát4c325482019-04-11 17:51:55 +0200162 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át329c6c32019-02-06 16:41:53 +0100174 SECTION("cd example:twoKeyList[name=\"AHOJ\"][")
175 {
176 input = "cd example:twoKeyList[name=\"AHOJ\"][";
177 expected = {"number="};
178 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100179
Václav Kubernát329c6c32019-02-06 16:41:53 +0100180 SECTION("cd example:twoKeyList[number=42][")
181 {
182 input = "cd example:twoKeyList[number=42][";
183 expected = {"name="};
184 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100185
Václav Kubernát329c6c32019-02-06 16:41:53 +0100186 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áta395d332019-02-13 16:49:20 +0100195 expected = {"]/"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100196 }
Václav Kubernát4c325482019-04-11 17:51:55 +0200197
198 SECTION("cd example:ovoce")
199 {
200 input = "cd example:ovoce";
201 expected = {"example:ovoce", "example:ovocezelenina"};
202 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100203 }
204
205 REQUIRE(parser.completeCommand(input, errorStream) == expected);
206}