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 | { |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 32 | dataPath_ expectedPath; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 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 | 89728d8 | 2018-09-13 16:28:28 +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 | 89728d8 | 2018-09-13 16:28:28 +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 | |
Jan Kundrát | 3081afa | 2018-09-14 16:53:43 +0200 | [diff] [blame] | 60 | SECTION("mod:list[quote='double\"quote']/contInList") |
| 61 | { |
| 62 | input = "mod:list[quote='double\"quote']/contInList"; |
| 63 | auto keys = std::map<std::string, std::string>{ |
| 64 | {"quote", "double\"quote"}}; |
| 65 | expectedPath.m_nodes = {{{module_{"mod"}}, listElement_("list", keys)}, {container_("contInList")}}; |
| 66 | } |
| 67 | |
| 68 | SECTION("mod:list[quote=\"single'quote\"]/contInList") |
| 69 | { |
| 70 | input = "mod:list[quote=\"single'quote\"]/contInList"; |
| 71 | auto keys = std::map<std::string, std::string>{ |
| 72 | {"quote", "single'quote"}}; |
| 73 | expectedPath.m_nodes = {{{module_{"mod"}}, listElement_("list", keys)}, {container_("contInList")}}; |
| 74 | } |
| 75 | |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 76 | create_ expectedCreate; |
| 77 | expectedCreate.m_path = expectedPath; |
| 78 | command_ commandCreate = parser.parseCommand("create " + input, errorStream); |
| 79 | REQUIRE(commandCreate.type() == typeid(create_)); |
| 80 | create_ create = boost::get<create_>(commandCreate); |
| 81 | REQUIRE(create == expectedCreate); |
| 82 | |
Jan Kundrát | 2a8f433 | 2018-09-14 17:05:31 +0200 | [diff] [blame] | 83 | REQUIRE(pathToDataString(create.m_path) == input); |
| 84 | |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 85 | delete_ expectedDelete; |
| 86 | expectedDelete.m_path = expectedPath; |
| 87 | command_ commandDelete = parser.parseCommand("delete " + input, errorStream); |
| 88 | REQUIRE(commandDelete.type() == typeid(delete_)); |
| 89 | delete_ delet = boost::get<delete_>(commandDelete); |
| 90 | REQUIRE(delet == expectedDelete); |
| 91 | } |
| 92 | SECTION("invalid input") |
| 93 | { |
| 94 | SECTION("c") |
| 95 | { |
| 96 | input = "c"; |
| 97 | } |
| 98 | |
| 99 | SECTION("a/a2") |
| 100 | { |
| 101 | input = "a/a2"; |
| 102 | } |
| 103 | |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 104 | SECTION("list[quote='lol']") |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 105 | { |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 106 | input = "list[quote='lol']"; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 107 | } |
| 108 | |
Václav Kubernát | b7a279d | 2018-10-04 15:27:50 +0200 | [diff] [blame] | 109 | REQUIRE_THROWS_AS(parser.parseCommand("create " + input, errorStream), InvalidCommandException&); |
| 110 | REQUIRE_THROWS_AS(parser.parseCommand("delete " + input, errorStream), InvalidCommandException&); |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 111 | } |
| 112 | } |