Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 1 | /* |
| 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át | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 8 | #include "trompeloeil_doctest.hpp" |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 9 | #include "parser.hpp" |
| 10 | #include "static_schema.hpp" |
| 11 | |
| 12 | TEST_CASE("list manipulation") |
| 13 | { |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 14 | using namespace std::string_literals; |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 15 | auto schema = std::make_shared<StaticSchema>(); |
| 16 | schema->addModule("mod"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 17 | schema->addList("/", "mod:list", {"number"}); |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 18 | schema->addLeaf("/mod:list", "mod:number", yang::Int32{}); |
| 19 | schema->addLeaf("/mod:list", "mod:leafInList", yang::String{}); |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 20 | schema->addLeafList("/", "mod:addresses", yang::String{}); |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 21 | 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át | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame] | 31 | auto keys = std::map<std::string, leaf_data_>{ |
| 32 | {"number", int32_t{3}}}; |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 33 | expectedPath.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)}); |
| 34 | } |
| 35 | |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 36 | 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át | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 43 | 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át | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 54 | |
| 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át | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 67 | } |