Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [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 | |
Václav Kubernát | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 9 | #include "trompeloeil_doctest.hpp" |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 10 | #include "completion.hpp" |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame^] | 11 | #include "leaf_data_helpers.hpp" |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 12 | #include "utils.hpp" |
| 13 | |
| 14 | TEST_CASE("utils") |
| 15 | { |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 16 | SECTION("filterByPrefix") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 17 | { |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 18 | std::set<Completion> set{{"ahoj"}, {"coze"}, {"copak"}, {"aha"}, {"polivka"}}; |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 19 | |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 20 | REQUIRE((filterByPrefix(set, "a") == std::set<Completion>{{"ahoj"}, {"aha"}})); |
| 21 | REQUIRE((filterByPrefix(set, "ah") == std::set<Completion>{{"ahoj"}, {"aha"}})); |
| 22 | REQUIRE((filterByPrefix(set, "aho") == std::set<Completion>{{"ahoj"}})); |
| 23 | REQUIRE((filterByPrefix(set, "polivka") == std::set<Completion>{{"polivka"}})); |
| 24 | REQUIRE((filterByPrefix(set, "polivkax") == std::set<Completion>{})); |
| 25 | REQUIRE((filterByPrefix(set, "co") == std::set<Completion>{{"copak"}, {"coze"}})); |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 26 | } |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 27 | |
| 28 | SECTION("joinPaths") { |
| 29 | std::string prefix, suffix, result; |
| 30 | |
| 31 | SECTION("regular") { |
| 32 | prefix = "/example:a"; |
| 33 | suffix = "leaf"; |
| 34 | result = "/example:a/leaf"; |
| 35 | } |
| 36 | |
| 37 | SECTION("no prefix - absolute path") { |
| 38 | suffix = "/example:a/leaf"; |
| 39 | result = "/example:a/leaf"; |
| 40 | } |
| 41 | |
| 42 | SECTION("no prefix - relative path") { |
| 43 | suffix = "example:a/leaf"; |
| 44 | result = "example:a/leaf"; |
| 45 | } |
| 46 | |
| 47 | SECTION("no suffix") { |
| 48 | prefix = "/example:a/leaf"; |
| 49 | result = "/example:a/leaf"; |
| 50 | } |
| 51 | |
| 52 | SECTION("at root") { |
| 53 | prefix = "/"; |
| 54 | suffix = "example:a"; |
| 55 | result = "/example:a"; |
| 56 | } |
| 57 | |
| 58 | SECTION("trailing slash") { |
| 59 | prefix = "/example:a"; |
| 60 | suffix = "/"; |
| 61 | result = "/example:a/"; |
| 62 | } |
| 63 | |
| 64 | SECTION("prefix ends with slash") { |
| 65 | prefix = "/example:a/"; |
| 66 | suffix = "leaf"; |
| 67 | result = "/example:a/leaf"; |
| 68 | } |
| 69 | |
| 70 | SECTION("suffix starts with slash") { |
| 71 | prefix = "/example:a"; |
| 72 | suffix = "/leaf"; |
| 73 | result = "/example:a/leaf"; |
| 74 | } |
| 75 | |
| 76 | SECTION("slashes all the way to eleven") { |
| 77 | prefix = "/example:a/"; |
| 78 | suffix = "/leaf"; |
| 79 | result = "/example:a/leaf"; |
| 80 | } |
| 81 | |
| 82 | REQUIRE(joinPaths(prefix, suffix) == result); |
| 83 | } |
Václav Kubernát | 2984f44 | 2020-02-20 17:43:35 +0100 | [diff] [blame^] | 84 | |
| 85 | SECTION("leafDataTypeToString") |
| 86 | { |
| 87 | yang::LeafDataType type; |
| 88 | std::string expected; |
| 89 | SECTION("union") |
| 90 | { |
| 91 | type = yang::Union{{ |
| 92 | yang::String{}, |
| 93 | createEnum({"foo", "bar"}), |
| 94 | yang::Int8{}, |
| 95 | yang::Int64{}, |
| 96 | }}; |
| 97 | expected = "a string, an enum, an 8-bit integer, a 64-bit integer"; |
| 98 | } |
| 99 | |
| 100 | REQUIRE(leafDataTypeToString(type) == expected); |
| 101 | |
| 102 | } |
| 103 | |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 104 | } |