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 | |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 9 | #include "trompeloeil_doctest.h" |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 10 | #include "utils.hpp" |
| 11 | |
| 12 | TEST_CASE("utils") |
| 13 | { |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 14 | SECTION("filterByPrefix") |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 15 | { |
| 16 | std::set<std::string> set{"ahoj", "coze", "copak", "aha", "polivka"}; |
| 17 | |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 18 | REQUIRE((filterByPrefix(set, "a") == std::set<std::string>{"ahoj", "aha"})); |
| 19 | REQUIRE((filterByPrefix(set, "ah") == std::set<std::string>{"ahoj", "aha"})); |
| 20 | REQUIRE((filterByPrefix(set, "aho") == std::set<std::string>{"ahoj"})); |
| 21 | REQUIRE((filterByPrefix(set, "polivka") == std::set<std::string>{"polivka"})); |
| 22 | REQUIRE((filterByPrefix(set, "polivkax") == std::set<std::string>{})); |
| 23 | REQUIRE((filterByPrefix(set, "co") == std::set<std::string>{"copak", "coze"})); |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 24 | } |
Václav Kubernát | a44bdf2 | 2020-01-24 12:15:31 +0100 | [diff] [blame] | 25 | |
| 26 | SECTION("joinPaths") { |
| 27 | std::string prefix, suffix, result; |
| 28 | |
| 29 | SECTION("regular") { |
| 30 | prefix = "/example:a"; |
| 31 | suffix = "leaf"; |
| 32 | result = "/example:a/leaf"; |
| 33 | } |
| 34 | |
| 35 | SECTION("no prefix - absolute path") { |
| 36 | suffix = "/example:a/leaf"; |
| 37 | result = "/example:a/leaf"; |
| 38 | } |
| 39 | |
| 40 | SECTION("no prefix - relative path") { |
| 41 | suffix = "example:a/leaf"; |
| 42 | result = "example:a/leaf"; |
| 43 | } |
| 44 | |
| 45 | SECTION("no suffix") { |
| 46 | prefix = "/example:a/leaf"; |
| 47 | result = "/example:a/leaf"; |
| 48 | } |
| 49 | |
| 50 | SECTION("at root") { |
| 51 | prefix = "/"; |
| 52 | suffix = "example:a"; |
| 53 | result = "/example:a"; |
| 54 | } |
| 55 | |
| 56 | SECTION("trailing slash") { |
| 57 | prefix = "/example:a"; |
| 58 | suffix = "/"; |
| 59 | result = "/example:a/"; |
| 60 | } |
| 61 | |
| 62 | SECTION("prefix ends with slash") { |
| 63 | prefix = "/example:a/"; |
| 64 | suffix = "leaf"; |
| 65 | result = "/example:a/leaf"; |
| 66 | } |
| 67 | |
| 68 | SECTION("suffix starts with slash") { |
| 69 | prefix = "/example:a"; |
| 70 | suffix = "/leaf"; |
| 71 | result = "/example:a/leaf"; |
| 72 | } |
| 73 | |
| 74 | SECTION("slashes all the way to eleven") { |
| 75 | prefix = "/example:a/"; |
| 76 | suffix = "/leaf"; |
| 77 | result = "/example:a/leaf"; |
| 78 | } |
| 79 | |
| 80 | REQUIRE(joinPaths(prefix, suffix) == result); |
| 81 | } |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 82 | } |