2024-05-21 12:42:08 +00:00
|
|
|
{ pkgs, lib, self }:
|
|
|
|
|
|
|
|
let
|
|
|
|
# A modified version that simply removes the functor to focus more on the
|
|
|
|
# actual results. Also, it will mess up the result comparison since comparing
|
|
|
|
# functions is reference-based so it will always fail.
|
|
|
|
normalizeData = colors:
|
2024-06-04 12:40:29 +00:00
|
|
|
lib.attrsets.removeAttrs colors [ "__functor" "methods" ];
|
2024-05-21 12:42:08 +00:00
|
|
|
|
|
|
|
rgbSample = self.colors.rgb.RGB {
|
|
|
|
r = 255;
|
|
|
|
g = 255;
|
|
|
|
b = 255;
|
|
|
|
};
|
|
|
|
|
|
|
|
# A modified version of RGB that normalizes data out-of-the-boxly.
|
|
|
|
RGB = colors: normalizeData (self.colors.rgb.RGB colors);
|
2024-06-04 12:40:29 +00:00
|
|
|
in lib.runTests {
|
2024-05-21 12:42:08 +00:00
|
|
|
testsBasicRgb = {
|
|
|
|
expr = RGB {
|
|
|
|
r = 34;
|
|
|
|
g = 2;
|
|
|
|
b = 0;
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
r = 34;
|
|
|
|
g = 2;
|
|
|
|
b = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-06-04 12:40:29 +00:00
|
|
|
testsBasicRgb2 = {
|
|
|
|
expr = RGB {
|
|
|
|
r = 23;
|
|
|
|
g = 65;
|
|
|
|
b = 241;
|
|
|
|
a = 255;
|
|
|
|
};
|
|
|
|
expected = {
|
|
|
|
r = 23;
|
|
|
|
g = 65;
|
|
|
|
b = 241;
|
|
|
|
a = 255;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-21 12:42:08 +00:00
|
|
|
testsFromHex = {
|
|
|
|
expr = normalizeData (self.colors.rgb.fromHex "FFFFFF");
|
|
|
|
expected = normalizeData (self.colors.rgb.RGB {
|
|
|
|
r = 255;
|
|
|
|
g = 255;
|
|
|
|
b = 255;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
testsFromHex2 = {
|
|
|
|
expr = normalizeData (self.colors.rgb.fromHex "FFF");
|
|
|
|
expected = normalizeData (self.colors.rgb.RGB {
|
|
|
|
r = 255;
|
|
|
|
g = 255;
|
|
|
|
b = 255;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
testsFromHex3 = {
|
|
|
|
expr = normalizeData (self.colors.rgb.fromHex "FFFF");
|
|
|
|
expected = normalizeData (self.colors.rgb.RGB {
|
|
|
|
r = 255;
|
|
|
|
g = 255;
|
|
|
|
b = 255;
|
2024-06-04 12:40:29 +00:00
|
|
|
a = 255;
|
2024-05-21 12:42:08 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
testsFromHex4 = {
|
|
|
|
expr = normalizeData (self.colors.rgb.fromHex "FFFFFFFF");
|
|
|
|
expected = normalizeData (self.colors.rgb.RGB {
|
|
|
|
r = 255;
|
|
|
|
g = 255;
|
|
|
|
b = 255;
|
2024-06-04 12:40:29 +00:00
|
|
|
a = 255;
|
2024-05-21 12:42:08 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
testsToHex = {
|
|
|
|
expr = self.colors.rgb.toHex rgbSample;
|
|
|
|
expected = "FFFFFF";
|
|
|
|
};
|
|
|
|
|
|
|
|
testsToHex2 = {
|
|
|
|
expr = self.colors.rgb.toHex (RGB {
|
|
|
|
r = 23;
|
|
|
|
g = 58;
|
|
|
|
b = 105;
|
|
|
|
});
|
|
|
|
expected = "173A69";
|
|
|
|
};
|
|
|
|
|
2024-06-14 15:46:01 +00:00
|
|
|
testsToHex3 = {
|
|
|
|
expr = self.colors.rgb.toHex (RGB {
|
|
|
|
r = 23;
|
|
|
|
g = 58;
|
|
|
|
b = 105;
|
|
|
|
a = 21;
|
|
|
|
});
|
|
|
|
expected = "173A69";
|
|
|
|
};
|
|
|
|
|
2024-06-04 12:40:29 +00:00
|
|
|
testsToHexVariant = {
|
|
|
|
expr = self.colors.rgb.toHex' (RGB {
|
|
|
|
r = 255;
|
|
|
|
g = 56;
|
|
|
|
b = 105;
|
|
|
|
});
|
|
|
|
expected = "FF3869FF";
|
|
|
|
};
|
|
|
|
|
|
|
|
testsToHexVariant2 = {
|
|
|
|
expr = self.colors.rgb.toHex' (RGB {
|
|
|
|
r = 255;
|
|
|
|
g = 56;
|
|
|
|
b = 105;
|
|
|
|
a = 34;
|
|
|
|
});
|
|
|
|
expected = "FF386922";
|
|
|
|
};
|
|
|
|
|
2024-05-21 12:42:08 +00:00
|
|
|
testsHexMatch = {
|
|
|
|
expr = self.colors.rgb.hexMatch "FFF";
|
|
|
|
expected = [ 255 255 255 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testsHexMatch2 = {
|
|
|
|
expr = self.colors.rgb.hexMatch "FFFF";
|
|
|
|
expected = [ 255 255 255 255 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testsHexMatch3 = {
|
|
|
|
expr = self.colors.rgb.hexMatch "0A0B0C0D";
|
|
|
|
expected = [ 10 11 12 13 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
testsHexMatch4 = {
|
|
|
|
expr = self.colors.rgb.hexMatch "0A0B0C";
|
|
|
|
expected = [ 10 11 12 ];
|
|
|
|
};
|
|
|
|
}
|