* Fixing clang tidy comments
* Fixing missing includes * Fixing formattingpull/2852/head
parent
9556b0fe89
commit
10cb4180f6
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "glibmm/refptr.h"
|
|
||||||
#include "giomm/file.h"
|
#include "giomm/file.h"
|
||||||
#include "giomm/filemonitor.h"
|
#include "giomm/filemonitor.h"
|
||||||
|
#include "glibmm/refptr.h"
|
||||||
|
|
||||||
struct pollfd;
|
struct pollfd;
|
||||||
|
|
||||||
|
@ -20,24 +21,21 @@ class CssReloadHelper {
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::string> parseImports(const std::string& cssFile);
|
std::vector<std::string> parseImports(const std::string& cssFile);
|
||||||
|
|
||||||
void parseImports(const std::string& cssFile,
|
void parseImports(const std::string& cssFile, std::unordered_map<std::string, bool>& imports);
|
||||||
std::unordered_map<std::string, bool>& imports);
|
|
||||||
|
|
||||||
|
|
||||||
void watchFiles(const std::vector<std::string>& files);
|
void watchFiles(const std::vector<std::string>& files);
|
||||||
|
|
||||||
bool handleInotifyEvents(int fd);
|
bool handleInotifyEvents(int fd);
|
||||||
|
|
||||||
bool watch(int inotifyFd, pollfd * pollFd);
|
bool watch(int inotifyFd, pollfd* pollFd);
|
||||||
|
|
||||||
virtual std::string getFileContents(const std::string& filename);
|
virtual std::string getFileContents(const std::string& filename);
|
||||||
|
|
||||||
virtual std::string findPath(const std::string& filename);
|
virtual std::string findPath(const std::string& filename);
|
||||||
|
|
||||||
void handleFileChange(
|
void handleFileChange(Glib::RefPtr<Gio::File> const& file,
|
||||||
Glib::RefPtr<Gio::File> const& file,
|
Glib::RefPtr<Gio::File> const& other_type,
|
||||||
Glib::RefPtr<Gio::File> const& other_type,
|
Gio::FileMonitorEvent event_type);
|
||||||
Gio::FileMonitorEvent event_type);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_cssFile;
|
std::string m_cssFile;
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "glibmm/refptr.h"
|
|
||||||
#include "giomm/file.h"
|
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
#include "giomm/file.h"
|
||||||
|
#include "glibmm/refptr.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const std::regex IMPORT_REGEX(R"(@import\s+(?:url\()?(?:"|')([^"')]+)(?:"|')\)?;)");
|
const std::regex IMPORT_REGEX(R"(@import\s+(?:url\()?(?:"|')([^"')]+)(?:"|')\)?;)");
|
||||||
|
@ -30,7 +30,7 @@ std::string waybar::CssReloadHelper::getFileContents(const std::string& filename
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::string((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
return {(std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string waybar::CssReloadHelper::findPath(const std::string& filename) {
|
std::string waybar::CssReloadHelper::findPath(const std::string& filename) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "util/css_reload_helper.hpp"
|
#include "util/css_reload_helper.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
#if __has_include(<catch2/catch_test_macros.hpp>)
|
#if __has_include(<catch2/catch_test_macros.hpp>)
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
@ -9,59 +9,39 @@
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
class CssReloadHelperTest : public waybar::CssReloadHelper {
|
||||||
|
public:
|
||||||
|
CssReloadHelperTest() : CssReloadHelper("/tmp/waybar_test.css", [this]() { callback(); }) {}
|
||||||
|
|
||||||
class CssReloadHelperTest : public waybar::CssReloadHelper
|
void callback() { m_callbackCounter++; }
|
||||||
{
|
|
||||||
public:
|
|
||||||
CssReloadHelperTest()
|
|
||||||
: CssReloadHelper("/tmp/waybar_test.css", [this]() {callback();})
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void callback()
|
protected:
|
||||||
{
|
std::string getFileContents(const std::string& filename) override {
|
||||||
m_callbackCounter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
std::string getFileContents(const std::string& filename) override
|
|
||||||
{
|
|
||||||
return m_fileContents[filename];
|
return m_fileContents[filename];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string findPath(const std::string& filename) override
|
std::string findPath(const std::string& filename) override { return filename; }
|
||||||
{
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setFileContents(const std::string& filename, const std::string& contents)
|
void setFileContents(const std::string& filename, const std::string& contents) {
|
||||||
{
|
|
||||||
m_fileContents[filename] = contents;
|
m_fileContents[filename] = contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getCallbackCounter() const
|
int getCallbackCounter() const { return m_callbackCounter; }
|
||||||
{
|
|
||||||
return m_callbackCounter;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_callbackCounter{};
|
int m_callbackCounter{};
|
||||||
std::map<std::string, std::string> m_fileContents;
|
std::map<std::string, std::string> m_fileContents;
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE_METHOD(CssReloadHelperTest, "parse_imports", "[util][css_reload_helper]")
|
TEST_CASE_METHOD(CssReloadHelperTest, "parse_imports", "[util][css_reload_helper]") {
|
||||||
{
|
SECTION("no imports") {
|
||||||
SECTION("no imports")
|
|
||||||
{
|
|
||||||
setFileContents("/tmp/waybar_test.css", "body { color: red; }");
|
setFileContents("/tmp/waybar_test.css", "body { color: red; }");
|
||||||
auto files = parseImports("/tmp/waybar_test.css");
|
auto files = parseImports("/tmp/waybar_test.css");
|
||||||
REQUIRE(files.size() == 1);
|
REQUIRE(files.size() == 1);
|
||||||
CHECK(files[0] == "/tmp/waybar_test.css");
|
CHECK(files[0] == "/tmp/waybar_test.css");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("single import")
|
SECTION("single import") {
|
||||||
{
|
|
||||||
setFileContents("/tmp/waybar_test.css", "@import 'test.css';");
|
setFileContents("/tmp/waybar_test.css", "@import 'test.css';");
|
||||||
setFileContents("test.css", "body { color: red; }");
|
setFileContents("test.css", "body { color: red; }");
|
||||||
auto files = parseImports("/tmp/waybar_test.css");
|
auto files = parseImports("/tmp/waybar_test.css");
|
||||||
|
@ -71,8 +51,7 @@ TEST_CASE_METHOD(CssReloadHelperTest, "parse_imports", "[util][css_reload_helper
|
||||||
CHECK(files[1] == "test.css");
|
CHECK(files[1] == "test.css");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("multiple imports")
|
SECTION("multiple imports") {
|
||||||
{
|
|
||||||
setFileContents("/tmp/waybar_test.css", "@import 'test.css'; @import 'test2.css';");
|
setFileContents("/tmp/waybar_test.css", "@import 'test.css'; @import 'test2.css';");
|
||||||
setFileContents("test.css", "body { color: red; }");
|
setFileContents("test.css", "body { color: red; }");
|
||||||
setFileContents("test2.css", "body { color: blue; }");
|
setFileContents("test2.css", "body { color: blue; }");
|
||||||
|
@ -84,8 +63,7 @@ TEST_CASE_METHOD(CssReloadHelperTest, "parse_imports", "[util][css_reload_helper
|
||||||
CHECK(files[2] == "test2.css");
|
CHECK(files[2] == "test2.css");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("nested imports")
|
SECTION("nested imports") {
|
||||||
{
|
|
||||||
setFileContents("/tmp/waybar_test.css", "@import 'test.css';");
|
setFileContents("/tmp/waybar_test.css", "@import 'test.css';");
|
||||||
setFileContents("test.css", "@import 'test2.css';");
|
setFileContents("test.css", "@import 'test2.css';");
|
||||||
setFileContents("test2.css", "body { color: red; }");
|
setFileContents("test2.css", "body { color: red; }");
|
||||||
|
@ -97,8 +75,7 @@ TEST_CASE_METHOD(CssReloadHelperTest, "parse_imports", "[util][css_reload_helper
|
||||||
CHECK(files[2] == "test2.css");
|
CHECK(files[2] == "test2.css");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("circular imports")
|
SECTION("circular imports") {
|
||||||
{
|
|
||||||
setFileContents("/tmp/waybar_test.css", "@import 'test.css';");
|
setFileContents("/tmp/waybar_test.css", "@import 'test.css';");
|
||||||
setFileContents("test.css", "@import 'test2.css';");
|
setFileContents("test.css", "@import 'test2.css';");
|
||||||
setFileContents("test2.css", "@import 'test.css';");
|
setFileContents("test2.css", "@import 'test.css';");
|
||||||
|
@ -110,16 +87,14 @@ TEST_CASE_METHOD(CssReloadHelperTest, "parse_imports", "[util][css_reload_helper
|
||||||
CHECK(files[2] == "test2.css");
|
CHECK(files[2] == "test2.css");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("empty")
|
SECTION("empty") {
|
||||||
{
|
|
||||||
setFileContents("/tmp/waybar_test.css", "");
|
setFileContents("/tmp/waybar_test.css", "");
|
||||||
auto files = parseImports("/tmp/waybar_test.css");
|
auto files = parseImports("/tmp/waybar_test.css");
|
||||||
REQUIRE(files.size() == 1);
|
REQUIRE(files.size() == 1);
|
||||||
CHECK(files[0] == "/tmp/waybar_test.css");
|
CHECK(files[0] == "/tmp/waybar_test.css");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("empty name")
|
SECTION("empty name") {
|
||||||
{
|
|
||||||
auto files = parseImports("");
|
auto files = parseImports("");
|
||||||
REQUIRE(files.empty());
|
REQUIRE(files.empty());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue