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