File: file.cpp

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (46 lines) | stat: -rw-r--r-- 1,497 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "utils/file.hpp"

#include <iomanip>
#include <iostream>

#include "common/test.hpp"
#include "utils/command.hpp"
#include "utils/env.hpp"

using namespace polybar;

using expand_test_t = pair<string, string>;
class ExpandTest : public testing::TestWithParam<expand_test_t> {};

vector<expand_test_t> expand_absolute_test_list = {
    {"~/foo", env_util::get("HOME") + "/foo"},
    {"$HOME/foo", env_util::get("HOME") + "/foo"},
    {"/scratch/polybar", "/scratch/polybar"},
};

INSTANTIATE_TEST_SUITE_P(Inst, ExpandTest, ::testing::ValuesIn(expand_absolute_test_list));

TEST_P(ExpandTest, absolute) {
  EXPECT_EQ(file_util::expand(GetParam().first), GetParam().second);
}

TEST_P(ExpandTest, relativeToAbsolute) {
  EXPECT_EQ(file_util::expand(GetParam().first, "/scratch"), GetParam().second);
}

using expand_relative_test_t = std::tuple<string, string, string>;
class ExpandRelativeTest : public testing::TestWithParam<expand_relative_test_t> {};

vector<expand_relative_test_t> expand_relative_test_list = {
    {"../test", "/scratch", "/scratch/../test"},
    {"modules/battery", "/scratch/polybar", "/scratch/polybar/modules/battery"},
    {"/tmp/foo", "/scratch", "/tmp/foo"},
};

INSTANTIATE_TEST_SUITE_P(Inst, ExpandRelativeTest, ::testing::ValuesIn(expand_relative_test_list));

TEST_P(ExpandRelativeTest, correctness) {
  string path, relative_to, expected;
  std::tie(path, relative_to, expected) = GetParam();
  EXPECT_EQ(file_util::expand(path, relative_to), expected);
}