Václav Kubernát | 1446fe1 | 2019-10-02 19:32:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/ |
| 3 | * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/ |
| 4 | * |
| 5 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #include <experimental/iterator> |
Václav Kubernát | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 10 | #include "trompeloeil_doctest.hpp" |
Václav Kubernát | 1446fe1 | 2019-10-02 19:32:51 +0200 | [diff] [blame] | 11 | #include "ast_commands.hpp" |
| 12 | #include "parser.hpp" |
| 13 | #include "static_schema.hpp" |
| 14 | |
| 15 | namespace std { |
| 16 | std::ostream& operator<<(std::ostream& s, const std::set<std::string> set) |
| 17 | { |
| 18 | s << std::endl |
| 19 | << "{"; |
| 20 | std::copy(set.begin(), set.end(), std::experimental::make_ostream_joiner(s, ", ")); |
| 21 | s << "}" << std::endl; |
| 22 | return s; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | TEST_CASE("parser methods") |
| 27 | { |
| 28 | auto schema = std::make_shared<StaticSchema>(); |
| 29 | schema->addModule("example"); |
| 30 | schema->addModule("second"); |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 31 | schema->addContainer("/", "example:a"); |
| 32 | schema->addList("/example:a", "example:listInCont", {"number"}); |
| 33 | schema->addContainer("/", "second:a"); |
| 34 | schema->addContainer("/", "example:b"); |
| 35 | schema->addContainer("/example:a", "example:a2"); |
| 36 | schema->addContainer("/example:b", "example:b2"); |
| 37 | schema->addContainer("/example:a/example:a2", "example:a3"); |
| 38 | schema->addContainer("/example:b/example:b2", "example:b3"); |
| 39 | schema->addList("/", "example:list", {"number"}); |
| 40 | schema->addContainer("/example:list", "example:contInList"); |
| 41 | schema->addList("/", "example:twoKeyList", {"number", "name"}); |
Václav Kubernát | 1446fe1 | 2019-10-02 19:32:51 +0200 | [diff] [blame] | 42 | Parser parser(schema); |
| 43 | |
| 44 | SECTION("availableNodes") |
| 45 | { |
| 46 | std::set<std::string> expected; |
Václav Kubernát | 9456b5c | 2019-10-02 21:14:52 +0200 | [diff] [blame] | 47 | boost::optional<boost::variant<boost::variant<dataPath_, schemaPath_>, module_>> arg{boost::none}; |
Václav Kubernát | 1446fe1 | 2019-10-02 19:32:51 +0200 | [diff] [blame] | 48 | SECTION("cwd: /") |
| 49 | { |
| 50 | SECTION("arg: <none>") |
| 51 | { |
| 52 | expected = {"example:a", "example:b", "example:list", "example:twoKeyList", "second:a"}; |
| 53 | } |
| 54 | |
| 55 | SECTION("arg: example:a") |
| 56 | { |
| 57 | arg = dataPath_{Scope::Relative, {{module_{"example"}, container_{"a"}}}}; |
| 58 | expected = {"example:a2", "example:listInCont"}; |
| 59 | } |
| 60 | |
| 61 | SECTION("arg: example:list") |
| 62 | { |
| 63 | arg = dataPath_{Scope::Relative, {{module_{"example"}, list_{"list"}}}}; |
| 64 | expected = {"example:contInList"}; |
| 65 | } |
| 66 | |
| 67 | SECTION("arg: /example:a") |
| 68 | { |
| 69 | arg = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}}}}; |
| 70 | expected = {"example:a2", "example:listInCont"}; |
| 71 | } |
| 72 | |
| 73 | SECTION("arg: /example:list") |
| 74 | { |
| 75 | arg = dataPath_{Scope::Absolute, {{module_{"example"}, list_{"list"}}}}; |
| 76 | expected = {"example:contInList"}; |
| 77 | } |
| 78 | } |
| 79 | SECTION("cwd: /example:a") |
| 80 | { |
| 81 | parser.changeNode({Scope::Relative, {{module_{"example"}, container_{"a"}}}}); |
| 82 | |
| 83 | SECTION("arg: <none>") |
| 84 | { |
| 85 | expected = {"example:a2", "example:listInCont"}; |
| 86 | } |
| 87 | |
| 88 | SECTION("arg: example:a2") |
| 89 | { |
| 90 | arg = dataPath_{Scope::Relative, {{container_{"a2"}}}}; |
| 91 | expected = {"example:a3"}; |
| 92 | } |
| 93 | |
| 94 | SECTION("arg: example:listInCont") |
| 95 | { |
| 96 | arg = dataPath_{Scope::Relative, {{list_{"listInCont"}}}}; |
| 97 | } |
| 98 | |
| 99 | SECTION("arg: /example:a") |
| 100 | { |
| 101 | arg = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}}}}; |
| 102 | expected = {"example:a2", "example:listInCont"}; |
| 103 | } |
| 104 | |
| 105 | SECTION("arg: /example:list") |
| 106 | { |
| 107 | arg = dataPath_{Scope::Absolute, {{module_{"example"}, list_{"list"}}}}; |
| 108 | expected = {"example:contInList"}; |
| 109 | } |
| 110 | } |
| 111 | SECTION("cwd: /example:list") |
| 112 | { |
| 113 | parser.changeNode({Scope::Relative, {{module_{"example"}, list_{"list"}}}}); |
| 114 | |
| 115 | SECTION("arg: <none>") |
| 116 | { |
| 117 | expected = {"example:contInList"}; |
| 118 | } |
| 119 | |
| 120 | SECTION("arg: example:contInList") |
| 121 | { |
| 122 | arg = dataPath_{Scope::Relative, {{container_{"contInList"}}}}; |
| 123 | } |
| 124 | |
| 125 | SECTION("arg: /example:a") |
| 126 | { |
| 127 | arg = dataPath_{Scope::Absolute, {{module_{"example"}, container_{"a"}}}}; |
| 128 | expected = {"example:a2", "example:listInCont"}; |
| 129 | } |
| 130 | |
| 131 | SECTION("arg: /example:list") |
| 132 | { |
| 133 | arg = dataPath_{Scope::Absolute, {{module_{"example"}, list_{"list"}}}}; |
| 134 | expected = {"example:contInList"}; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | REQUIRE(expected == parser.availableNodes(arg, Recursion::NonRecursive)); |
| 139 | } |
| 140 | } |