-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gradient_test.go
64 lines (57 loc) · 1.56 KB
/
gradient_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) Liam Stanley <me@liamstanley.io>. All rights reserved. Use
// of this source code is governed by the MIT license that can be found in
// the LICENSE file.
package tint
import (
"reflect"
"testing"
"github.com/charmbracelet/lipgloss"
)
func TestFromToHex(t *testing.T) {
type args struct {
from lipgloss.TerminalColor
to lipgloss.TerminalColor
steps int
}
tests := []struct {
name string
args args
wantGradient []string
}{
{
name: "simple-3",
args: args{
from: lipgloss.Color("#000000"),
to: lipgloss.Color("#ffffff"),
steps: 3,
},
wantGradient: []string{"#000000", "#4e4e4e", "#a2a2a2"},
},
{
name: "simple-10",
args: args{
from: lipgloss.Color("#000000"),
to: lipgloss.Color("#ffffff"),
steps: 10,
},
wantGradient: []string{"#000000", "#1b1b1b", "#303030", "#474747", "#5e5e5e", "#777777", "#919191", "#ababab", "#c6c6c6", "#e2e2e2"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotGradient := FromToHex(tt.args.from, tt.args.to, tt.args.steps)
gotGradientColor := FromTo(tt.args.from, tt.args.to, tt.args.steps)
if !reflect.DeepEqual(gotGradient, tt.wantGradient) {
t.Errorf("FromToHex() = %v, want %v", gotGradient, tt.wantGradient)
}
for i := range gotGradient {
c := lipgloss.Color(gotGradient[i])
cr, cg, cb, ca := c.RGBA()
gr, gg, gb, ga := gotGradientColor[i].RGBA()
if cr != gr || cg != gg || cb != gb || ca != ga {
t.Errorf("FromTo() = %v, want %v", gotGradientColor[i], c)
}
}
})
}
}