<commit_before>#include "utils/color.hpp"

#include "common/test.hpp"

using namespace polybar;

TEST(Rgba, constructor) {
  rgba v{"invalid"};
  EXPECT_FALSE(v.has_color());

  v = rgba{"#f"};
  EXPECT_FALSE(v.has_color());

  v = rgba{"#12"};
  EXPECT_EQ(rgba::ALPHA_ONLY, v.m_type);

  v = rgba{"#ff"};
  EXPECT_EQ(0xff000000, v.m_value);

  v = rgba{"#fff"};
  EXPECT_EQ(0xffffffff, v.m_value);

  v = rgba{"#890"};
  EXPECT_EQ(0xFF889900, v.m_value);

  v = rgba{"#a890"};
  EXPECT_EQ(0xaa889900, v.m_value);

  v = rgba{"#55888777"};
  EXPECT_EQ(0x55888777, v.m_value);

  v = rgba{"#88aaaaaa"};
  EXPECT_EQ(0x88aaaaaa, v.m_value);

  v = rgba{"#00aaaaaa"};
  EXPECT_EQ(0x00aaaaaa, v.m_value);

  v = rgba{"#00FFFFFF"};
  EXPECT_EQ(0x00FFFFFF, v.m_value);
}

TEST(Rgba, parse) {
  EXPECT_EQ(0xffffffff, rgba{"#fff"}.m_value);
  EXPECT_EQ(0xffffffff, rgba{"fff"}.m_value);
  EXPECT_EQ(0xff112233, rgba{"#123"}.m_value);
  EXPECT_EQ(0xff112233, rgba{"123"}.m_value);
  EXPECT_EQ(0xff888888, rgba{"#888888"}.m_value);
  EXPECT_EQ(0xff888888, rgba{"888888"}.m_value);
  EXPECT_EQ(0x00aa00aa, rgba{"#00aa00aa"}.m_value);
  EXPECT_EQ(0x00aa00aa, rgba{"00aa00aa"}.m_value);
  EXPECT_EQ(0x11223344, rgba{"#1234"}.m_value);
  EXPECT_EQ(0x11223344, rgba{"1234"}.m_value);
  EXPECT_EQ(0xaa000000, rgba{"#aa"}.m_value);
  EXPECT_EQ(0xaa000000, rgba{"aa"}.m_value);
}

TEST(Rgba, string) {
  rgba v{"#1234"};

  EXPECT_EQ("#11223344", static_cast<string>(v));

  v = rgba{"#12"};

  EXPECT_EQ("#12000000", static_cast<string>(v));
}

TEST(Rgba, eq) {
  rgba v(0x12, rgba::NONE);

  EXPECT_TRUE(v == rgba(0, rgba::NONE));
  EXPECT_TRUE(v == rgba(0x11, rgba::NONE));
  EXPECT_FALSE(v == rgba{0x1234});

  v = rgba{0xCC123456};

  EXPECT_TRUE(v == rgba{0xCC123456});
  EXPECT_FALSE(v == rgba(0xCC123456, rgba::NONE));

  v = rgba{"#aa"};

  EXPECT_TRUE(v == rgba(0xaa000000, rgba::ALPHA_ONLY));
  EXPECT_FALSE(v == rgba(0xaa000000, rgba::ARGB));
  EXPECT_FALSE(v == rgba(0xab000000, rgba::ALPHA_ONLY));
}

TEST(Rgba, hasColor) {
  rgba v{"#"};

  EXPECT_FALSE(v.has_color());

  v = rgba{"#ff"};

  EXPECT_TRUE(v.has_color());

  v = rgba{"#cc123456"};

  EXPECT_TRUE(v.has_color());

  v = rgba(0x1243, rgba::NONE);

  EXPECT_FALSE(v.has_color());
}

TEST(Rgba, channel) {
  rgba v{0xCC123456};
  EXPECT_EQ(0xCC, v.a_int());
  EXPECT_EQ(0x12, v.r_int());
  EXPECT_EQ(0x34, v.g_int());
  EXPECT_EQ(0x56, v.b_int());

  EXPECT_EQ(0xCC / 255.0, rgba{0xCC112233}.a());
  EXPECT_EQ(0x99 / 255.0, rgba{0x88449933}.g());
}

TEST(ColorUtil, simplify) {<commit_msg>Add tests for apply_alpha<commit_after>#include "utils/color.hpp"

#include "common/test.hpp"

using namespace polybar;

TEST(Rgba, constructor) {
  rgba v{"invalid"};
  EXPECT_FALSE(v.has_color());

  v = rgba{"#f"};
  EXPECT_FALSE(v.has_color());

  v = rgba{"#12"};
  EXPECT_EQ(rgba::ALPHA_ONLY, v.m_type);

  v = rgba{"#ff"};
  EXPECT_EQ(0xff000000, v.m_value);

  v = rgba{"#fff"};
  EXPECT_EQ(0xffffffff, v.m_value);

  v = rgba{"#890"};
  EXPECT_EQ(0xFF889900, v.m_value);

  v = rgba{"#a890"};
  EXPECT_EQ(0xaa889900, v.m_value);

  v = rgba{"#55888777"};
  EXPECT_EQ(0x55888777, v.m_value);

  v = rgba{"#88aaaaaa"};
  EXPECT_EQ(0x88aaaaaa, v.m_value);

  v = rgba{"#00aaaaaa"};
  EXPECT_EQ(0x00aaaaaa, v.m_value);

  v = rgba{"#00FFFFFF"};
  EXPECT_EQ(0x00FFFFFF, v.m_value);
}

TEST(Rgba, parse) {
  EXPECT_EQ(0xffffffff, rgba{"#fff"}.m_value);
  EXPECT_EQ(0xffffffff, rgba{"fff"}.m_value);
  EXPECT_EQ(0xff112233, rgba{"#123"}.m_value);
  EXPECT_EQ(0xff112233, rgba{"123"}.m_value);
  EXPECT_EQ(0xff888888, rgba{"#888888"}.m_value);
  EXPECT_EQ(0xff888888, rgba{"888888"}.m_value);
  EXPECT_EQ(0x00aa00aa, rgba{"#00aa00aa"}.m_value);
  EXPECT_EQ(0x00aa00aa, rgba{"00aa00aa"}.m_value);
  EXPECT_EQ(0x11223344, rgba{"#1234"}.m_value);
  EXPECT_EQ(0x11223344, rgba{"1234"}.m_value);
  EXPECT_EQ(0xaa000000, rgba{"#aa"}.m_value);
  EXPECT_EQ(0xaa000000, rgba{"aa"}.m_value);
}

TEST(Rgba, string) {
  rgba v{"#1234"};

  EXPECT_EQ("#11223344", static_cast<string>(v));

  v = rgba{"#12"};

  EXPECT_EQ("#12000000", static_cast<string>(v));
}

TEST(Rgba, eq) {
  rgba v(0x12, rgba::NONE);

  EXPECT_TRUE(v == rgba(0, rgba::NONE));
  EXPECT_TRUE(v == rgba(0x11, rgba::NONE));
  EXPECT_FALSE(v == rgba{0x1234});

  v = rgba{0xCC123456};

  EXPECT_TRUE(v == rgba{0xCC123456});
  EXPECT_FALSE(v == rgba(0xCC123456, rgba::NONE));

  v = rgba{"#aa"};

  EXPECT_TRUE(v == rgba(0xaa000000, rgba::ALPHA_ONLY));
  EXPECT_FALSE(v == rgba(0xaa000000, rgba::ARGB));
  EXPECT_FALSE(v == rgba(0xab000000, rgba::ALPHA_ONLY));
}

TEST(Rgba, hasColor) {
  rgba v{"#"};

  EXPECT_FALSE(v.has_color());

  v = rgba{"#ff"};

  EXPECT_TRUE(v.has_color());

  v = rgba{"#cc123456"};

  EXPECT_TRUE(v.has_color());

  v = rgba(0x1243, rgba::NONE);

  EXPECT_FALSE(v.has_color());
}

TEST(Rgba, channel) {
  rgba v{0xCC123456};
  EXPECT_EQ(0xCC, v.a_int());
  EXPECT_EQ(0x12, v.r_int());
  EXPECT_EQ(0x34, v.g_int());
  EXPECT_EQ(0x56, v.b_int());

  EXPECT_EQ(0xCC / 255.0, rgba{0xCC112233}.a());
  EXPECT_EQ(0x99 / 255.0, rgba{0x88449933}.g());
}

TEST(Rgba, applyAlpha) {
  rgba v{0xCC123456};
  v.apply_alpha(rgba{0xAA000000, rgba::ALPHA_ONLY});
  EXPECT_EQ(0xAA123456, v.m_value);

  v = rgba{0x00123456};
  v.apply_alpha(rgba{0xCC999999});
  EXPECT_EQ(0xCC123456, v.m_value);
}

TEST(ColorUtil, simplify) {
{'fraction_non_alphanumeric': 0.20389440179741622, 'fraction_numerical': 0.12057667103538663, 'mean_word_length': 5.451690821256038, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6180009', 'n_tokens_mistral': 3037, 'n_tokens_neox': 2441, 'n_words': 322}