Split path_ into schemaPath_ and dataPath_
This change is necessary because different commands accept different
kinds of paths (for example "cd" only accepts a data path, on the other
hand "ls" doesn't care about data, so it accepts both). One option was to
create a new path struct for every command, but that could get quickly
out of control as new commands get added. The other option was define only
the data path and schema path and then change the commands' grammars, so
that they only accept the relevant paths, but in the end always return a
data path or a schema path.
Change-Id: I7668a446fbf674c7a5deae22d9aacdfb3da9b07e
diff --git a/tests/cd.cpp b/tests/cd.cpp
index ffa4bbf..85ea794 100644
--- a/tests/cd.cpp
+++ b/tests/cd.cpp
@@ -40,40 +40,40 @@
SECTION("example:a")
{
input = "cd example:a";
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("a")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("a")));
}
SECTION("second:a")
{
input = "cd second:a";
- expected.m_path.m_nodes.push_back(node_(module_{"second"}, container_("a")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"second"}, container_("a")));
}
SECTION("example:b")
{
input = "cd example:b";
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("b")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("b")));
}
SECTION("example:a/a2")
{
input = "cd example:a/a2";
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("a")));
- expected.m_path.m_nodes.push_back(node_(container_("a2")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("a")));
+ expected.m_path.m_nodes.push_back(dataNode_(container_("a2")));
}
SECTION("example:a/example:a2")
{
input = "cd example:a/example:a2";
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("a")));
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("a2")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("a")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("a2")));
}
SECTION("example:b/b2")
{
input = "cd example:b/b2";
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("b")));
- expected.m_path.m_nodes.push_back(node_(container_("b2")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("b")));
+ expected.m_path.m_nodes.push_back(dataNode_(container_("b2")));
}
}
@@ -84,7 +84,7 @@
input = "cd example:list[number=1]";
auto keys = std::map<std::string, std::string>{
{"number", "1"}};
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, listElement_("list", keys)));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, listElement_("list", keys)));
}
SECTION("example:list[number=1]/contInList")
@@ -92,8 +92,8 @@
input = "cd example:list[number=1]/contInList";
auto keys = std::map<std::string, std::string>{
{"number", "1"}};
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, listElement_("list", keys)));
- expected.m_path.m_nodes.push_back(node_(container_("contInList")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, listElement_("list", keys)));
+ expected.m_path.m_nodes.push_back(dataNode_(container_("contInList")));
}
SECTION("example:twoKeyList[number=4][name='abcd']")
@@ -102,7 +102,7 @@
auto keys = std::map<std::string, std::string>{
{"number", "4"},
{"name", "abcd"}};
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, listElement_("twoKeyList", keys)));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, listElement_("twoKeyList", keys)));
}
}
@@ -111,7 +111,7 @@
SECTION(" cd example:a ")
{
input = " cd example:a ";
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("a")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("a")));
}
}
@@ -120,25 +120,25 @@
SECTION("example:a/..")
{
input = "cd example:a/..";
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("a")));
- expected.m_path.m_nodes.push_back(node_(nodeup_()));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("a")));
+ expected.m_path.m_nodes.push_back(dataNode_(nodeup_()));
}
SECTION("example:a/../example:a")
{
input = "cd example:a/../example:a";
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("a")));
- expected.m_path.m_nodes.push_back(node_(nodeup_()));
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("a")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("a")));
+ expected.m_path.m_nodes.push_back(dataNode_(nodeup_()));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("a")));
}
SECTION("example:a/../example:a/a2")
{
input = "cd example:a/../example:a/a2";
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("a")));
- expected.m_path.m_nodes.push_back(node_(nodeup_()));
- expected.m_path.m_nodes.push_back(node_(module_{"example"}, container_("a")));
- expected.m_path.m_nodes.push_back(node_(container_("a2")));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("a")));
+ expected.m_path.m_nodes.push_back(dataNode_(nodeup_()));
+ expected.m_path.m_nodes.push_back(dataNode_(module_{"example"}, container_("a")));
+ expected.m_path.m_nodes.push_back(dataNode_(container_("a2")));
}
}
diff --git a/tests/leaf_editing.cpp b/tests/leaf_editing.cpp
index a0eeed3..757a617 100644
--- a/tests/leaf_editing.cpp
+++ b/tests/leaf_editing.cpp
@@ -36,15 +36,15 @@
SECTION("set leafString some_data")
{
input = "set mod:leafString some_data";
- expected.m_path.m_nodes.push_back(node_{module_{"mod"}, leaf_("leafString")});
+ expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
expected.m_data = std::string("some_data");
}
SECTION("set mod:contA/leafInCont more_data")
{
input = "set mod:contA/leafInCont more_data";
- expected.m_path.m_nodes.push_back(node_{module_{"mod"}, container_("contA")});
- expected.m_path.m_nodes.push_back(node_{leaf_("leafInCont")});
+ expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, container_("contA")});
+ expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInCont")});
expected.m_data = std::string("more_data");
}
@@ -53,8 +53,8 @@
input = "set mod:list[number=1]/leafInList another_data";
auto keys = std::map<std::string, std::string>{
{"number", "1"}};
- expected.m_path.m_nodes.push_back(node_{module_{"mod"}, listElement_("list", keys)});
- expected.m_path.m_nodes.push_back(node_{leaf_("leafInList")});
+ expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)});
+ expected.m_path.m_nodes.push_back(dataNode_{leaf_("leafInList")});
expected.m_data = std::string("another_data");
}
@@ -63,35 +63,35 @@
SECTION("string")
{
input = "set mod:leafString somedata";
- expected.m_path.m_nodes.push_back(node_{module_{"mod"}, leaf_("leafString")});
+ expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafString")});
expected.m_data = std::string("somedata");
}
SECTION("int")
{
input = "set mod:leafInt 2";
- expected.m_path.m_nodes.push_back(node_{module_{"mod"}, leaf_("leafInt")});
+ expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafInt")});
expected.m_data = 2;
}
SECTION("decimal")
{
input = "set mod:leafDecimal 3.14159";
- expected.m_path.m_nodes.push_back(node_{module_{"mod"}, leaf_("leafDecimal")});
+ expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafDecimal")});
expected.m_data = 3.14159;
}
SECTION("enum")
{
input = "set mod:leafEnum coze";
- expected.m_path.m_nodes.push_back(node_{module_{"mod"}, leaf_("leafEnum")});
+ expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafEnum")});
expected.m_data = enum_("coze");
}
SECTION("bool")
{
input = "set mod:leafBool true";
- expected.m_path.m_nodes.push_back(node_{module_{"mod"}, leaf_("leafBool")});
+ expected.m_path.m_nodes.push_back(dataNode_{module_{"mod"}, leaf_("leafBool")});
expected.m_data = true;
}
}
diff --git a/tests/ls.cpp b/tests/ls.cpp
index 47d28ed..d202a1c 100644
--- a/tests/ls.cpp
+++ b/tests/ls.cpp
@@ -51,81 +51,81 @@
SECTION("ls example:a")
{
input = "ls example:a";
- expected.m_path = path_{Scope::Relative, {node_(module_{"example"}, container_{"a"})}};
+ expected.m_path = dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a"})}};
}
SECTION("ls /example:a")
{
SECTION("cwd: /") {}
- SECTION("cwd: /example:a") {parser.changeNode(path_{Scope::Relative, {node_(module_{"example"}, container_{"a"})}});}
+ SECTION("cwd: /example:a") {parser.changeNode(dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a"})}});}
input = "ls /example:a";
- expected.m_path = path_{Scope::Absolute, {node_(module_{"example"}, container_{"a"})}};
+ expected.m_path = dataPath_{Scope::Absolute, {dataNode_(module_{"example"}, container_{"a"})}};
}
SECTION("ls /")
{
SECTION("cwd: /") {}
- SECTION("cwd: /example:a") {parser.changeNode(path_{Scope::Relative, {node_(module_{"example"}, container_{"a"})}});}
+ SECTION("cwd: /example:a") {parser.changeNode(dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a"})}});}
input = "ls /";
- expected.m_path = path_{Scope::Absolute, {}};
+ expected.m_path = dataPath_{Scope::Absolute, {}};
}
SECTION("ls example:a/a2")
{
input = "ls example:a/a2";
- expected.m_path = path_{Scope::Relative, {node_(module_{"example"}, container_{"a"}),
- node_(container_{"a2"})}};
+ expected.m_path = dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a"}),
+ dataNode_(container_{"a2"})}};
}
SECTION("ls a2")
{
- parser.changeNode(path_{Scope::Relative, {node_(module_{"example"}, container_{"a"})}});
+ parser.changeNode(dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a"})}});
input = "ls a2";
- expected.m_path = path_{Scope::Relative, {node_(container_{"a2"})}};
+ expected.m_path = dataPath_{Scope::Relative, {dataNode_(container_{"a2"})}};
}
SECTION("ls /example:a/a2")
{
SECTION("cwd: /") {}
- SECTION("cwd: /example:a") {parser.changeNode(path_{Scope::Relative, {node_(module_{"example"}, container_{"a"})}});}
+ SECTION("cwd: /example:a") {parser.changeNode(dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a"})}});}
input = "ls /example:a/a2";
- expected.m_path = path_{Scope::Absolute, {node_(module_{"example"}, container_{"a"}),
- node_(container_{"a2"})}};
+ expected.m_path = dataPath_{Scope::Absolute, {dataNode_(module_{"example"}, container_{"a"}),
+ dataNode_(container_{"a2"})}};
}
SECTION("ls example:a/example:a2")
{
input = "ls example:a/example:a2";
- expected.m_path = path_{Scope::Relative, {node_(module_{"example"}, container_{"a"}),
- node_(module_{"example"}, container_{"a2"})}};
+ expected.m_path = dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a"}),
+ dataNode_(module_{"example"}, container_{"a2"})}};
}
SECTION("ls example:a2")
{
- parser.changeNode(path_{Scope::Relative, {node_(module_{"example"}, container_{"a"})}});
+ parser.changeNode(dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a"})}});
input = "ls example:a2";
- expected.m_path = path_{Scope::Relative, {node_(module_{"example"}, container_{"a2"})}};
+ expected.m_path = dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a2"})}};
}
SECTION("ls /example:a/example:a2")
{
SECTION("cwd: /") {}
- SECTION("cwd: /example:a") {parser.changeNode(path_{Scope::Relative, {node_(module_{"example"}, container_{"a"})}});}
+ SECTION("cwd: /example:a") {parser.changeNode(dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a"})}});}
input = "ls /example:a/example:a2";
- expected.m_path = path_{Scope::Absolute, {node_(module_{"example"}, container_{"a"}),
- node_(module_{"example"}, container_{"a2"})}};
+ expected.m_path = dataPath_{Scope::Absolute, {dataNode_(module_{"example"}, container_{"a"}),
+ dataNode_(module_{"example"}, container_{"a2"})}};
}
SECTION("ls --recursive /example:a")
{
SECTION("cwd: /") {}
- SECTION("cwd: /example:a") {parser.changeNode(path_{Scope::Relative, {node_(module_{"example"}, container_{"a"})}});}
+ SECTION("cwd: /example:a") {parser.changeNode(dataPath_{Scope::Relative, {dataNode_(module_{"example"}, container_{"a"})}});}
input = "ls --recursive /example:a";
expected.m_options.push_back(LsOption::Recursive);
- expected.m_path = path_{Scope::Absolute, {node_(module_{"example"}, container_{"a"})}};
+ expected.m_path = dataPath_{Scope::Absolute, {dataNode_(module_{"example"}, container_{"a"})}};
}
}
diff --git a/tests/presence_containers.cpp b/tests/presence_containers.cpp
index 5a43ce9..6872d1b 100644
--- a/tests/presence_containers.cpp
+++ b/tests/presence_containers.cpp
@@ -29,7 +29,7 @@
SECTION("valid input")
{
- path_ expectedPath;
+ dataPath_ expectedPath;
SECTION("mod:a")
{
diff --git a/tests/yang.cpp b/tests/yang.cpp
index dc2286d..76b3c15 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -124,7 +124,7 @@
{
YangSchema ys;
ys.addSchemaString(schema);
- path_ path;
+ schemaPath_ path;
ModuleNodePair node;
SECTION("positive")
@@ -139,7 +139,7 @@
SECTION("example-schema:a/a2")
{
- path.m_nodes.push_back(node_(module_{"example-schema"}, container_("a")));
+ path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
node.second = "a2";
}
@@ -155,7 +155,7 @@
SECTION("example-schema:a/leafa")
{
- path.m_nodes.push_back(node_(module_{"example-schema"}, container_("a")));
+ path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
node.first = "example-schema";
node.second = "leafa";
}
@@ -186,8 +186,8 @@
{
SECTION("example-schema:a/a2/a3")
{
- path.m_nodes.push_back(node_(module_{"example-schema"}, container_("a")));
- path.m_nodes.push_back(node_(module_{"example-schema"}, container_("a2")));
+ path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
+ path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a2")));
node.second = "a3";
}
@@ -359,7 +359,7 @@
SECTION("a")
{
- path.m_nodes.push_back(node_(module_{"example-schema"}, container_("a")));
+ path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
set = {"example-schema:a2", "example-schema:leafa"};
}
@@ -379,13 +379,13 @@
SECTION("example-schema:a/nevim")
{
- path.m_nodes.push_back(node_(module_{"example-schema"}, container_("a")));
+ path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
node.second = "nevim";
}
SECTION("modul:a/nevim")
{
- path.m_nodes.push_back(node_(module_{"modul"}, container_("a")));
+ path.m_nodes.push_back(schemaNode_(module_{"modul"}, container_("a")));
node.second = "nevim";
}
@@ -405,7 +405,7 @@
SECTION("example-schema:a/a2")
{
- path.m_nodes.push_back(node_(module_{"example-schema"}, container_("a")));
+ path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
node.second = "a2";
}
@@ -416,7 +416,7 @@
SECTION("nodetype-specific methods called with different nodetypes")
{
- path.m_nodes.push_back(node_(module_{"example-schema"}, container_("a")));
+ path.m_nodes.push_back(schemaNode_(module_{"example-schema"}, container_("a")));
node.second = "a2";
REQUIRE(!ys.leafEnumHasValue(path, node, "haha"));