The last one fails -- it returns 0xFF4 instead of 0xFF000004.
The code seems to be unclear about its assumptions. If a Hex Color Code should always be 6 or 8 characters, then the function should either assert that, or check that.
I'm guessing that you supply an FF opacity when no alpha is provided. That's fine, but then presumably any value less than 6 digits should be treated as having preceding zeros.
@awhitford
The PR is closed and every unit test looks good. Your improvements a legit and I think we can use it like this. Will release a new version with this and the other fixes next week.
hexToInt
https://github.com/Ephenodrom/Dart-Basic-Utils/blob/3b53270fc71b9d94386a0a5d7240c4a59b80665e/lib/src/ColorUtils.dart#L13-L26
What do you think should happen with these test cases?
The last one fails -- it returns 0xFF4 instead of 0xFF000004.
The code seems to be unclear about its assumptions. If a Hex Color Code should always be 6 or 8 characters, then the function should either
assert
that, orcheck
that.I'm guessing that you supply an FF opacity when no alpha is provided. That's fine, but then presumably any value less than 6 digits should be treated as having preceding zeros.
intToHex
https://github.com/Ephenodrom/Dart-Basic-Utils/blob/3b53270fc71b9d94386a0a5d7240c4a59b80665e/lib/src/ColorUtils.dart#L28-L38
What do you think should happen with these test cases?
The last one fails -- it returns "#FC" instead of "#0000FC".
The
intToHex
function is stripping the alpha/opacity, so aAARRGGBB
hex code will turn into#RRGGBB
.Generally, one would assume that
i == hexToInt(intToHex(i))
, but if there is a non FF alpha value, then that is not true.