blob: 77174800afa3d33d93bbab5535d7145faf1bf48c [file] [log] [blame]
Václav Kubernát4108e0d2018-10-29 13:32:22 +01001/*
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áta33cf082019-03-28 11:55:57 +01009#include "trompeloeil_doctest.h"
Václav Kubernát4108e0d2018-10-29 13:32:22 +010010#include "utils.hpp"
11
12TEST_CASE("utils")
13{
Václav Kubernáta395d332019-02-13 16:49:20 +010014 SECTION("filterByPrefix")
Václav Kubernát4108e0d2018-10-29 13:32:22 +010015 {
16 std::set<std::string> set{"ahoj", "coze", "copak", "aha", "polivka"};
17
Václav Kubernáta395d332019-02-13 16:49:20 +010018 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át4108e0d2018-10-29 13:32:22 +010024 }
Václav Kubernáta44bdf22020-01-24 12:15:31 +010025
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át4108e0d2018-10-29 13:32:22 +010082}