blob: 87957cb27819204cf2881cfc376b7e5d6072928f [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áta10d8b62018-06-13 17:42:46 +020018 schema->addContainer("", "a", yang::ContainerTraits::Presence);
19 schema->addContainer("", "b");
20 schema->addContainer("a", "a2");
21 schema->addContainer("a/a2", "a3", yang::ContainerTraits::Presence);
22 schema->addContainer("b", "b2", yang::ContainerTraits::Presence);
23 schema->addList("", "list", {"quote"});
24 schema->addContainer("list", "contInList", yang::ContainerTraits::Presence);
Václav Kubernátb61336d2018-05-28 17:35:03 +020025 Parser parser(schema);
26 std::string input;
27 std::ostringstream errorStream;
28
29 SECTION("valid input")
30 {
31 path_ expectedPath;
32
33 SECTION("a")
34 {
35 input = "a";
Václav Kubernátebca2552018-06-08 19:06:02 +020036 expectedPath.m_nodes = {container_("a")};
Václav Kubernátb61336d2018-05-28 17:35:03 +020037 }
38
39 SECTION("b/b2")
40 {
41 input = "b/b2";
Václav Kubernátebca2552018-06-08 19:06:02 +020042 expectedPath.m_nodes = {container_("b"), container_("b2")};
Václav Kubernátb61336d2018-05-28 17:35:03 +020043 }
44
45 SECTION("a/a2/a3")
46 {
47 input = "a/a2/a3";
Václav Kubernátebca2552018-06-08 19:06:02 +020048 expectedPath.m_nodes = {container_("a"), container_("a2"), container_("a3")};
Václav Kubernátb61336d2018-05-28 17:35:03 +020049 }
50
51 SECTION("list[quote=lol]/contInList")
52 {
53 input = "list[quote=lol]/contInList";
54 auto keys = std::map<std::string, std::string>{
55 {"quote", "lol"}};
Václav Kubernátebca2552018-06-08 19:06:02 +020056 expectedPath.m_nodes = {listElement_("list", keys), container_("contInList")};
Václav Kubernátb61336d2018-05-28 17:35:03 +020057 }
58
59 create_ expectedCreate;
60 expectedCreate.m_path = expectedPath;
61 command_ commandCreate = parser.parseCommand("create " + input, errorStream);
62 REQUIRE(commandCreate.type() == typeid(create_));
63 create_ create = boost::get<create_>(commandCreate);
64 REQUIRE(create == expectedCreate);
65
66 delete_ expectedDelete;
67 expectedDelete.m_path = expectedPath;
68 command_ commandDelete = parser.parseCommand("delete " + input, errorStream);
69 REQUIRE(commandDelete.type() == typeid(delete_));
70 delete_ delet = boost::get<delete_>(commandDelete);
71 REQUIRE(delet == expectedDelete);
72 }
73 SECTION("invalid input")
74 {
75 SECTION("c")
76 {
77 input = "c";
78 }
79
80 SECTION("a/a2")
81 {
82 input = "a/a2";
83 }
84
85 SECTION("list[quote=lol]")
86 {
87 input = "list[quote=lol]";
88 }
89
90 REQUIRE_THROWS(parser.parseCommand("create " + input, errorStream));
91 REQUIRE_THROWS(parser.parseCommand("delete " + input, errorStream));
92 }
93}