blob: 4f7a4825db8bf1ca0164c5fbc94e9ccf16711543 [file] [log] [blame]
Václav Kubernát1446fe12019-10-02 19:32:51 +02001/*
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 <experimental/iterator>
Václav Kubernát26b56082020-02-03 18:28:56 +010010#include "trompeloeil_doctest.hpp"
Václav Kubernát1446fe12019-10-02 19:32:51 +020011#include "ast_commands.hpp"
12#include "parser.hpp"
13#include "static_schema.hpp"
14
15namespace std {
16std::ostream& operator<<(std::ostream& s, const std::set<std::string> set)
17{
18 s << std::endl
19 << "{";
20 std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", "));
21 s << "}" << std::endl;
22 return s;
23}
24}
25
26TEST_CASE("parser methods")
27{
28 auto schema = std::make_shared<StaticSchema>();
29 schema->addModule("example");
30 schema->addModule("second");
Václav Kubernátefcac932020-01-10 15:26:32 +010031 schema->addContainer("/", "example:a");
32 schema->addList("/example:a", "example:listInCont", {"number"});
33 schema->addContainer("/", "second:a");
34 schema->addContainer("/", "example:b");
35 schema->addContainer("/example:a", "example:a2");
36 schema->addContainer("/example:b", "example:b2");
37 schema->addContainer("/example:a/example:a2", "example:a3");
38 schema->addContainer("/example:b/example:b2", "example:b3");
39 schema->addList("/", "example:list", {"number"});
40 schema->addContainer("/example:list", "example:contInList");
41 schema->addList("/", "example:twoKeyList", {"number", "name"});
Václav Kubernát1446fe12019-10-02 19:32:51 +020042 Parser parser(schema);
43
44 SECTION("availableNodes")
45 {
46 std::set<std::string> expected;
Václav Kubernátbeaa8aa2020-04-29 22:39:34 +020047 boost::optional<boost::variant<dataPath_, schemaPath_, module_>> arg{boost::none};
Václav Kubernát1446fe12019-10-02 19:32:51 +020048 SECTION("cwd: /")
49 {
50 SECTION("arg: <none>")
51 {
52 expected = {"example:a", "example:b", "example:list", "example:twoKeyList", "second:a"};
53 }
54
55 SECTION("arg: example:a")
56 {
57 arg = dataPath_{Scope::Relative, {{module_{"example"}, container_{"a"}}}};
58 expected = {"example:a2", "example:listInCont"};
59 }
60
61 SECTION("arg: example:list")
62 {
63 arg = dataPath_{Scope::Relative, {{module_{"example"}, list_{"list"}}}};
64 expected = {"example:contInList"};
65 }
66
67 SECTION("arg: /example:a")
68 {
69 arg = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}}}};
70 expected = {"example:a2", "example:listInCont"};
71 }
72
73 SECTION("arg: /example:list")
74 {
75 arg = dataPath_{Scope::Absolute, {{module_{"example"}, list_{"list"}}}};
76 expected = {"example:contInList"};
77 }
78 }
79 SECTION("cwd: /example:a")
80 {
81 parser.changeNode({Scope::Relative, {{module_{"example"}, container_{"a"}}}});
82
83 SECTION("arg: <none>")
84 {
85 expected = {"example:a2", "example:listInCont"};
86 }
87
88 SECTION("arg: example:a2")
89 {
90 arg = dataPath_{Scope::Relative, {{container_{"a2"}}}};
91 expected = {"example:a3"};
92 }
93
94 SECTION("arg: example:listInCont")
95 {
96 arg = dataPath_{Scope::Relative, {{list_{"listInCont"}}}};
97 }
98
99 SECTION("arg: /example:a")
100 {
101 arg = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}}}};
102 expected = {"example:a2", "example:listInCont"};
103 }
104
105 SECTION("arg: /example:list")
106 {
107 arg = dataPath_{Scope::Absolute, {{module_{"example"}, list_{"list"}}}};
108 expected = {"example:contInList"};
109 }
110 }
111 SECTION("cwd: /example:list")
112 {
113 parser.changeNode({Scope::Relative, {{module_{"example"}, list_{"list"}}}});
114
115 SECTION("arg: <none>")
116 {
117 expected = {"example:contInList"};
118 }
119
120 SECTION("arg: example:contInList")
121 {
122 arg = dataPath_{Scope::Relative, {{container_{"contInList"}}}};
123 }
124
125 SECTION("arg: /example:a")
126 {
127 arg = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}}}};
128 expected = {"example:a2", "example:listInCont"};
129 }
130
131 SECTION("arg: /example:list")
132 {
133 arg = dataPath_{Scope::Absolute, {{module_{"example"}, list_{"list"}}}};
134 expected = {"example:contInList"};
135 }
136 }
137
138 REQUIRE(expected == parser.availableNodes(arg, Recursion::NonRecursive));
139 }
140}