blob: 9683daf80373d766101b10476459717fe604e4df [file] [log] [blame]
Václav Kubernátb61336d2018-05-28 17:35:03 +02001
2/*
3 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
4 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
5 *
6 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
7 *
8*/
9
10#include "trompeloeil_catch.h"
Václav Kubernát24df80e2018-06-06 15:18:03 +020011#include "ast_commands.hpp"
Václav Kubernátb61336d2018-05-28 17:35:03 +020012#include "parser.hpp"
Václav Kubernátbddbb172018-06-13 16:27:39 +020013#include "static_schema.hpp"
Václav Kubernátb61336d2018-05-28 17:35:03 +020014
15TEST_CASE("presence containers")
16{
Václav Kubernátbddbb172018-06-13 16:27:39 +020017 auto schema = std::make_shared<StaticSchema>();
Václav Kubernát744f57f2018-06-29 22:46:26 +020018 schema->addModule("mod");
19 schema->addContainer("", "mod:a", yang::ContainerTraits::Presence);
20 schema->addContainer("", "mod:b");
21 schema->addContainer("mod:a", "mod:a2");
22 schema->addContainer("mod:a/mod:a2", "mod:a3", yang::ContainerTraits::Presence);
23 schema->addContainer("mod:b", "mod:b2", yang::ContainerTraits::Presence);
24 schema->addList("", "mod:list", {"quote"});
25 schema->addContainer("mod:list", "mod:contInList", yang::ContainerTraits::Presence);
Václav Kubernátb61336d2018-05-28 17:35:03 +020026 Parser parser(schema);
27 std::string input;
28 std::ostringstream errorStream;
29
30 SECTION("valid input")
31 {
32 path_ expectedPath;
33
Václav Kubernát744f57f2018-06-29 22:46:26 +020034 SECTION("mod:a")
Václav Kubernátb61336d2018-05-28 17:35:03 +020035 {
Václav Kubernát744f57f2018-06-29 22:46:26 +020036 input = "mod:a";
37 expectedPath.m_nodes = {{module_{"mod"}, {container_("a")}}};
Václav Kubernátb61336d2018-05-28 17:35:03 +020038 }
39
Václav Kubernát744f57f2018-06-29 22:46:26 +020040 SECTION("mod:b/b2")
Václav Kubernátb61336d2018-05-28 17:35:03 +020041 {
Václav Kubernát744f57f2018-06-29 22:46:26 +020042 input = "mod:b/b2";
43 expectedPath.m_nodes = {{{module_{"mod"}}, container_("b")}, {container_("b2")}};
Václav Kubernátb61336d2018-05-28 17:35:03 +020044 }
45
Václav Kubernát744f57f2018-06-29 22:46:26 +020046 SECTION("mod:a/a2/a3")
Václav Kubernátb61336d2018-05-28 17:35:03 +020047 {
Václav Kubernát744f57f2018-06-29 22:46:26 +020048 input = "mod:a/a2/a3";
49 expectedPath.m_nodes = {{{module_{"mod"}}, container_("a")}, {container_("a2")}, {container_("a3")}};
Václav Kubernátb61336d2018-05-28 17:35:03 +020050 }
51
Václav Kubernát744f57f2018-06-29 22:46:26 +020052 SECTION("mod:list[quote=lol]/contInList")
Václav Kubernátb61336d2018-05-28 17:35:03 +020053 {
Václav Kubernát744f57f2018-06-29 22:46:26 +020054 input = "mod:list[quote=lol]/contInList";
Václav Kubernátb61336d2018-05-28 17:35:03 +020055 auto keys = std::map<std::string, std::string>{
56 {"quote", "lol"}};
Václav Kubernát744f57f2018-06-29 22:46:26 +020057 expectedPath.m_nodes = {{{module_{"mod"}}, listElement_("list", keys)}, {container_("contInList")}};
Václav Kubernátb61336d2018-05-28 17:35:03 +020058 }
59
60 create_ expectedCreate;
61 expectedCreate.m_path = expectedPath;
62 command_ commandCreate = parser.parseCommand("create " + input, errorStream);
63 REQUIRE(commandCreate.type() == typeid(create_));
64 create_ create = boost::get<create_>(commandCreate);
65 REQUIRE(create == expectedCreate);
66
67 delete_ expectedDelete;
68 expectedDelete.m_path = expectedPath;
69 command_ commandDelete = parser.parseCommand("delete " + input, errorStream);
70 REQUIRE(commandDelete.type() == typeid(delete_));
71 delete_ delet = boost::get<delete_>(commandDelete);
72 REQUIRE(delet == expectedDelete);
73 }
74 SECTION("invalid input")
75 {
76 SECTION("c")
77 {
78 input = "c";
79 }
80
81 SECTION("a/a2")
82 {
83 input = "a/a2";
84 }
85
86 SECTION("list[quote=lol]")
87 {
88 input = "list[quote=lol]";
89 }
90
91 REQUIRE_THROWS(parser.parseCommand("create " + input, errorStream));
92 REQUIRE_THROWS(parser.parseCommand("delete " + input, errorStream));
93 }
94}