blob: 0359675463428695f30632bc2afcfb6ad22412c6 [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"});
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át51853b22019-04-16 21:53:44 +0200113 SECTION("set example:list")
114 {
115 input = "set example:list";
116 expected = {"example:list"};
117 }
118
Václav Kubernát329c6c32019-02-06 16:41:53 +0100119 SECTION("cd example:list[")
120 {
121 input = "cd example:list[";
122 expected = {"number="};
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[numb")
126 {
127 input = "cd example:list[numb";
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")
132 {
133 input = "cd example:list[number";
Václav Kubernáta395d332019-02-13 16:49:20 +0100134 expected = {"number="};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100135 }
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:list[number=12]")
144 {
145 input = "cd example:list[number=12]";
Václav Kubernáta395d332019-02-13 16:49:20 +0100146 expected = {"]/"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100147 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100148
Václav Kubernát329c6c32019-02-06 16:41:53 +0100149 SECTION("cd example:twoKeyList[")
150 {
151 input = "cd example:twoKeyList[";
152 expected = {"name=", "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[name=\"AHOJ\"][")
156 {
157 input = "cd example:twoKeyList[name=\"AHOJ\"][";
158 expected = {"number="};
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[number=42][")
162 {
163 input = "cd example:twoKeyList[number=42][";
164 expected = {"name="};
165 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100166
Václav Kubernát329c6c32019-02-06 16:41:53 +0100167 SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123")
168 {
169 input = "cd example:twoKeyList[name=\"AHOJ\"][number=123";
170 expected = {"]/"};
171 }
172
173 SECTION("cd example:twoKeyList[name=\"AHOJ\"][number=123]")
174 {
175 input = "cd example:twoKeyList[name=\"AHOJ\"][number=123]";
Václav Kubernáta395d332019-02-13 16:49:20 +0100176 expected = {"]/"};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100177 }
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100178 }
179
180 REQUIRE(parser.completeCommand(input, errorStream) == expected);
181}