blob: d56a488eb62b2e2b566d42d17b40259aa4afd477 [file] [log] [blame]
Václav Kubernát3d787b12020-10-29 09:11:26 +01001
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_doctest.hpp"
11#include "parser.hpp"
12#include "pretty_printers.hpp"
13#include "static_schema.hpp"
14
15TEST_CASE("prepare command")
16{
17 auto schema = std::make_shared<StaticSchema>();
18 schema->addModule("example");
19 schema->addRpc("/", "example:fire");
20 schema->addList("/", "example:port", {"name"});
21 schema->addLeaf("/example:port", "example:name", yang::String{});
22 schema->addAction("/example:port", "example:shutdown");
23 Parser parser(schema);
24 std::string input;
25 std::ostringstream errorStream;
26 prepare_ expected;
27 expected.m_path.m_scope = Scope::Relative;
28 SECTION("rpc")
29 {
30 input = "prepare example:fire";
Václav Kubernátf82e2242020-12-01 04:30:51 +010031 expected.m_path.m_nodes.emplace_back(module_{"example"}, rpcNode_{"fire"});
Václav Kubernát3d787b12020-10-29 09:11:26 +010032 }
33
34 SECTION("action")
35 {
36 input = "prepare example:port[name='eth0']/shutdown";
Václav Kubernátf82e2242020-12-01 04:30:51 +010037 expected.m_path.m_nodes.emplace_back(module_{"example"}, listElement_{"port", {{"name", std::string{"eth0"}}}});
38 expected.m_path.m_nodes.emplace_back(actionNode_{"shutdown"});
Václav Kubernát3d787b12020-10-29 09:11:26 +010039 }
40
41 command_ command = parser.parseCommand(input, errorStream);
42 REQUIRE(command.type() == typeid(prepare_));
43 auto lol = boost::get<prepare_>(command);
44 REQUIRE(boost::get<prepare_>(command) == expected);
45}