blob: b71ee7b01760c6b8086987200d3c12357a772ccb [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{
14 auto schema = std::make_shared<StaticSchema>();
15 schema->addModule("mod");
Václav Kubernátefcac932020-01-10 15:26:32 +010016 schema->addList("/", "mod:list", {"number"});
Václav Kubernát7707cae2020-01-16 12:04:53 +010017 schema->addLeaf("/mod:list", "mod:number", yang::LeafDataTypes::Int32);
Václav Kubernátefcac932020-01-10 15:26:32 +010018 schema->addLeaf("/mod:list", "mod:leafInList", yang::LeafDataTypes::String);
Václav Kubernátf5f64f02019-03-19 17:15:47 +010019 Parser parser(schema);
20 std::string input;
21 std::ostringstream errorStream;
22
23 SECTION("creating/deleting list instances")
24 {
25 dataPath_ expectedPath;
26 SECTION("mod:list[number=3]")
27 {
28 input = "mod:list[number=3]";
Václav Kubernát7707cae2020-01-16 12:04:53 +010029 auto keys = std::map<std::string, leaf_data_>{
30 {"number", int32_t{3}}};
Václav Kubernátf5f64f02019-03-19 17:15:47 +010031 expectedPath.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)});
32 }
33
34 command_ parsedCreate = parser.parseCommand("create " + input, errorStream);
35 command_ parsedDelete = parser.parseCommand("delete " + input, errorStream);
36 create_ expectedCreate;
37 expectedCreate.m_path = expectedPath;
38 delete_ expectedDelete;
39 expectedDelete.m_path = expectedPath;
40 REQUIRE(parsedCreate.type() == typeid(create_));
41 REQUIRE(parsedDelete.type() == typeid(delete_));
42 REQUIRE(boost::get<create_>(parsedCreate) == expectedCreate);
43 REQUIRE(boost::get<delete_>(parsedDelete) == expectedDelete);
44 }
45}