Merge "Update the NETCONF stack"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ffc9230..c5058b7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -234,6 +234,7 @@
     cli_test(command_completion)
     cli_test(enum_completion)
     cli_test(list_manipulation)
+    cli_test(parser_methods)
     datastore_test(sysrepo sysrepo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/example-schema.yang)
     target_link_libraries(test_sysrepo sysrepoaccess yangschema)
     datastore_test(netconf sysrepo.cpp ${CMAKE_CURRENT_SOURCE_DIR}/example-schema.yang)
diff --git a/src/parser.cpp b/src/parser.cpp
index 420db27..26e186a 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -100,7 +100,11 @@
     auto pathArg = dataPathToSchemaPath(m_curDir);
     if (path) {
         auto schemaPath = boost::apply_visitor(getSchemaPathVisitor(), *path);
-        pathArg.m_nodes.insert(pathArg.m_nodes.end(), schemaPath.m_nodes.begin(), schemaPath.m_nodes.end());
+        if (schemaPath.m_scope == Scope::Absolute) {
+            pathArg = schemaPath;
+        } else {
+            pathArg.m_nodes.insert(pathArg.m_nodes.end(), schemaPath.m_nodes.begin(), schemaPath.m_nodes.end());
+        }
     }
     return m_schema->childNodes(pathArg, option);
 }
diff --git a/src/static_schema.cpp b/src/static_schema.cpp
index 6d28626..280f0da 100644
--- a/src/static_schema.cpp
+++ b/src/static_schema.cpp
@@ -91,7 +91,8 @@
 {
     m_nodes.at(location).emplace(name, yang::list{keys});
 
-    m_nodes.emplace(name, std::unordered_map<std::string, NodeType>());
+    std::string key = joinPaths(location, name);
+    m_nodes.emplace(key, std::unordered_map<std::string, NodeType>());
 }
 
 bool StaticSchema::isPresenceContainer(const schemaPath_& location, const ModuleNodePair& node) const
diff --git a/tests/parser_methods.cpp b/tests/parser_methods.cpp
new file mode 100644
index 0000000..d8080b3
--- /dev/null
+++ b/tests/parser_methods.cpp
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
+ * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
+ *
+ * Written by Václav Kubernát <kubervac@fit.cvut.cz>
+ *
+*/
+
+#include <experimental/iterator>
+#include "trompeloeil_doctest.h"
+#include "ast_commands.hpp"
+#include "parser.hpp"
+#include "static_schema.hpp"
+
+namespace std {
+std::ostream& operator<<(std::ostream& s, const std::set<std::string> set)
+{
+    s << std::endl
+      << "{";
+    std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", "));
+    s << "}" << std::endl;
+    return s;
+}
+}
+
+TEST_CASE("parser methods")
+{
+    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"});
+    Parser parser(schema);
+
+    SECTION("availableNodes")
+    {
+        std::set<std::string> expected;
+        boost::optional<boost::variant<dataPath_, schemaPath_>> arg{boost::none};
+        SECTION("cwd: /")
+        {
+            SECTION("arg: <none>")
+            {
+                expected = {"example:a", "example:b", "example:list", "example:twoKeyList", "second:a"};
+            }
+
+            SECTION("arg: example:a")
+            {
+                arg = dataPath_{Scope::Relative, {{module_{"example"}, container_{"a"}}}};
+                expected = {"example:a2", "example:listInCont"};
+            }
+
+            SECTION("arg: example:list")
+            {
+                arg = dataPath_{Scope::Relative, {{module_{"example"}, list_{"list"}}}};
+                expected = {"example:contInList"};
+            }
+
+            SECTION("arg: /example:a")
+            {
+                arg = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}}}};
+                expected = {"example:a2", "example:listInCont"};
+            }
+
+            SECTION("arg: /example:list")
+            {
+                arg = dataPath_{Scope::Absolute, {{module_{"example"}, list_{"list"}}}};
+                expected = {"example:contInList"};
+            }
+        }
+        SECTION("cwd: /example:a")
+        {
+            parser.changeNode({Scope::Relative, {{module_{"example"}, container_{"a"}}}});
+
+            SECTION("arg: <none>")
+            {
+                expected = {"example:a2", "example:listInCont"};
+            }
+
+            SECTION("arg: example:a2")
+            {
+                arg = dataPath_{Scope::Relative, {{container_{"a2"}}}};
+                expected = {"example:a3"};
+            }
+
+            SECTION("arg: example:listInCont")
+            {
+                arg = dataPath_{Scope::Relative, {{list_{"listInCont"}}}};
+            }
+
+            SECTION("arg: /example:a")
+            {
+                arg = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}}}};
+                expected = {"example:a2", "example:listInCont"};
+            }
+
+            SECTION("arg: /example:list")
+            {
+                arg = dataPath_{Scope::Absolute, {{module_{"example"}, list_{"list"}}}};
+                expected = {"example:contInList"};
+            }
+        }
+        SECTION("cwd: /example:list")
+        {
+            parser.changeNode({Scope::Relative, {{module_{"example"}, list_{"list"}}}});
+
+            SECTION("arg: <none>")
+            {
+                expected = {"example:contInList"};
+            }
+
+            SECTION("arg: example:contInList")
+            {
+                arg = dataPath_{Scope::Relative, {{container_{"contInList"}}}};
+            }
+
+            SECTION("arg: /example:a")
+            {
+                arg = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}}}};
+                expected = {"example:a2", "example:listInCont"};
+            }
+
+            SECTION("arg: /example:list")
+            {
+                arg = dataPath_{Scope::Absolute, {{module_{"example"}, list_{"list"}}}};
+                expected = {"example:contInList"};
+            }
+        }
+
+        REQUIRE(expected == parser.availableNodes(arg, Recursion::NonRecursive));
+    }
+}