add presence containers

Change-Id: Ic8e33d68e496deae9dfe4c3e5ebcecbd45ee31b2
diff --git a/tests/presence_containers.cpp b/tests/presence_containers.cpp
new file mode 100644
index 0000000..a4050f8
--- /dev/null
+++ b/tests/presence_containers.cpp
@@ -0,0 +1,93 @@
+
+/*
+ * 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 "trompeloeil_catch.h"
+#include "ast.hpp"
+#include "parser.hpp"
+#include "schema.hpp"
+
+TEST_CASE("presence containers")
+{
+    Schema schema;
+    schema.addContainer("", "a", yang::ContainerTraits::Presence);
+    schema.addContainer("", "b");
+    schema.addContainer("a", "a2");
+    schema.addContainer("a/a2", "a3", yang::ContainerTraits::Presence);
+    schema.addContainer("b", "b2", yang::ContainerTraits::Presence);
+    schema.addList("", "list", {"quote"});
+    schema.addContainer("list", "contInList", yang::ContainerTraits::Presence);
+    Parser parser(schema);
+    std::string input;
+    std::ostringstream errorStream;
+
+    SECTION("valid input")
+    {
+        path_ expectedPath;
+
+        SECTION("a")
+        {
+            input = "a";
+            expectedPath.m_nodes = { container_("a") };
+        }
+
+        SECTION("b/b2")
+        {
+            input = "b/b2";
+            expectedPath.m_nodes = { container_("b"), container_("b2") };
+        }
+
+        SECTION("a/a2/a3")
+        {
+            input = "a/a2/a3";
+            expectedPath.m_nodes = { container_("a"), container_("a2"), container_("a3") };
+        }
+
+        SECTION("list[quote=lol]/contInList")
+        {
+            input = "list[quote=lol]/contInList";
+            auto keys = std::map<std::string, std::string>{
+                {"quote", "lol"}};
+            expectedPath.m_nodes = { listElement_("list", keys), container_("contInList") };
+        }
+
+        create_ expectedCreate;
+        expectedCreate.m_path = expectedPath;
+        command_ commandCreate = parser.parseCommand("create " + input, errorStream);
+        REQUIRE(commandCreate.type() == typeid(create_));
+        create_ create = boost::get<create_>(commandCreate);
+        REQUIRE(create == expectedCreate);
+
+        delete_ expectedDelete;
+        expectedDelete.m_path = expectedPath;
+        command_ commandDelete = parser.parseCommand("delete " + input, errorStream);
+        REQUIRE(commandDelete.type() == typeid(delete_));
+        delete_ delet = boost::get<delete_>(commandDelete);
+        REQUIRE(delet == expectedDelete);
+    }
+    SECTION("invalid input")
+    {
+        SECTION("c")
+        {
+            input = "c";
+        }
+
+        SECTION("a/a2")
+        {
+            input = "a/a2";
+        }
+
+        SECTION("list[quote=lol]")
+        {
+            input = "list[quote=lol]";
+        }
+
+        REQUIRE_THROWS(parser.parseCommand("create " + input, errorStream));
+        REQUIRE_THROWS(parser.parseCommand("delete " + input, errorStream));
+    }
+}