blob: 139ef4be3c82c25c5dbbe613d31f7273b869d87a [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";
31 expected.m_path.m_nodes.push_back({module_{"example"}, rpcNode_{"fire"}});
32 }
33
34 SECTION("action")
35 {
36 input = "prepare example:port[name='eth0']/shutdown";
37 expected.m_path.m_nodes.push_back({module_{"example"}, listElement_{"port", {{"name", std::string{"eth0"}}}}});
38 expected.m_path.m_nodes.push_back({actionNode_{"shutdown"}});
39 }
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}