Upstream gookit/color state of the touched files before 4eed092414
This commit is contained in:
1 parent
caf059eba7
commit
9df61ac4fe
2 files changed
+1
-12
No files matched your search
+1
-3
@@ -483,9 +483,7 @@ func RgbToHex(rgb []int) string {
|
||||
hexNodes := make([]string, 0, len(rgb))
|
||||
|
||||
for _, v := range rgb {
|
||||
// Channels below 0x10 must keep two digits, or the fixed-width format and
|
||||
// the round-trip with HexToRgb both break.
|
||||
hexNodes = append(hexNodes, fmt.Sprintf("%02x", v))
|
||||
hexNodes = append(hexNodes, strconv.FormatInt(int64(v), 16))
|
||||
}
|
||||
return strings.Join(hexNodes, "")
|
||||
}
|
||||
|
||||
@@ -119,21 +119,12 @@ func TestRgbToHex(t *testing.T) {
|
||||
{"cccccc", []int{204, 204, 204}},
|
||||
{"aabbcc", []int{170, 187, 204}},
|
||||
{"aa99cd", []int{170, 153, 205}},
|
||||
// channels below 0x10 must be zero-padded to two hex digits
|
||||
{"000000", []int{0, 0, 0}},
|
||||
{"010203", []int{1, 2, 3}},
|
||||
{"0a0b0c", []int{10, 11, 12}},
|
||||
}
|
||||
|
||||
for _, item := range tests {
|
||||
assert.Equal(t, RgbToHex(item.given), item.want)
|
||||
assert.Equal(t, Rgb2hex(item.given), item.want)
|
||||
}
|
||||
|
||||
// RgbToHex must be the inverse of HexToRgb, including for small channels.
|
||||
for _, hex := range []string{"010203", "000000", "0a0b0c", "aabbcc"} {
|
||||
assert.Equal(t, RgbToHex(HexToRgb(hex)), hex)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRgbToAnsi(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user