[
{ "fn": "parseHex", "name": "six digits", "args": ["#e69f00"], "expect": { "r": 230, "g": 159, "b": 0 } },
{ "fn": "parseHex", "name": "upper case", "args": ["#56B4E9"], "expect": { "r": 86, "g": 180, "b": 233 } },
{ "fn": "parseHex", "name": "three digits double each one, as CSS does", "args": ["#f80"], "expect": { "r": 255, "g": 136, "b": 0 } },
{ "fn": "parseHex", "name": "black", "args": ["#000000"], "expect": { "r": 0, "g": 0, "b": 0 } },
{ "fn": "parseHex", "name": "white", "args": ["#FFF"], "expect": { "r": 255, "g": 255, "b": 255 } },
{ "fn": "parseHex", "name": "a missing # is an error", "args": ["e69f00"], "expectError": "is not a hex colour (#rgb or #rrggbb)" },
{ "fn": "parseHex", "name": "a non-hex digit is an error", "args": ["#e69g00"], "expectError": "is not a hex colour (#rgb or #rrggbb)" },
{ "fn": "parseHex", "name": "an alpha channel is not accepted", "args": ["#e69f00ff"], "expectError": "is not a hex colour (#rgb or #rrggbb)" },
{ "fn": "parseHex", "name": "a colour name is an error", "args": ["red"], "expectError": "is not a hex colour (#rgb or #rrggbb)" },
{ "fn": "toHex", "name": "lower case, two digits per channel", "args": [{ "r": 230, "g": 159, "b": 0 }], "expect": "#e69f00" },
{ "fn": "toHex", "name": "single-digit channels are zero-padded", "args": [{ "r": 1, "g": 10, "b": 15 }], "expect": "#010a0f" },
{ "fn": "toHex", "name": "white", "args": [{ "r": 255, "g": 255, "b": 255 }], "expect": "#ffffff" },
{ "fn": "toHex", "name": "a channel above 255 is an error", "args": [{ "r": 256, "g": 0, "b": 0 }], "expectError": "rgb channels must be whole numbers from 0 to 255" },
{ "fn": "toHex", "name": "a negative channel is an error", "args": [{ "r": 0, "g": -1, "b": 0 }], "expectError": "rgb channels must be whole numbers from 0 to 255" },
{ "fn": "srgbToLinear", "name": "black is 0", "args": [0], "expect": 0 },
{ "fn": "srgbToLinear", "name": "white is 1", "args": [255], "expect": 1 },
{ "fn": "srgbToLinear", "name": "the darkest step is on the straight segment: 1/255/12.92", "args": [1], "expect": 0.000303526984 },
{ "fn": "srgbToLinear", "name": "10 is the last value on the straight segment", "args": [10], "expect": 0.003035269835 },
{ "fn": "srgbToLinear", "name": "11 is the first on the power curve", "args": [11], "expect": 0.003346535764 },
{ "fn": "srgbToLinear", "name": "mid grey 128 is only 21.6% of the light, not 50%", "args": [128], "expect": 0.215860500114 },
{ "fn": "srgbToLinear", "name": "188 is about half the light", "args": [188], "expect": 0.502886458033 },
{ "fn": "srgbToLinear", "name": "above 255 is an error", "args": [256], "expectError": "channel must be a whole number from 0 to 255" },
{ "fn": "linearToSrgb", "name": "half the light is 188, not 128", "args": [0.5], "expect": 188 },
{ "fn": "linearToSrgb", "name": "back from 128's linear value", "args": [0.215860500114], "expect": 128 },
{ "fn": "linearToSrgb", "name": "back from 1's linear value", "args": [0.000303526984], "expect": 1 },
{ "fn": "linearToSrgb", "name": "the straight segment's end: 12.92 x 0.0031308 x 255 = 10.31", "args": [0.0031308], "expect": 10 },
{ "fn": "linearToSrgb", "name": "on the straight segment 6.59 rounds to 7", "args": [0.002], "expect": 7 },
{ "fn": "linearToSrgb", "name": "white", "args": [1], "expect": 255 },
{ "fn": "linearToSrgb", "name": "below 0 clips to black", "args": [-0.1], "expect": 0 },
{ "fn": "linearToSrgb", "name": "above 1 clips to white", "args": [1.2], "expect": 255 },
{ "fn": "linearToSrgb", "name": "18% grey", "args": [0.18], "expect": 118 },
{ "fn": "toHex", "name": "black", "args": [{ "r": 0, "g": 0, "b": 0 }], "expect": "#000000" },
{ "fn": "toHex", "name": "15 and 16 straddle the digit boundary, so both are padded to two digits", "args": [{ "r": 15, "g": 16, "b": 255 }], "expect": "#0f10ff" },
{ "fn": "toHex", "name": "mid grey", "args": [{ "r": 128, "g": 128, "b": 128 }], "expect": "#808080" },
{ "fn": "linearToSrgb", "name": "black stays black", "args": [0], "expect": 0 },
{ "fn": "linearToSrgb", "name": "on the straight segment 3.29 rounds down to 3", "args": [0.001], "expect": 3 },
{ "fn": "toHex", "name": "a blue channel above 255 is an error", "args": [{ "r": 0, "g": 0, "b": 300 }], "expectError": "rgb channels must be whole numbers from 0 to 255" },
{ "fn": "linearToSrgb", "name": "a value that is not a number is an error, not black", "args": ["0.5"], "expectError": "value must be a finite number" },
{ "fn": "linearToSrgb", "name": "null is an error, not black", "args": [null], "expectError": "value must be a finite number" }
]