forked from Alexays/Waybar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss_reload_helper.cpp
100 lines (84 loc) · 3.23 KB
/
css_reload_helper.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "util/css_reload_helper.hpp"
#include <map>
#if __has_include(<catch2/catch_test_macros.hpp>)
#include <catch2/catch_test_macros.hpp>
#else
#include <catch2/catch.hpp>
#endif
class CssReloadHelperTest : public waybar::CssReloadHelper {
public:
CssReloadHelperTest() : CssReloadHelper("/tmp/waybar_test.css", [this]() { callback(); }) {}
void callback() { m_callbackCounter++; }
protected:
std::string getFileContents(const std::string& filename) override {
return m_fileContents[filename];
}
std::string findPath(const std::string& filename) override { return filename; }
void setFileContents(const std::string& filename, const std::string& contents) {
m_fileContents[filename] = contents;
}
int getCallbackCounter() const { return m_callbackCounter; }
private:
int m_callbackCounter{};
std::map<std::string, std::string> m_fileContents;
};
TEST_CASE_METHOD(CssReloadHelperTest, "parse_imports", "[util][css_reload_helper]") {
SECTION("no imports") {
setFileContents("/tmp/waybar_test.css", "body { color: red; }");
auto files = parseImports("/tmp/waybar_test.css");
REQUIRE(files.size() == 1);
CHECK(files[0] == "/tmp/waybar_test.css");
}
SECTION("single import") {
setFileContents("/tmp/waybar_test.css", "@import 'test.css';");
setFileContents("test.css", "body { color: red; }");
auto files = parseImports("/tmp/waybar_test.css");
std::sort(files.begin(), files.end());
REQUIRE(files.size() == 2);
CHECK(files[0] == "/tmp/waybar_test.css");
CHECK(files[1] == "test.css");
}
SECTION("multiple imports") {
setFileContents("/tmp/waybar_test.css", "@import 'test.css'; @import 'test2.css';");
setFileContents("test.css", "body { color: red; }");
setFileContents("test2.css", "body { color: blue; }");
auto files = parseImports("/tmp/waybar_test.css");
std::sort(files.begin(), files.end());
REQUIRE(files.size() == 3);
CHECK(files[0] == "/tmp/waybar_test.css");
CHECK(files[1] == "test.css");
CHECK(files[2] == "test2.css");
}
SECTION("nested imports") {
setFileContents("/tmp/waybar_test.css", "@import 'test.css';");
setFileContents("test.css", "@import 'test2.css';");
setFileContents("test2.css", "body { color: red; }");
auto files = parseImports("/tmp/waybar_test.css");
std::sort(files.begin(), files.end());
REQUIRE(files.size() == 3);
CHECK(files[0] == "/tmp/waybar_test.css");
CHECK(files[1] == "test.css");
CHECK(files[2] == "test2.css");
}
SECTION("circular imports") {
setFileContents("/tmp/waybar_test.css", "@import 'test.css';");
setFileContents("test.css", "@import 'test2.css';");
setFileContents("test2.css", "@import 'test.css';");
auto files = parseImports("/tmp/waybar_test.css");
std::sort(files.begin(), files.end());
REQUIRE(files.size() == 3);
CHECK(files[0] == "/tmp/waybar_test.css");
CHECK(files[1] == "test.css");
CHECK(files[2] == "test2.css");
}
SECTION("empty") {
setFileContents("/tmp/waybar_test.css", "");
auto files = parseImports("/tmp/waybar_test.css");
REQUIRE(files.size() == 1);
CHECK(files[0] == "/tmp/waybar_test.css");
}
SECTION("empty name") {
auto files = parseImports("");
REQUIRE(files.empty());
}
}