blob: e0faf157df74024dc419a429fbc1ee7acae23db5 [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
9#include "trompeloeil_catch.h"
10#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"});
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át329c6c32019-02-06 16:41:53 +010036 SECTION("node name completion")
Václav Kubernát4108e0d2018-10-29 13:32:22 +010037 {
Václav Kubernát329c6c32019-02-06 16:41:53 +010038 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áta395d332019-02-13 16:49:20 +010047 expected = {"example:ano", "example:anoda", "example:bota", "example:list", "example:twoKeyList"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010048 }
49
50 SECTION("ls example:ano")
51 {
52 input = "ls example:ano";
Václav Kubernáta395d332019-02-13 16:49:20 +010053 expected = {"example:ano", "example:anoda"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010054 }
55
56 SECTION("ls example:ano/example:a")
57 {
58 input = "ls example:ano/example:a";
Václav Kubernáta395d332019-02-13 16:49:20 +010059 expected = {"example:a2"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010060 }
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áta395d332019-02-13 16:49:20 +010077 expected = {"example:ano", "example:anoda", "example:bota", "example:list", "example:twoKeyList"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010078 }
79
80 SECTION("ls /s")
81 {
82 input = "ls /s";
Václav Kubernáta395d332019-02-13 16:49:20 +010083 expected = {"second:amelie"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010084 }
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áta395d332019-02-13 16:49:20 +010095 expected = {"example:contInList"};
Václav Kubernát329c6c32019-02-06 16:41:53 +010096 }
97
98 SECTION("ls /example:list[number=3]/a")
99 {
100 input = "ls /example:list[number=3]/a";
101 expected = {};
102 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100103 }
104
Václav Kubernát329c6c32019-02-06 16:41:53 +0100105 SECTION("list keys completion")
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100106 {
Václav Kubernát329c6c32019-02-06 16:41:53 +0100107 SECTION("cd example:lis")
108 {
109 input = "cd example:lis";
Václav Kubernáta395d332019-02-13 16:49:20 +0100110 expected = {"example:list"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100111 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100112
Václav Kubernát329c6c32019-02-06 16:41:53 +0100113 SECTION("cd example:list[")
114 {
115 input = "cd example:list[";
116 expected = {"number="};
117 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100118
Václav Kubernát329c6c32019-02-06 16:41:53 +0100119 SECTION("cd example:list[numb")
120 {
121 input = "cd example:list[numb";
Václav Kubernáta395d332019-02-13 16:49:20 +0100122 expected = {"number="};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100123 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100124
Václav Kubernát329c6c32019-02-06 16:41:53 +0100125 SECTION("cd example:list[number")
126 {
127 input = "cd example:list[number";
Václav Kubernáta395d332019-02-13 16:49:20 +0100128 expected = {"number="};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100129 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100130
Václav Kubernát329c6c32019-02-06 16:41:53 +0100131 SECTION("cd example:list[number=12")
132 {
133 input = "cd example:list[number=12";
134 expected = {"]/"};
135 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100136
Václav Kubernát329c6c32019-02-06 16:41:53 +0100137 SECTION("cd example:list[number=12]")
138 {
139 input = "cd example:list[number=12]";
Václav Kubernáta395d332019-02-13 16:49:20 +0100140 expected = {"]/"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100141 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100142
Václav Kubernát329c6c32019-02-06 16:41:53 +0100143 SECTION("cd example:twoKeyList[")
144 {
145 input = "cd example:twoKeyList[";
146 expected = {"name=", "number="};
147 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100148
Václav Kubernát329c6c32019-02-06 16:41:53 +0100149 SECTION("cd example:twoKeyList[name=\"AHOJ\"][")
150 {
151 input = "cd example:twoKeyList[name=\"AHOJ\"][";
152 expected = {"number="};
153 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100154
Václav Kubernát329c6c32019-02-06 16:41:53 +0100155 SECTION("cd example:twoKeyList[number=42][")
156 {
157 input = "cd example:twoKeyList[number=42][";
158 expected = {"name="};
159 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100160
Václav Kubernát329c6c32019-02-06 16:41:53 +0100161 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áta395d332019-02-13 16:49:20 +0100170 expected = {"]/"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100171 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100172 }
173
174 REQUIRE(parser.completeCommand(input, errorStream) == expected);
175}