Fix pathToDataString

The function wasn't properly converting multi-keyed lists. It also
didn't care if the path was absolute. This patch fixes both of these
issues.

Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/143
Change-Id: I4c3d19202be28e84b1db9a8311f49b848ef48a34
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e0be51d..2abb379 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -261,6 +261,7 @@
     cli_test(enum_completion)
     cli_test(list_manipulation)
     cli_test(parser_methods)
+    cli_test(path_utils)
 
     setup_datastore_tests()
     datastore_test(setting_values ${CMAKE_CURRENT_SOURCE_DIR}/example-schema.yang)
diff --git a/src/ast_path.cpp b/src/ast_path.cpp
index 861e52d..3a486a5 100644
--- a/src/ast_path.cpp
+++ b/src/ast_path.cpp
@@ -137,7 +137,7 @@
         std::ostringstream res;
         res << node.m_name + "[";
         std::transform(node.m_keys.begin(), node.m_keys.end(),
-                std::experimental::make_ostream_joiner(res, ' '),
+                std::experimental::make_ostream_joiner(res, "]["),
                 [] (const auto& it) { return it.first + "=" + escapeListKeyString(it.second); });
         res << "]";
         return res.str();
@@ -161,6 +161,9 @@
 std::string pathToDataString(const dataPath_& path)
 {
     std::string res;
+    if (path.m_scope == Scope::Absolute) {
+        res = "/";
+    }
     for (const auto it : path.m_nodes)
         if (it.m_prefix)
             res = joinPaths(res, it.m_prefix.value().m_name + ":" + boost::apply_visitor(nodeToDataStringVisitor(), it.m_suffix));
diff --git a/tests/path_utils.cpp b/tests/path_utils.cpp
new file mode 100644
index 0000000..eba2b34
--- /dev/null
+++ b/tests/path_utils.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2019 CESNET, https://photonics.cesnet.cz/
+ *
+ * Written by Václav Kubernát <kubervac@fit.cvut.cz>
+ *
+*/
+
+#include "trompeloeil_doctest.h"
+#include "ast_path.hpp"
+
+TEST_CASE("path utils")
+{
+    SECTION("pathToDataString")
+    {
+        dataPath_ path;
+        std::string expected;
+        SECTION("example-schema:twoKeyList[first='a'][second='b']")
+        {
+            SECTION("absolute")
+            {
+                path.m_scope = Scope::Absolute;
+                expected += "/";
+            }
+            SECTION("relative")
+            {
+                path.m_scope = Scope::Relative;
+            }
+            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);
+    }
+}