* Fixing clang tidy comments

* Fixing missing includes
* Fixing formatting
pull/2852/head
dpayne 2024-01-28 14:44:25 -08:00
parent 9556b0fe89
commit 10cb4180f6
3 changed files with 29 additions and 56 deletions

View File

@ -2,11 +2,12 @@
#include <functional>
#include <string>
#include <unordered_map>
#include <vector>
#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<std::string> parseImports(const std::string& cssFile);
void parseImports(const std::string& cssFile,
std::unordered_map<std::string, bool>& imports);
void parseImports(const std::string& cssFile, std::unordered_map<std::string, bool>& imports);
void watchFiles(const std::vector<std::string>& 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<Gio::File> const& file,
Glib::RefPtr<Gio::File> const& other_type,
Gio::FileMonitorEvent event_type);
void handleFileChange(Glib::RefPtr<Gio::File> const& file,
Glib::RefPtr<Gio::File> const& other_type,
Gio::FileMonitorEvent event_type);
private:
std::string m_cssFile;

View File

@ -8,10 +8,10 @@
#include <fstream>
#include <regex>
#include <unordered_map>
#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<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) {

View File

@ -1,6 +1,6 @@
#include "util/css_reload_helper.hpp"
#include <map>
#include <fstream>
#if __has_include(<catch2/catch_test_macros.hpp>)
#include <catch2/catch_test_macros.hpp>
@ -9,59 +9,39 @@
#include <catch2/catch.hpp>
#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<std::string, std::string> 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());
}