blob: 91c61cb2db67a7d10647cbe6dc8ca7c91ec88d75 [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
Václav Kubernát26b56082020-02-03 18:28:56 +01009#include "trompeloeil_doctest.hpp"
Václav Kubernátcb3af402020-02-12 16:49:17 +010010#include "completion.hpp"
Václav Kubernát4108e0d2018-10-29 13:32:22 +010011#include "utils.hpp"
12
13TEST_CASE("utils")
14{
Václav Kubernáta395d332019-02-13 16:49:20 +010015 SECTION("filterByPrefix")
Václav Kubernát4108e0d2018-10-29 13:32:22 +010016 {
Václav Kubernátcb3af402020-02-12 16:49:17 +010017 std::set<Completion> set{{"ahoj"}, {"coze"}, {"copak"}, {"aha"}, {"polivka"}};
Václav Kubernát4108e0d2018-10-29 13:32:22 +010018
Václav Kubernátcb3af402020-02-12 16:49:17 +010019 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át4108e0d2018-10-29 13:32:22 +010025 }
Václav Kubernáta44bdf22020-01-24 12:15:31 +010026
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át4108e0d2018-10-29 13:32:22 +010083}