Merge pathToAbsoluteSchemaString and pathToSchemaString

These functions did almost the same thing, the only difference was that
the former inserted module prefixes everyhwere and the other didn't.
The new function takes an argument specifying whether to insert prefixes
everyhwere.

pathToSchemaString also checks whether a path is absolute or relative
and prepends a slash. This means, that it's no longer possible to
convert and absolute path to a string with no leading slash. The
StaticSchema class had to be changed accordingly, because it stored
absolute paths in strings without a leading slash (because it was
designed before absolute paths existed).

The fact that this was split into two functions helped find an error in
a later patch.

Change-Id: I6112cb5982919b51b61152f355771a52dd467c6e
diff --git a/tests/cd.cpp b/tests/cd.cpp
index 45e7bec..1d03e78 100644
--- a/tests/cd.cpp
+++ b/tests/cd.cpp
@@ -16,16 +16,16 @@
     auto schema = std::make_shared<StaticSchema>();
     schema->addModule("example");
     schema->addModule("second");
-    schema->addContainer("", "example:a");
-    schema->addContainer("", "second:a");
-    schema->addContainer("", "example:b");
-    schema->addContainer("example:a", "example:a2");
-    schema->addContainer("example:b", "example:b2");
-    schema->addContainer("example:a/example:a2", "example:a3");
-    schema->addContainer("example:b/example:b2", "example:b3");
-    schema->addList("", "example:list", {"number"});
-    schema->addContainer("example:list", "example:contInList");
-    schema->addList("", "example:twoKeyList", {"number", "name"});
+    schema->addContainer("/", "example:a");
+    schema->addContainer("/", "second:a");
+    schema->addContainer("/", "example:b");
+    schema->addContainer("/example:a", "example:a2");
+    schema->addContainer("/example:b", "example:b2");
+    schema->addContainer("/example:a/example:a2", "example:a3");
+    schema->addContainer("/example:b/example:b2", "example:b3");
+    schema->addList("/", "example:list", {"number"});
+    schema->addContainer("/example:list", "example:contInList");
+    schema->addList("/", "example:twoKeyList", {"number", "name"});
     Parser parser(schema);
     std::string input;
     std::ostringstream errorStream;
diff --git a/tests/enum_completion.cpp b/tests/enum_completion.cpp
index f3cb2e9..a8ec4d2 100644
--- a/tests/enum_completion.cpp
+++ b/tests/enum_completion.cpp
@@ -15,11 +15,11 @@
 {
     auto schema = std::make_shared<StaticSchema>();
     schema->addModule("mod");
-    schema->addContainer("", "mod:contA");
-    schema->addLeafEnum("", "mod:leafEnum", {"lala", "lol", "data", "coze"});
-    schema->addLeafEnum("mod:contA", "mod:leafInCont", {"abc", "def"});
-    schema->addList("", "mod:list", {"number"});
-    schema->addLeafEnum("mod:list", "mod:leafInList", {"ano", "anoda", "ne", "katoda"});
+    schema->addContainer("/", "mod:contA");
+    schema->addLeafEnum("/", "mod:leafEnum", {"lala", "lol", "data", "coze"});
+    schema->addLeafEnum("/mod:contA", "mod:leafInCont", {"abc", "def"});
+    schema->addList("/", "mod:list", {"number"});
+    schema->addLeafEnum("/mod:list", "mod:leafInList", {"ano", "anoda", "ne", "katoda"});
     Parser parser(schema);
     std::string input;
     std::ostringstream errorStream;
diff --git a/tests/leaf_editing.cpp b/tests/leaf_editing.cpp
index ca9a5da..edf89b4 100644
--- a/tests/leaf_editing.cpp
+++ b/tests/leaf_editing.cpp
@@ -15,7 +15,7 @@
 
 std::ostream& operator<<(std::ostream& s, const set_ cmd)
 {
-    return s << "Command SET {path: " << pathToAbsoluteSchemaString(cmd.m_path) << ", type " << boost::core::demangle(cmd.m_data.type().name()) << ", data: " << leafDataToString(cmd.m_data) << "}";
+    return s << "Command SET {path: " << pathToSchemaString(cmd.m_path, Prefixes::Always) << ", type " << boost::core::demangle(cmd.m_data.type().name()) << ", data: " << leafDataToString(cmd.m_data) << "}";
 }
 
 TEST_CASE("leaf editing")
@@ -23,33 +23,33 @@
     auto schema = std::make_shared<StaticSchema>();
     schema->addModule("mod");
     schema->addModule("pizza-module");
-    schema->addContainer("", "mod:contA");
-    schema->addLeaf("", "mod:leafString", yang::LeafDataTypes::String);
-    schema->addLeaf("", "mod:leafDecimal", yang::LeafDataTypes::Decimal);
-    schema->addLeaf("", "mod:leafBool", yang::LeafDataTypes::Bool);
-    schema->addLeaf("", "mod:leafInt8", yang::LeafDataTypes::Int8);
-    schema->addLeaf("", "mod:leafInt16", yang::LeafDataTypes::Int16);
-    schema->addLeaf("", "mod:leafInt32", yang::LeafDataTypes::Int32);
-    schema->addLeaf("", "mod:leafInt64", yang::LeafDataTypes::Int64);
-    schema->addLeaf("", "mod:leafUint8", yang::LeafDataTypes::Uint8);
-    schema->addLeaf("", "mod:leafUint16", yang::LeafDataTypes::Uint16);
-    schema->addLeaf("", "mod:leafUint32", yang::LeafDataTypes::Uint32);
-    schema->addLeaf("", "mod:leafUint64", yang::LeafDataTypes::Uint64);
-    schema->addLeaf("", "mod:leafBinary", yang::LeafDataTypes::Binary);
+    schema->addContainer("/", "mod:contA");
+    schema->addLeaf("/", "mod:leafString", yang::LeafDataTypes::String);
+    schema->addLeaf("/", "mod:leafDecimal", yang::LeafDataTypes::Decimal);
+    schema->addLeaf("/", "mod:leafBool", yang::LeafDataTypes::Bool);
+    schema->addLeaf("/", "mod:leafInt8", yang::LeafDataTypes::Int8);
+    schema->addLeaf("/", "mod:leafInt16", yang::LeafDataTypes::Int16);
+    schema->addLeaf("/", "mod:leafInt32", yang::LeafDataTypes::Int32);
+    schema->addLeaf("/", "mod:leafInt64", yang::LeafDataTypes::Int64);
+    schema->addLeaf("/", "mod:leafUint8", yang::LeafDataTypes::Uint8);
+    schema->addLeaf("/", "mod:leafUint16", yang::LeafDataTypes::Uint16);
+    schema->addLeaf("/", "mod:leafUint32", yang::LeafDataTypes::Uint32);
+    schema->addLeaf("/", "mod:leafUint64", yang::LeafDataTypes::Uint64);
+    schema->addLeaf("/", "mod:leafBinary", yang::LeafDataTypes::Binary);
     schema->addIdentity(std::nullopt, ModuleValuePair{"mod", "food"});
     schema->addIdentity(std::nullopt, ModuleValuePair{"mod", "vehicle"});
     schema->addIdentity(ModuleValuePair{"mod", "food"}, ModuleValuePair{"mod", "pizza"});
     schema->addIdentity(ModuleValuePair{"mod", "food"}, ModuleValuePair{"mod", "spaghetti"});
     schema->addIdentity(ModuleValuePair{"mod", "pizza"}, ModuleValuePair{"pizza-module", "hawaii"});
-    schema->addLeafIdentityRef("", "mod:foodIdentRef", ModuleValuePair{"mod", "food"});
-    schema->addLeafIdentityRef("", "mod:pizzaIdentRef", ModuleValuePair{"mod", "pizza"});
-    schema->addLeafIdentityRef("mod:contA", "mod:identInCont", ModuleValuePair{"mod", "pizza"});
-    schema->addLeafEnum("", "mod:leafEnum", {"lol", "data", "coze"});
-    schema->addLeaf("mod:contA", "mod:leafInCont", yang::LeafDataTypes::String);
-    schema->addList("", "mod:list", {"number"});
-    schema->addLeaf("mod:list", "mod:leafInList", yang::LeafDataTypes::String);
-    schema->addLeafRef("", "mod:refToString", "mod:leafString");
-    schema->addLeafRef("", "mod:refToInt8", "mod:leafInt8");
+    schema->addLeafIdentityRef("/", "mod:foodIdentRef", ModuleValuePair{"mod", "food"});
+    schema->addLeafIdentityRef("/", "mod:pizzaIdentRef", ModuleValuePair{"mod", "pizza"});
+    schema->addLeafIdentityRef("/mod:contA", "mod:identInCont", ModuleValuePair{"mod", "pizza"});
+    schema->addLeafEnum("/", "mod:leafEnum", {"lol", "data", "coze"});
+    schema->addLeaf("/mod:contA", "mod:leafInCont", yang::LeafDataTypes::String);
+    schema->addList("/", "mod:list", {"number"});
+    schema->addLeaf("/mod:list", "mod:leafInList", yang::LeafDataTypes::String);
+    schema->addLeafRef("/", "mod:refToString", "/mod:leafString");
+    schema->addLeafRef("/", "mod:refToInt8", "/mod:leafInt8");
     Parser parser(schema);
     std::string input;
     std::ostringstream errorStream;
diff --git a/tests/list_manipulation.cpp b/tests/list_manipulation.cpp
index 717ce3a..3fa7a8b 100644
--- a/tests/list_manipulation.cpp
+++ b/tests/list_manipulation.cpp
@@ -13,8 +13,8 @@
 {
     auto schema = std::make_shared<StaticSchema>();
     schema->addModule("mod");
-    schema->addList("", "mod:list", {"number"});
-    schema->addLeaf("mod:list", "mod:leafInList", yang::LeafDataTypes::String);
+    schema->addList("/", "mod:list", {"number"});
+    schema->addLeaf("/mod:list", "mod:leafInList", yang::LeafDataTypes::String);
     Parser parser(schema);
     std::string input;
     std::ostringstream errorStream;
diff --git a/tests/ls.cpp b/tests/ls.cpp
index fffac28..0df428b 100644
--- a/tests/ls.cpp
+++ b/tests/ls.cpp
@@ -16,17 +16,17 @@
     auto schema = std::make_shared<StaticSchema>();
     schema->addModule("example");
     schema->addModule("second");
-    schema->addContainer("", "example:a");
-    schema->addList("example:a", "example:listInCont", {"number"});
-    schema->addContainer("", "second:a");
-    schema->addContainer("", "example:b");
-    schema->addContainer("example:a", "example:a2");
-    schema->addContainer("example:b", "example:b2");
-    schema->addContainer("example:a/example:a2", "example:a3");
-    schema->addContainer("example:b/example:b2", "example:b3");
-    schema->addList("", "example:list", {"number"});
-    schema->addContainer("example:list", "example:contInList");
-    schema->addList("", "example:twoKeyList", {"number", "name"});
+    schema->addContainer("/", "example:a");
+    schema->addList("/example:a", "example:listInCont", {"number"});
+    schema->addContainer("/", "second:a");
+    schema->addContainer("/", "example:b");
+    schema->addContainer("/example:a", "example:a2");
+    schema->addContainer("/example:b", "example:b2");
+    schema->addContainer("/example:a/example:a2", "example:a3");
+    schema->addContainer("/example:b/example:b2", "example:b3");
+    schema->addList("/", "example:list", {"number"});
+    schema->addContainer("/example:list", "example:contInList");
+    schema->addList("/", "example:twoKeyList", {"number", "name"});
     Parser parser(schema);
     std::string input;
     std::ostringstream errorStream;
diff --git a/tests/parser_methods.cpp b/tests/parser_methods.cpp
index 57e6e56..2a84428 100644
--- a/tests/parser_methods.cpp
+++ b/tests/parser_methods.cpp
@@ -28,17 +28,17 @@
     auto schema = std::make_shared<StaticSchema>();
     schema->addModule("example");
     schema->addModule("second");
-    schema->addContainer("", "example:a");
-    schema->addList("example:a", "example:listInCont", {"number"});
-    schema->addContainer("", "second:a");
-    schema->addContainer("", "example:b");
-    schema->addContainer("example:a", "example:a2");
-    schema->addContainer("example:b", "example:b2");
-    schema->addContainer("example:a/example:a2", "example:a3");
-    schema->addContainer("example:b/example:b2", "example:b3");
-    schema->addList("", "example:list", {"number"});
-    schema->addContainer("example:list", "example:contInList");
-    schema->addList("", "example:twoKeyList", {"number", "name"});
+    schema->addContainer("/", "example:a");
+    schema->addList("/example:a", "example:listInCont", {"number"});
+    schema->addContainer("/", "second:a");
+    schema->addContainer("/", "example:b");
+    schema->addContainer("/example:a", "example:a2");
+    schema->addContainer("/example:b", "example:b2");
+    schema->addContainer("/example:a/example:a2", "example:a3");
+    schema->addContainer("/example:b/example:b2", "example:b3");
+    schema->addList("/", "example:list", {"number"});
+    schema->addContainer("/example:list", "example:contInList");
+    schema->addList("/", "example:twoKeyList", {"number", "name"});
     Parser parser(schema);
 
     SECTION("availableNodes")
diff --git a/tests/path_completion.cpp b/tests/path_completion.cpp
index cff254f..115cfdd 100644
--- a/tests/path_completion.cpp
+++ b/tests/path_completion.cpp
@@ -26,21 +26,21 @@
     auto schema = std::make_shared<StaticSchema>();
     schema->addModule("example");
     schema->addModule("second");
-    schema->addContainer("", "example:ano");
-    schema->addContainer("", "example:anoda");
-    schema->addList("example:ano", "example:listInCont", {"number"});
-    schema->addContainer("", "second:amelie");
-    schema->addContainer("", "example:bota");
-    schema->addContainer("example:ano", "example:a2");
-    schema->addContainer("example:bota", "example:b2");
-    schema->addContainer("example:ano/example:a2", "example:a3");
-    schema->addContainer("example:bota/example:b2", "example:b3");
-    schema->addList("", "example:list", {"number"});
-    schema->addList("", "example:ovoce", {"name"});
-    schema->addList("", "example:ovocezelenina", {"name"});
-    schema->addContainer("example:list", "example:contInList");
-    schema->addList("", "example:twoKeyList", {"number", "name"});
-    schema->addLeaf("", "example:leafInt", yang::LeafDataTypes::Int32);
+    schema->addContainer("/", "example:ano");
+    schema->addContainer("/", "example:anoda");
+    schema->addList("/example:ano", "example:listInCont", {"number"});
+    schema->addContainer("/", "second:amelie");
+    schema->addContainer("/", "example:bota");
+    schema->addContainer("/example:ano", "example:a2");
+    schema->addContainer("/example:bota", "example:b2");
+    schema->addContainer("/example:ano/example:a2", "example:a3");
+    schema->addContainer("/example:bota/example:b2", "example:b3");
+    schema->addList("/", "example:list", {"number"});
+    schema->addList("/", "example:ovoce", {"name"});
+    schema->addList("/", "example:ovocezelenina", {"name"});
+    schema->addContainer("/example:list", "example:contInList");
+    schema->addList("/", "example:twoKeyList", {"number", "name"});
+    schema->addLeaf("/", "example:leafInt", yang::LeafDataTypes::Int32);
     Parser parser(schema);
     std::string input;
     std::ostringstream errorStream;
diff --git a/tests/path_utils.cpp b/tests/path_utils.cpp
index eba2b34..f8dc250 100644
--- a/tests/path_utils.cpp
+++ b/tests/path_utils.cpp
@@ -28,6 +28,6 @@
             path.m_nodes.push_back(dataNode_{module_{"example-schema"}, listElement_{"twoKeyList", {{"first", "a"}, {"second", "b"}}}});
             expected += "example-schema:twoKeyList[first='a'][second='b']";
         }
-        REQUIRE(pathToDataString(path) == expected);
+        REQUIRE(pathToDataString(path, Prefixes::WhenNeeded) == expected);
     }
 }
diff --git a/tests/presence_containers.cpp b/tests/presence_containers.cpp
index e027fb9..ba8938e 100644
--- a/tests/presence_containers.cpp
+++ b/tests/presence_containers.cpp
@@ -16,13 +16,13 @@
 {
     auto schema = std::make_shared<StaticSchema>();
     schema->addModule("mod");
-    schema->addContainer("", "mod:a", yang::ContainerTraits::Presence);
-    schema->addContainer("", "mod:b");
-    schema->addContainer("mod:a", "mod:a2");
-    schema->addContainer("mod:a/mod:a2", "mod:a3", yang::ContainerTraits::Presence);
-    schema->addContainer("mod:b", "mod:b2", yang::ContainerTraits::Presence);
-    schema->addList("", "mod:list", {"quote"});
-    schema->addContainer("mod:list", "mod:contInList", yang::ContainerTraits::Presence);
+    schema->addContainer("/", "mod:a", yang::ContainerTraits::Presence);
+    schema->addContainer("/", "mod:b");
+    schema->addContainer("/mod:a", "mod:a2");
+    schema->addContainer("/mod:a/mod:a2", "mod:a3", yang::ContainerTraits::Presence);
+    schema->addContainer("/mod:b", "mod:b2", yang::ContainerTraits::Presence);
+    schema->addList("/", "mod:list", {"quote"});
+    schema->addContainer("/mod:list", "mod:contInList", yang::ContainerTraits::Presence);
     Parser parser(schema);
     std::string input;
     std::ostringstream errorStream;
@@ -80,7 +80,7 @@
         create_ create = boost::get<create_>(commandCreate);
         REQUIRE(create == expectedCreate);
 
-        REQUIRE(pathToDataString(create.m_path) == input);
+        REQUIRE(pathToDataString(create.m_path, Prefixes::WhenNeeded) == input);
 
         delete_ expectedDelete;
         expectedDelete.m_path = expectedPath;
diff --git a/tests/yang.cpp b/tests/yang.cpp
index d519825..fa394b5 100644
--- a/tests/yang.cpp
+++ b/tests/yang.cpp
@@ -284,7 +284,7 @@
     });
     ys.addSchemaString(second_schema);
 
-    schemaPath_ path;
+    schemaPath_ path{Scope::Absolute, {}};
     ModuleNodePair node;
 
     SECTION("positive")