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