blob: 72c9daf38b40444ba79bec41de9ed3be076df6a5 [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"
13#include "schema.hpp"
14
15TEST_CASE("presence containers")
16{
17 Schema schema;
18 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);
25 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";
36 expectedPath.m_nodes = { container_("a") };
37 }
38
39 SECTION("b/b2")
40 {
41 input = "b/b2";
42 expectedPath.m_nodes = { container_("b"), container_("b2") };
43 }
44
45 SECTION("a/a2/a3")
46 {
47 input = "a/a2/a3";
48 expectedPath.m_nodes = { container_("a"), container_("a2"), container_("a3") };
49 }
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"}};
56 expectedPath.m_nodes = { listElement_("list", keys), container_("contInList") };
57 }
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}