blob: 7a9090b7be853e363f9a2ca58070621723f89714 [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";
47 expected = {"xample:ano", "xample:anoda", "xample:bota", "xample:list", "xample:twoKeyList"};
48 }
49
50 SECTION("ls example:ano")
51 {
52 input = "ls example:ano";
53 expected = {"", "da"};
54 }
55
56 SECTION("ls example:ano/example:a")
57 {
58 input = "ls example:ano/example:a";
59 expected = {"2"};
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";
77 expected = {"xample:ano", "xample:anoda", "xample:bota", "xample:list", "xample:twoKeyList"};
78 }
79
80 SECTION("ls /s")
81 {
82 input = "ls /s";
83 expected = {"econd:amelie"};
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";
95 expected = {"xample:contInList"};
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á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";
110 expected = {"t"};
111 }
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";
122 expected = {"er="};
123 }
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";
128 expected = {"="};
129 }
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]";
140 expected = {"/"};
141 }
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]";
170 expected = {"/"};
171 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100172 }
173
174 REQUIRE(parser.completeCommand(input, errorStream) == expected);
175}