tests: don't crash on missing prefixes

I'm adding some tests for setting leafs while `cd`-ed away from the
root. After an equivalent of `cd mod:contA`, a simple `set leafInCont
"X"` would throw.

I think that the only reason why this doesn't crash "in production" is
that the parser itself never calls `pathToDataString` or
`pathToSchemaString` directly when "just" using the CLI. The tests do
that while printing these commands, though.

Change-Id: Icc0ccdc28ea0c31ee823316d061b7c195b4df0da
diff --git a/src/ast_path.cpp b/src/ast_path.cpp
index 33b25fe..e0348db 100644
--- a/src/ast_path.cpp
+++ b/src/ast_path.cpp
@@ -267,7 +267,7 @@
         if (it.m_prefix) {
             res = joinPaths(res, it.m_prefix.value().m_name + ":" + std::visit(nodeToDataStringVisitor(), it.m_suffix));
         } else {
-            res = joinPaths(res, (prefixes == Prefixes::Always ? path.m_nodes.at(0).m_prefix.value().m_name + ":" : "") + std::visit(nodeToDataStringVisitor(), it.m_suffix));
+            res = joinPaths(res, (prefixes == Prefixes::Always && path.m_nodes.at(0).m_prefix ? path.m_nodes.at(0).m_prefix.value().m_name + ":" : "") + std::visit(nodeToDataStringVisitor(), it.m_suffix));
         }
     }
 
@@ -285,7 +285,7 @@
         if (it.m_prefix) {
             res = joinPaths(res, it.m_prefix.value().m_name + ":" + std::visit(nodeToSchemaStringVisitor(), it.m_suffix));
         } else {
-            res = joinPaths(res, (prefixes == Prefixes::Always ? path.m_nodes.at(0).m_prefix.value().m_name + ":" : "") + std::visit(nodeToSchemaStringVisitor(), it.m_suffix));
+            res = joinPaths(res, (prefixes == Prefixes::Always && path.m_nodes.at(0).m_prefix ? path.m_nodes.at(0).m_prefix.value().m_name + ":" : "") + std::visit(nodeToSchemaStringVisitor(), it.m_suffix));
         }
     }
     return res;