Václav Kubernát | 5395e71 | 2019-12-03 18:24:33 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Václav Kubernát <kubervac@fit.cvut.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
Václav Kubernát | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 8 | #include "trompeloeil_doctest.hpp" |
Václav Kubernát | 5395e71 | 2019-12-03 18:24:33 +0100 | [diff] [blame] | 9 | #include "ast_path.hpp" |
| 10 | |
| 11 | TEST_CASE("path utils") |
| 12 | { |
| 13 | SECTION("pathToDataString") |
| 14 | { |
| 15 | dataPath_ path; |
| 16 | std::string expected; |
| 17 | SECTION("example-schema:twoKeyList[first='a'][second='b']") |
| 18 | { |
| 19 | SECTION("absolute") |
| 20 | { |
| 21 | path.m_scope = Scope::Absolute; |
| 22 | expected += "/"; |
| 23 | } |
| 24 | SECTION("relative") |
| 25 | { |
| 26 | path.m_scope = Scope::Relative; |
| 27 | } |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 28 | path.m_nodes.emplace_back(module_{"example-schema"}, listElement_{"twoKeyList", {{"first", std::string{"a"}}, {"second", std::string{"b"}}}}); |
Václav Kubernát | 5395e71 | 2019-12-03 18:24:33 +0100 | [diff] [blame] | 29 | expected += "example-schema:twoKeyList[first='a'][second='b']"; |
| 30 | } |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 31 | |
| 32 | SECTION("example-schema:addresses[.='0.0.0.0']") |
| 33 | { |
| 34 | SECTION("absolute") |
| 35 | { |
| 36 | path.m_scope = Scope::Absolute; |
| 37 | expected += "/"; |
| 38 | } |
| 39 | SECTION("relative") |
| 40 | { |
| 41 | path.m_scope = Scope::Relative; |
| 42 | } |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 43 | path.m_nodes.emplace_back(module_{"example-schema"}, leafListElement_{"addresses", std::string{"0.0.0.0"}}); |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 44 | expected += "example-schema:addresses[.='0.0.0.0']"; |
| 45 | } |
Václav Kubernát | efcac93 | 2020-01-10 15:26:32 +0100 | [diff] [blame] | 46 | REQUIRE(pathToDataString(path, Prefixes::WhenNeeded) == expected); |
Václav Kubernát | 5395e71 | 2019-12-03 18:24:33 +0100 | [diff] [blame] | 47 | } |
| 48 | } |