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"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 16 | schema->addList("/", "mod:list", {"number"}); |
Václav Kubernát | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame^] | 17 | schema->addLeaf("/mod:list", "mod:number", yang::LeafDataTypes::Int32); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 18 | schema->addLeaf("/mod:list", "mod:leafInList", yang::LeafDataTypes::String); |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 19 | 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át | 7707cae | 2020-01-16 12:04:53 +0100 | [diff] [blame^] | 29 | auto keys = std::map<std::string, leaf_data_>{ |
| 30 | {"number", int32_t{3}}}; |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 31 | 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 | } |