Allow going up with ".." when in root

Issue: https://tree.taiga.io/project/jktjkt-netconf-cli/issue/176
Change-Id: I23797edf159d39efe4e58b1d7c560aa3c13117b3
diff --git a/src/parser.cpp b/src/parser.cpp
index ce583ea..4911fac 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -86,10 +86,13 @@
         m_curDir = name;
     } else {
         for (const auto& it : name.m_nodes) {
-            if (std::holds_alternative<nodeup_>(it.m_suffix))
-                m_curDir.m_nodes.pop_back();
-            else
+            if (std::holds_alternative<nodeup_>(it.m_suffix)) {
+                if (!m_curDir.m_nodes.empty()) { // Allow going up, when already at root
+                    m_curDir.m_nodes.pop_back();
+                }
+            } else {
                 m_curDir.m_nodes.push_back(it);
+            }
         }
     }
 }
diff --git a/src/parser_context.cpp b/src/parser_context.cpp
index 723fbae..d1ebe06 100644
--- a/src/parser_context.cpp
+++ b/src/parser_context.cpp
@@ -41,7 +41,9 @@
 {
     auto pushNode = [] (auto& where, const auto& what) {
         if (std::holds_alternative<nodeup_>(what.m_suffix)) {
-            where.m_nodes.pop_back();
+            if (!where.m_nodes.empty()) { // Allow going up, when already at root
+                where.m_nodes.pop_back();
+            }
         } else {
             where.m_nodes.push_back(what);
         }
diff --git a/tests/cd.cpp b/tests/cd.cpp
index f85593b..e0d6293 100644
--- a/tests/cd.cpp
+++ b/tests/cd.cpp
@@ -136,6 +136,19 @@
 
         SECTION("moving up")
         {
+            SECTION("moving up when already in root")
+            {
+                input = "cd ..";
+                expected.m_path.m_nodes.push_back(dataNode_(nodeup_()));
+            }
+
+            SECTION("moving up TWICE when already in root")
+            {
+                input = "cd ../..";
+                expected.m_path.m_nodes.push_back(dataNode_(nodeup_()));
+                expected.m_path.m_nodes.push_back(dataNode_(nodeup_()));
+            }
+
             SECTION("example:a/..")
             {
                 input = "cd example:a/..";