From 10cb4180f67a1a3d43cf00574ebcade25205047c Mon Sep 17 00:00:00 2001 From: dpayne Date: Sun, 28 Jan 2024 14:44:25 -0800 Subject: [PATCH] * Fixing clang tidy comments * Fixing missing includes * Fixing formatting --- include/util/css_reload_helper.hpp | 16 ++++---- src/util/css_reload_helper.cpp | 6 +-- test/css_reload_helper.cpp | 63 +++++++++--------------------- 3 files changed, 29 insertions(+), 56 deletions(-) diff --git a/include/util/css_reload_helper.hpp b/include/util/css_reload_helper.hpp index 4da64ec6..4826fc31 100644 --- a/include/util/css_reload_helper.hpp +++ b/include/util/css_reload_helper.hpp @@ -2,11 +2,12 @@ #include #include +#include #include -#include "glibmm/refptr.h" #include "giomm/file.h" #include "giomm/filemonitor.h" +#include "glibmm/refptr.h" struct pollfd; @@ -20,24 +21,21 @@ class CssReloadHelper { protected: std::vector parseImports(const std::string& cssFile); - void parseImports(const std::string& cssFile, - std::unordered_map& imports); - + void parseImports(const std::string& cssFile, std::unordered_map& imports); void watchFiles(const std::vector& files); 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 findPath(const std::string& filename); - void handleFileChange( - Glib::RefPtr const& file, - Glib::RefPtr const& other_type, - Gio::FileMonitorEvent event_type); + void handleFileChange(Glib::RefPtr const& file, + Glib::RefPtr const& other_type, + Gio::FileMonitorEvent event_type); private: std::string m_cssFile; diff --git a/src/util/css_reload_helper.cpp b/src/util/css_reload_helper.cpp index 9bbd0f93..45fd801a 100644 --- a/src/util/css_reload_helper.cpp +++ b/src/util/css_reload_helper.cpp @@ -8,10 +8,10 @@ #include #include #include -#include "glibmm/refptr.h" -#include "giomm/file.h" #include "config.hpp" +#include "giomm/file.h" +#include "glibmm/refptr.h" namespace { const std::regex IMPORT_REGEX(R"(@import\s+(?:url\()?(?:"|')([^"')]+)(?:"|')\)?;)"); @@ -30,7 +30,7 @@ std::string waybar::CssReloadHelper::getFileContents(const std::string& filename return {}; } - return std::string((std::istreambuf_iterator(file)), std::istreambuf_iterator()); + return {(std::istreambuf_iterator(file)), std::istreambuf_iterator()}; } std::string waybar::CssReloadHelper::findPath(const std::string& filename) { diff --git a/test/css_reload_helper.cpp b/test/css_reload_helper.cpp index ac7b3eb7..01850bc3 100644 --- a/test/css_reload_helper.cpp +++ b/test/css_reload_helper.cpp @@ -1,6 +1,6 @@ #include "util/css_reload_helper.hpp" + #include -#include #if __has_include() #include @@ -9,59 +9,39 @@ #include #endif +class CssReloadHelperTest : public waybar::CssReloadHelper { + public: + CssReloadHelperTest() : CssReloadHelper("/tmp/waybar_test.css", [this]() { callback(); }) {} -class CssReloadHelperTest : public waybar::CssReloadHelper -{ -public: - CssReloadHelperTest() - : CssReloadHelper("/tmp/waybar_test.css", [this]() {callback();}) - { - } + void callback() { m_callbackCounter++; } - void callback() - { - m_callbackCounter++; - } - -protected: - - std::string getFileContents(const std::string& filename) override - { + protected: + std::string getFileContents(const std::string& filename) override { return m_fileContents[filename]; } - std::string findPath(const std::string& filename) override - { - return filename; - } + std::string findPath(const std::string& filename) override { 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; } - int getCallbackCounter() const - { - return m_callbackCounter; - } + int getCallbackCounter() const { return m_callbackCounter; } -private: + private: int m_callbackCounter{}; std::map m_fileContents; }; -TEST_CASE_METHOD(CssReloadHelperTest, "parse_imports", "[util][css_reload_helper]") -{ - SECTION("no imports") - { +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") - { + SECTION("single import") { setFileContents("/tmp/waybar_test.css", "@import 'test.css';"); setFileContents("test.css", "body { color: red; }"); 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"); } - SECTION("multiple imports") - { + 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; }"); @@ -84,8 +63,7 @@ TEST_CASE_METHOD(CssReloadHelperTest, "parse_imports", "[util][css_reload_helper CHECK(files[2] == "test2.css"); } - SECTION("nested imports") - { + SECTION("nested imports") { setFileContents("/tmp/waybar_test.css", "@import 'test.css';"); setFileContents("test.css", "@import 'test2.css';"); 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"); } - SECTION("circular imports") - { + SECTION("circular imports") { setFileContents("/tmp/waybar_test.css", "@import 'test.css';"); setFileContents("test.css", "@import 'test2.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"); } - SECTION("empty") - { + 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") - { + SECTION("empty name") { auto files = parseImports(""); REQUIRE(files.empty()); }