1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 12:27:52 +00:00
conky/tests/test-colours.cc
bi4k8 30eda7e5d0
colours: parse 3-digit colour specifications again (#1480)
Co-authored-by: bi4k8 <bi4k8@github>
2023-03-31 12:52:37 -04:00

110 lines
2.9 KiB
C++

#include "catch2/catch.hpp"
#include <colours.h>
#include <config.h>
TEST_CASE("parse_color correctly parses colours", "[colours][parse_color]") {
SECTION("parsing abbreviated hex color") {
auto colour = parse_color("#abc");
REQUIRE(colour.alpha == 255);
REQUIRE(colour.red == 0xaa);
REQUIRE(colour.green == 0xbb);
REQUIRE(colour.blue == 0xcc);
}
SECTION("parsing abbreviated hex color with alpha") {
auto colour = parse_color("#4abc");
REQUIRE(colour.alpha == 0x44);
REQUIRE(colour.red == 0xaa);
REQUIRE(colour.green == 0xbb);
REQUIRE(colour.blue == 0xcc);
}
SECTION("parsing hex red") {
auto colour = parse_color("#ff0000");
REQUIRE(colour.alpha == 255);
REQUIRE(colour.red == 255);
REQUIRE(colour.green == 0);
REQUIRE(colour.blue == 0);
}
SECTION("parsing hex green") {
auto colour = parse_color("#00ff00");
REQUIRE(colour.alpha == 255);
REQUIRE(colour.red == 0);
REQUIRE(colour.green == 255);
REQUIRE(colour.blue == 0);
}
SECTION("parsing hex blue") {
auto colour = parse_color("#0000ff");
REQUIRE(colour.alpha == 255);
REQUIRE(colour.red == 0);
REQUIRE(colour.green == 0);
REQUIRE(colour.blue == 255);
}
SECTION("parsing red") {
auto colour = parse_color("ff0000");
REQUIRE(colour.alpha == 255);
REQUIRE(colour.red == 255);
REQUIRE(colour.green == 0);
REQUIRE(colour.blue == 0);
}
SECTION("parsing green") {
auto colour = parse_color("00ff00");
REQUIRE(colour.alpha == 255);
REQUIRE(colour.red == 0);
REQUIRE(colour.green == 255);
REQUIRE(colour.blue == 0);
}
SECTION("parsing blue") {
auto colour = parse_color("0000ff");
REQUIRE(colour.alpha == 255);
REQUIRE(colour.red == 0);
REQUIRE(colour.green == 0);
REQUIRE(colour.blue == 255);
}
SECTION("argb values produce the expected result") {
auto colour = Colour::from_argb32(0x11223344);
REQUIRE(colour.alpha == 0x11);
REQUIRE(colour.red == 0x22);
REQUIRE(colour.green == 0x33);
REQUIRE(colour.blue == 0x44);
}
SECTION("it parses the colour 'red'") {
auto colour = parse_color("red");
REQUIRE(colour.alpha == 255);
REQUIRE(colour.red == 255);
REQUIRE(colour.green == 0);
REQUIRE(colour.blue == 0);
}
SECTION("it parses the colour 'green'") {
auto colour = parse_color("green");
REQUIRE(colour.alpha == 255);
REQUIRE(colour.red == 0);
REQUIRE(colour.green == 255);
REQUIRE(colour.blue == 0);
}
SECTION("it parses the colour 'blue'") {
auto colour = parse_color("blue");
REQUIRE(colour.alpha == 255);
REQUIRE(colour.red == 0);
REQUIRE(colour.green == 0);
REQUIRE(colour.blue == 255);
}
SECTION("two identical colours should be equal") {
auto c = GENERATE(take(100, random((uint32_t)0, (uint32_t)0xffffffff)));
auto colour1 = Colour::from_argb32(c);
auto colour2 = Colour::from_argb32(c);
REQUIRE(colour1 == colour2);
}
}