add list parsing

Change-Id: Id4be03cedd687892b6f4ae45d90afee8e2a4a43c
diff --git a/tests/cd.cpp b/tests/cd.cpp
index 39487a3..376e74c 100644
--- a/tests/cd.cpp
+++ b/tests/cd.cpp
@@ -20,56 +20,120 @@
     tree.addContainer("b", "b2");
     tree.addContainer("a/a2", "a3");
     tree.addContainer("b/b2", "b3");
-
+    tree.addList("", "list", {"number"});
+    tree.addContainer("list", "contInList");
+    tree.addList("", "twoKeyList", {"number", "name"});
     CParser parser(tree);
-    cd_ expected;
-
     std::string input;
 
-    SECTION("basic cd parsing")
+    SECTION("valid input")
     {
-        SECTION("a")
+        cd_ expected;
+
+        SECTION("container")
         {
-            input = "cd a";
-            expected.m_path.m_nodes.push_back(container_("a"));
+            SECTION("a")
+            {
+                input = "cd a";
+                expected.m_path.m_nodes.push_back(container_("a"));
+            }
+
+            SECTION("b")
+            {
+                input = "cd b";
+                expected.m_path.m_nodes.push_back(container_("b"));
+            }
+
+            SECTION("a/a2")
+            {
+                input = "cd a/a2";
+                expected.m_path.m_nodes.push_back(container_("a"));
+                expected.m_path.m_nodes.push_back(container_("a2"));
+            }
+
+            SECTION("b/b2")
+            {
+                input = "cd b/b2";
+                expected.m_path.m_nodes.push_back(container_("b"));
+                expected.m_path.m_nodes.push_back(container_("b2"));
+            }
+
         }
 
-        SECTION("b")
+        SECTION("list elements")
         {
-            input = "cd b";
-            expected.m_path.m_nodes.push_back(container_("b"));
+            SECTION("list[number=1]")
+            {
+                input = "cd list[number=1]";
+                auto keys = std::map<std::string, std::string>{
+                        {"number", "1"}
+                };
+                expected.m_path.m_nodes.push_back(listElement_("list", keys));
+            }
+
+            SECTION("list[number=1]/contInList")
+            {
+                input = "cd list[number=1]/contInList";
+                auto keys = std::map<std::string, std::string>{
+                        {"number", "1"}};
+                expected.m_path.m_nodes.push_back(listElement_("list", keys));
+                expected.m_path.m_nodes.push_back(container_("contInList"));
+            }
+
+            SECTION("twoKeyList[number=4 name=abcd]")
+            {
+                input = "cd twoKeyList[number=4 name=abcd]";
+                auto keys = std::map<std::string, std::string>{
+                        {"number", "4"},
+                        {"name", "abcd"}};
+                expected.m_path.m_nodes.push_back(listElement_("twoKeyList", keys));
+            }
+
         }
-
-
-        SECTION("a/a2")
-        {
-            input = "cd a/a2";
-            expected.m_path.m_nodes.push_back(container_("a"));
-            expected.m_path.m_nodes.push_back(container_("a2"));
-        }
-
-        SECTION("b/b2")
-        {
-            input = "cd b/b2";
-            expected.m_path.m_nodes.push_back(container_("b"));
-            expected.m_path.m_nodes.push_back(container_("b2"));
-        }
-
         cd_ command = parser.parseCommand(input);
         REQUIRE(command == expected);
     }
-
-    SECTION("InvalidNodeException")
+    SECTION("invalid input")
     {
-        SECTION("x")
+        SECTION("invalid identifiers")
         {
-            input = "cd x";
-        }
+            SECTION("nonexistent")
+            {
+                input = "cd nonexistent";
+                REQUIRE_THROWS(parser.parseCommand(input));
+            }
 
-        SECTION("a/x")
-        {
-            input = "cd a/x";
+            SECTION("nonexistent/lol")
+            {
+                input = "cd nonexistent/lol";
+                REQUIRE_THROWS(parser.parseCommand(input));
+            }
         }
-        REQUIRE_THROWS_AS(parser.parseCommand(input), InvalidNodeException);
+        SECTION("invalid list key identifiers")
+        {
+            SECTION("twoKeyList[invalidKey=4]")
+            {
+                input = "cd twoKeyList[invalidKey=4]";
+                REQUIRE_THROWS(parser.parseCommand(input));
+            }
+
+            SECTION("twoKeyList[number=4 number=5]")
+            {
+                input = "cd twoKeyList[number=4 number=5]";
+                REQUIRE_THROWS(parser.parseCommand(input));
+            }
+
+            SECTION("twoKeyList[number=4 name=lol number=7]")
+            {
+                input = "cd twoKeyList[number=4 name=lol number=7]";
+                REQUIRE_THROWS(parser.parseCommand(input));
+            }
+
+            SECTION("twoKeyList[number=4]")
+            {
+                input = "cd twoKeyList[number=4]";
+                REQUIRE_THROWS(parser.parseCommand(input));
+            }
+        }
     }
 }