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 | |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame^] | 8 | #include "trompeloeil_doctest.h" |
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 | { |
| 14 | auto schema = std::make_shared<StaticSchema>(); |
| 15 | schema->addModule("mod"); |
| 16 | schema->addList("", "mod:list", {"number"}); |
| 17 | schema->addLeaf("mod:list", "mod:leafInList", yang::LeafDataTypes::String); |
| 18 | Parser parser(schema); |
| 19 | std::string input; |
| 20 | std::ostringstream errorStream; |
| 21 | |
| 22 | SECTION("creating/deleting list instances") |
| 23 | { |
| 24 | dataPath_ expectedPath; |
| 25 | SECTION("mod:list[number=3]") |
| 26 | { |
| 27 | input = "mod:list[number=3]"; |
| 28 | auto keys = std::map<std::string, std::string>{ |
| 29 | {"number", "3"}}; |
| 30 | expectedPath.m_nodes.push_back(dataNode_{module_{"mod"}, listElement_("list", keys)}); |
| 31 | } |
| 32 | |
| 33 | command_ parsedCreate = parser.parseCommand("create " + input, errorStream); |
| 34 | command_ parsedDelete = parser.parseCommand("delete " + input, errorStream); |
| 35 | create_ expectedCreate; |
| 36 | expectedCreate.m_path = expectedPath; |
| 37 | delete_ expectedDelete; |
| 38 | expectedDelete.m_path = expectedPath; |
| 39 | REQUIRE(parsedCreate.type() == typeid(create_)); |
| 40 | REQUIRE(parsedDelete.type() == typeid(delete_)); |
| 41 | REQUIRE(boost::get<create_>(parsedCreate) == expectedCreate); |
| 42 | REQUIRE(boost::get<delete_>(parsedDelete) == expectedDelete); |
| 43 | } |
| 44 | } |