blob: 509c2fe2091919a8b4e672f09a9af6f8cefefbbc [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át2984f442020-02-20 17:43:35 +010011#include "leaf_data_helpers.hpp"
Václav Kubernát4108e0d2018-10-29 13:32:22 +010012#include "utils.hpp"
13
14TEST_CASE("utils")
15{
Václav Kubernáta395d332019-02-13 16:49:20 +010016 SECTION("filterByPrefix")
Václav Kubernát4108e0d2018-10-29 13:32:22 +010017 {
Václav Kubernátcb3af402020-02-12 16:49:17 +010018 std::set<Completion> set{{"ahoj"}, {"coze"}, {"copak"}, {"aha"}, {"polivka"}};
Václav Kubernát4108e0d2018-10-29 13:32:22 +010019
Václav Kubernátcb3af402020-02-12 16:49:17 +010020 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át4108e0d2018-10-29 13:32:22 +010026 }
Václav Kubernáta44bdf22020-01-24 12:15:31 +010027
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át2984f442020-02-20 17:43:35 +010084
85 SECTION("leafDataTypeToString")
86 {
87 yang::LeafDataType type;
88 std::string expected;
89 SECTION("union")
90 {
91 type = yang::Union{{
Václav Kubernát13b23d72020-04-16 21:49:51 +020092 yang::TypeInfo{yang::String{}},
93 yang::TypeInfo{createEnum({"foo", "bar"})},
94 yang::TypeInfo{yang::Int8{}},
95 yang::TypeInfo{yang::Int64{}},
Václav Kubernát2984f442020-02-20 17:43:35 +010096 }};
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át4108e0d2018-10-29 13:32:22 +0100104}