From 477189e44302bfa68729bce8ba8ad77d08169389 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Fri, 27 Nov 2020 20:46:04 +0100
Subject: [PATCH] Cleanup
---
include/components/builder.hpp | 3 ---
src/utils/color.cpp | 6 +----
tests/unit_tests/utils/color.cpp | 44 ++++++++++----------------------
3 files changed, 15 insertions(+), 38 deletions(-)
diff --git a/include/components/builder.hpp b/include/components/builder.hpp
index 4d39f62d..8aeeafa3 100644
--- a/include/components/builder.hpp
+++ b/include/components/builder.hpp
@@ -70,9 +70,6 @@ class builder {
map m_attrs{};
int m_fontindex{0};
-
- string m_background{};
- string m_foreground{};
};
POLYBAR_NS_END
diff --git a/src/utils/color.cpp b/src/utils/color.cpp
index 8fdbc565..e46750d4 100644
--- a/src/utils/color.cpp
+++ b/src/utils/color.cpp
@@ -51,7 +51,6 @@ static string normalize_hex(string hex) {
return hex;
}
-
rgba::rgba() : m_value(0), m_type(NONE) {}
rgba::rgba(uint32_t value, color_type type) : m_value(value), m_type(type) {}
rgba::rgba(string hex) {
@@ -71,9 +70,7 @@ rgba::rgba(string hex) {
rgba::operator string() const {
char s[10];
- size_t len = 0;
-
- len = snprintf(s, 10, "#%08x", m_value);
+ size_t len = snprintf(s, 10, "#%08x", m_value);
return string(s, len);
}
@@ -98,7 +95,6 @@ rgba::operator uint32_t() const {
return m_value;
}
-
uint32_t rgba::value() const {
return this->m_value;
}
diff --git a/tests/unit_tests/utils/color.cpp b/tests/unit_tests/utils/color.cpp
index ea0c51e7..a780ed17 100644
--- a/tests/unit_tests/utils/color.cpp
+++ b/tests/unit_tests/utils/color.cpp
@@ -5,38 +5,27 @@
using namespace polybar;
TEST(Rgba, constructor) {
- rgba v{"invalid"};
- EXPECT_FALSE(v.has_color());
+ EXPECT_FALSE(rgba("invalid").has_color());
- v = rgba{"#f"};
- EXPECT_FALSE(v.has_color());
+ EXPECT_FALSE(rgba("#f").has_color());
- v = rgba{"#12"};
- EXPECT_EQ(rgba::ALPHA_ONLY, v.type());
+ EXPECT_EQ(rgba::ALPHA_ONLY, rgba{"#12"}.type());
- v = rgba{"#ff"};
- EXPECT_EQ(0xff000000, (uint32_t)v.value());
+ EXPECT_EQ(0xff000000, rgba{"#ff"}.value());
- v = rgba{"#fff"};
- EXPECT_EQ(0xffffffff, v.value());
+ EXPECT_EQ(0xffffffff, rgba{"#fff"}.value());
- v = rgba{"#890"};
- EXPECT_EQ(0xFF889900, v.value());
+ EXPECT_EQ(0xFF889900, rgba{"#890"}.value());
- v = rgba{"#a890"};
- EXPECT_EQ(0xaa889900, v.value());
+ EXPECT_EQ(0xaa889900, rgba{"#a890"}.value());
- v = rgba{"#55888777"};
- EXPECT_EQ(0x55888777, v.value());
+ EXPECT_EQ(0x55888777, rgba{"#55888777"}.value());
- v = rgba{"#88aaaaaa"};
- EXPECT_EQ(0x88aaaaaa, v.value());
+ EXPECT_EQ(0x88aaaaaa, rgba{"#88aaaaaa"}.value());
- v = rgba{"#00aaaaaa"};
- EXPECT_EQ(0x00aaaaaa, v.value());
+ EXPECT_EQ(0x00aaaaaa, rgba{"#00aaaaaa"}.value());
- v = rgba{"#00FFFFFF"};
- EXPECT_EQ(0x00FFFFFF, v.value());
+ EXPECT_EQ(0x00FFFFFF, rgba{"#00FFFFFF"}.value());
}
TEST(Rgba, parse) {
@@ -55,13 +44,8 @@ TEST(Rgba, parse) {
}
TEST(Rgba, string) {
- rgba v{"#1234"};
-
- EXPECT_EQ("#11223344", static_cast(v));
-
- v = rgba{"#12"};
-
- EXPECT_EQ("#12000000", static_cast(v));
+ EXPECT_EQ("#11223344", static_cast(rgba{"#1234"}));
+ EXPECT_EQ("#12000000", static_cast(rgba{"#12"}));
}
TEST(Rgba, eq) {
@@ -69,7 +53,7 @@ TEST(Rgba, eq) {
EXPECT_TRUE(v == rgba(0, rgba::NONE));
EXPECT_TRUE(v == rgba(0x11, rgba::NONE));
- EXPECT_FALSE(v == rgba{0x1234});
+ EXPECT_FALSE(v == rgba{0x123456});
v = rgba{0xCC123456};