Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 1 | |
| 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_catch.h" |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 11 | #include "ast_commands.hpp" |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 12 | #include "parser.hpp" |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 13 | #include "static_schema.hpp" |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 14 | |
| 15 | TEST_CASE("presence containers") |
| 16 | { |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 17 | auto schema = std::make_shared<StaticSchema>(); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 18 | schema->addModule("mod"); |
| 19 | schema->addContainer("", "mod:a", yang::ContainerTraits::Presence); |
| 20 | schema->addContainer("", "mod:b"); |
| 21 | schema->addContainer("mod:a", "mod:a2"); |
| 22 | schema->addContainer("mod:a/mod:a2", "mod:a3", yang::ContainerTraits::Presence); |
| 23 | schema->addContainer("mod:b", "mod:b2", yang::ContainerTraits::Presence); |
| 24 | schema->addList("", "mod:list", {"quote"}); |
| 25 | schema->addContainer("mod:list", "mod:contInList", yang::ContainerTraits::Presence); |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 26 | Parser parser(schema); |
| 27 | std::string input; |
| 28 | std::ostringstream errorStream; |
| 29 | |
| 30 | SECTION("valid input") |
| 31 | { |
| 32 | path_ expectedPath; |
| 33 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 34 | SECTION("mod:a") |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 35 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 36 | input = "mod:a"; |
| 37 | expectedPath.m_nodes = {{module_{"mod"}, {container_("a")}}}; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 40 | SECTION("mod:b/b2") |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 41 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 42 | input = "mod:b/b2"; |
| 43 | expectedPath.m_nodes = {{{module_{"mod"}}, container_("b")}, {container_("b2")}}; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 44 | } |
| 45 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 46 | SECTION("mod:a/a2/a3") |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 47 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 48 | input = "mod:a/a2/a3"; |
| 49 | expectedPath.m_nodes = {{{module_{"mod"}}, container_("a")}, {container_("a2")}, {container_("a3")}}; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 50 | } |
| 51 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 52 | SECTION("mod:list[quote=lol]/contInList") |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 53 | { |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 54 | input = "mod:list[quote=lol]/contInList"; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 55 | auto keys = std::map<std::string, std::string>{ |
| 56 | {"quote", "lol"}}; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 57 | expectedPath.m_nodes = {{{module_{"mod"}}, listElement_("list", keys)}, {container_("contInList")}}; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | create_ expectedCreate; |
| 61 | expectedCreate.m_path = expectedPath; |
| 62 | command_ commandCreate = parser.parseCommand("create " + input, errorStream); |
| 63 | REQUIRE(commandCreate.type() == typeid(create_)); |
| 64 | create_ create = boost::get<create_>(commandCreate); |
| 65 | REQUIRE(create == expectedCreate); |
| 66 | |
| 67 | delete_ expectedDelete; |
| 68 | expectedDelete.m_path = expectedPath; |
| 69 | command_ commandDelete = parser.parseCommand("delete " + input, errorStream); |
| 70 | REQUIRE(commandDelete.type() == typeid(delete_)); |
| 71 | delete_ delet = boost::get<delete_>(commandDelete); |
| 72 | REQUIRE(delet == expectedDelete); |
| 73 | } |
| 74 | SECTION("invalid input") |
| 75 | { |
| 76 | SECTION("c") |
| 77 | { |
| 78 | input = "c"; |
| 79 | } |
| 80 | |
| 81 | SECTION("a/a2") |
| 82 | { |
| 83 | input = "a/a2"; |
| 84 | } |
| 85 | |
| 86 | SECTION("list[quote=lol]") |
| 87 | { |
| 88 | input = "list[quote=lol]"; |
| 89 | } |
| 90 | |
| 91 | REQUIRE_THROWS(parser.parseCommand("create " + input, errorStream)); |
| 92 | REQUIRE_THROWS(parser.parseCommand("delete " + input, errorStream)); |
| 93 | } |
| 94 | } |