color.lua 773 B

123456789101112131415161718
  1. local function assert_colors_equal(c1, c2)
  2. if type(c1) == "table" and type(c2) == "table" then
  3. assert(c1.r == c2.r and c1.g == c2.g and c1.b == c2.b and c1.a == c2.a)
  4. else
  5. assert(c1 == c2)
  6. end
  7. end
  8. local function test_color_conversion()
  9. assert_colors_equal(core.colorspec_to_table("#fff"), {r = 255, g = 255, b = 255, a = 255})
  10. assert_colors_equal(core.colorspec_to_table(0xFF00FF00), {r = 0, g = 255, b = 0, a = 255})
  11. assert_colors_equal(core.colorspec_to_table("#00000000"), {r = 0, g = 0, b = 0, a = 0})
  12. assert_colors_equal(core.colorspec_to_table("green"), {r = 0, g = 128, b = 0, a = 255})
  13. assert_colors_equal(core.colorspec_to_table("gren"), nil)
  14. end
  15. unittests.register("test_color_conversion", test_color_conversion)