blob: 0e66595bea883f91193aebd1a76c5351965c407e [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 "ast_commands.hpp"
11#include "parser.hpp"
12#include "static_schema.hpp"
13
14TEST_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át4c325482019-04-11 17:51:55 +020029 schema->addList("", "example:ovoce", {"name"});
30 schema->addList("", "example:ovocezelenina", {"name"});
Václav Kubernát4108e0d2018-10-29 13:32:22 +010031 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át329c6c32019-02-06 16:41:53 +010038 SECTION("node name completion")
Václav Kubernát4108e0d2018-10-29 13:32:22 +010039 {
Václav Kubernát329c6c32019-02-06 16:41:53 +010040 SECTION("ls ")
41 {
42 input = "ls ";
Václav Kubernát4c325482019-04-11 17:51:55 +020043 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 +010044 }
45
46 SECTION("ls e")
47 {
48 input = "ls e";
Václav Kubernát4c325482019-04-11 17:51:55 +020049 expected = {"example:ano", "example:anoda", "example:bota", "example:list", "example:twoKeyList", "example:ovoce", "example:ovocezelenina"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010050 }
51
52 SECTION("ls example:ano")
53 {
54 input = "ls example:ano";
Václav Kubernáta395d332019-02-13 16:49:20 +010055 expected = {"example:ano", "example:anoda"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010056 }
57
58 SECTION("ls example:ano/example:a")
59 {
60 input = "ls example:ano/example:a";
Václav Kubernáta395d332019-02-13 16:49:20 +010061 expected = {"example:a2"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010062 }
63
64 SECTION("ls x")
65 {
66 input = "ls x";
67 expected = {};
68 }
69
70 SECTION("ls /")
71 {
72 input = "ls /";
Václav Kubernát4c325482019-04-11 17:51:55 +020073 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 +010074 }
75
76 SECTION("ls /e")
77 {
78 input = "ls /e";
Václav Kubernát4c325482019-04-11 17:51:55 +020079 expected = {"example:ano", "example:anoda", "example:bota", "example:list", "example:twoKeyList", "example:ovoce", "example:ovocezelenina"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010080 }
81
82 SECTION("ls /s")
83 {
84 input = "ls /s";
Václav Kubernáta395d332019-02-13 16:49:20 +010085 expected = {"second:amelie"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010086 }
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áta395d332019-02-13 16:49:20 +010097 expected = {"example:contInList"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010098 }
99
100 SECTION("ls /example:list[number=3]/a")
101 {
102 input = "ls /example:list[number=3]/a";
103 expected = {};
104 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100105 }
106
Václav Kubernát329c6c32019-02-06 16:41:53 +0100107 SECTION("list keys completion")
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100108 {
Václav Kubernát329c6c32019-02-06 16:41:53 +0100109 SECTION("cd example:lis")
110 {
111 input = "cd example:lis";
Václav Kubernáta395d332019-02-13 16:49:20 +0100112 expected = {"example:list"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100113 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100114
Václav Kubernát51853b22019-04-16 21:53:44 +0200115 SECTION("set example:list")
116 {
117 input = "set example:list";
Václav Kubernát4c325482019-04-11 17:51:55 +0200118 expected = {"example:list["};
119 }
120
121 SECTION("cd example:list")
122 {
123 input = "cd example:list";
124 expected = {"example:list["};
Václav Kubernát51853b22019-04-16 21:53:44 +0200125 }
126
Václav Kubernát329c6c32019-02-06 16:41:53 +0100127 SECTION("cd example:list[")
128 {
129 input = "cd example:list[";
130 expected = {"number="};
131 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100132
Václav Kubernát329c6c32019-02-06 16:41:53 +0100133 SECTION("cd example:list[numb")
134 {
135 input = "cd example:list[numb";
Václav Kubernáta395d332019-02-13 16:49:20 +0100136 expected = {"number="};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100137 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100138
Václav Kubernát329c6c32019-02-06 16:41:53 +0100139 SECTION("cd example:list[number")
140 {
141 input = "cd example:list[number";
Václav Kubernáta395d332019-02-13 16:49:20 +0100142 expected = {"number="};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100143 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100144
Václav Kubernát329c6c32019-02-06 16:41:53 +0100145 SECTION("cd example:list[number=12")
146 {
147 input = "cd example:list[number=12";
148 expected = {"]/"};
149 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100150
Václav Kubernát329c6c32019-02-06 16:41:53 +0100151 SECTION("cd example:list[number=12]")
152 {
153 input = "cd example:list[number=12]";
Václav Kubernáta395d332019-02-13 16:49:20 +0100154 expected = {"]/"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100155 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100156
Václav Kubernát329c6c32019-02-06 16:41:53 +0100157 SECTION("cd example:twoKeyList[")
158 {
159 input = "cd example:twoKeyList[";
160 expected = {"name=", "number="};
161 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100162
Václav Kubernát4c325482019-04-11 17:51:55 +0200163 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át329c6c32019-02-06 16:41:53 +0100175 SECTION("cd example:twoKeyList[name=\"AHOJ\"][")
176 {
177 input = "cd example:twoKeyList[name=\"AHOJ\"][";
178 expected = {"number="};
179 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100180
Václav Kubernát329c6c32019-02-06 16:41:53 +0100181 SECTION("cd example:twoKeyList[number=42][")
182 {
183 input = "cd example:twoKeyList[number=42][";
184 expected = {"name="};
185 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100186
Václav Kubernát329c6c32019-02-06 16:41:53 +0100187 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áta395d332019-02-13 16:49:20 +0100196 expected = {"]/"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100197 }
Václav Kubernát4c325482019-04-11 17:51:55 +0200198
199 SECTION("cd example:ovoce")
200 {
201 input = "cd example:ovoce";
202 expected = {"example:ovoce", "example:ovocezelenina"};
203 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100204 }
205
206 REQUIRE(parser.completeCommand(input, errorStream) == expected);
207}