blob: 974d80651258939c97f90d159291aed5354151f3 [file] [log] [blame]
Václav Kubernátf5f64f02019-03-19 17:15:47 +01001/*
2 * Copyright (C) 2019 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Václav Kubernát <kubernat@cesnet.cz>
5 *
6*/
7
Václav Kubernát26b56082020-02-03 18:28:56 +01008#include "trompeloeil_doctest.hpp"
Václav Kubernátf5f64f02019-03-19 17:15:47 +01009#include "parser.hpp"
10#include "static_schema.hpp"
11
12TEST_CASE("list manipulation")
13{
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020014 using namespace std::string_literals;
Václav Kubernátf5f64f02019-03-19 17:15:47 +010015 auto schema = std::make_shared<StaticSchema>();
16 schema->addModule("mod");
Václav Kubernátefcac932020-01-10 15:26:32 +010017 schema->addList("/", "mod:list", {"number"});
Václav Kubernát3a99f002020-03-31 02:27:41 +020018 schema->addLeaf("/mod:list", "mod:number", yang::Int32{});
19 schema->addLeaf("/mod:list", "mod:leafInList", yang::String{});
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020020 schema->addLeafList("/", "mod:addresses", yang::String{});
Václav Kubernátf5f64f02019-03-19 17:15:47 +010021 Parser parser(schema);
22 std::string input;
23 std::ostringstream errorStream;
24
25 SECTION("creating/deleting list instances")
26 {
27 dataPath_ expectedPath;
28 SECTION("mod:list[number=3]")
29 {
30 input = "mod:list[number=3]";
Václav Kubernát7707cae2020-01-16 12:04:53 +010031 auto keys = std::map<std::string, leaf_data_>{
32 {"number", int32_t{3}}};
Václav Kubernátf5f64f02019-03-19 17:15:47 +010033 expectedPath.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)});
34 }
35
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020036 SECTION("create mod:addresses['0.0.0.0']")
37 {
38 input = "mod:addresses['0.0.0.0']";
39 expectedPath.m_nodes.push_back(dataNode_{module_{"mod"}, leafListElement_{"addresses", "0.0.0.0"s}});
40 }
41
42
Václav Kubernátf5f64f02019-03-19 17:15:47 +010043 command_ parsedCreate = parser.parseCommand("create " + input, errorStream);
44 command_ parsedDelete = parser.parseCommand("delete " + input, errorStream);
45 create_ expectedCreate;
46 expectedCreate.m_path = expectedPath;
47 delete_ expectedDelete;
48 expectedDelete.m_path = expectedPath;
49 REQUIRE(parsedCreate.type() == typeid(create_));
50 REQUIRE(parsedDelete.type() == typeid(delete_));
51 REQUIRE(boost::get<create_>(parsedCreate) == expectedCreate);
52 REQUIRE(boost::get<delete_>(parsedDelete) == expectedDelete);
53 }
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020054
55 SECTION("retrieving all leaflist instances")
56 {
57 dataPath_ expected;
58 input = "get mod:addresses";
59 expected.m_nodes.push_back(dataNode_{module_{"mod"}, leafList_{"addresses"}});
60
61 get_ expectedGet;
62 expectedGet.m_path = expected;
63 command_ commandGet = parser.parseCommand(input, errorStream);
64 REQUIRE(commandGet.type() == typeid(get_));
65 REQUIRE(boost::get<get_>(commandGet) == expectedGet);
66 }
Václav Kubernátf5f64f02019-03-19 17:15:47 +010067}