-
Notifications
You must be signed in to change notification settings - Fork 31
/
decoration_test.go
162 lines (141 loc) · 3.52 KB
/
decoration_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.
package gowid
import (
"testing"
tcell "github.com/gdamore/tcell/v2"
"github.com/go-test/deep"
"github.com/stretchr/testify/assert"
)
func TestColor1(t *testing.T) {
IgnoreBase16 = true
c, _ := MakeRGBColorExtSafe(0, 0, 0)
i2a, _ := c.ToTCellColor(Mode256Colors)
i2 := i2a.ToTCell()
// See https://jonasjacek.github.io/colors/ - we are skipping
// colors 0-21 inclusive
if i2 != tcell.Color232 {
t.Errorf("Failed")
}
}
func TestColor1b(t *testing.T) {
IgnoreBase16 = false
c, _ := MakeRGBColorExtSafe(0, 0, 0)
i2a, _ := c.ToTCellColor(Mode256Colors)
i2 := i2a.ToTCell()
if i2 != tcell.ColorValid {
t.Errorf("Failed")
}
}
func TestColor2(t *testing.T) {
c := NewUrwidColor("dark red")
i2a, _ := c.ToTCellColor(Mode256Colors)
i2 := i2a.ToTCell()
if i2 != tcell.ColorMaroon {
t.Errorf("Failed")
}
}
func TestColor3(t *testing.T) {
c := MakeGrayColor("g#ff")
if c.Val != 255 {
t.Errorf("Failed")
}
}
func TestColor4(t *testing.T) {
c := MakeGrayColor("g99")
if c.Val != 99 {
t.Errorf("Failed")
}
}
func TestColor5(t *testing.T) {
c := MakeGrayColor("g100")
if c.Val != 100 {
t.Errorf("Failed")
}
if v, _ := c.ToTCellColor(Mode256Colors); v.ToTCell() != tcell.Color232 {
t.Errorf("Failed")
}
}
func TestColor6(t *testing.T) {
c := MakeGrayColor("g3")
if c.Val != 3 {
t.Errorf("Failed")
}
if v, _ := c.ToTCellColor(Mode256Colors); v.ToTCell() != tcell.Color233 {
t.Errorf("Failed")
}
}
func TestColor7(t *testing.T) {
c := MakeGrayColor("g0")
if c.Val != 0 {
t.Errorf("Failed")
}
if v, _ := c.ToTCellColor(Mode256Colors); v.ToTCell() != tcell.Color17 {
t.Errorf("Failed")
}
}
func TestColorLookup1(t *testing.T) {
res := makeColorLookup([]int{0, 7, 9}, 10)
if deep.Equal(res, []int{0, 0, 0, 0, 1, 1, 1, 1, 1, 2}) != nil {
t.Errorf("Failed")
}
}
func TestIntScale1(t *testing.T) {
if intScale(0x7, 0x10, 0x10000) != 0x7777 {
t.Errorf("Failed val was %d", intScale(0x7, 0x10, 0x10000))
}
if intScale(0x5f, 0x100, 0x10) != 6 {
t.Errorf("Failed val was %d", intScale(0x5f, 0x100, 0x10))
}
if intScale(2, 6, 101) != 40 {
t.Errorf("Failed")
}
if intScale(1, 3, 4) != 2 {
t.Errorf("Failed")
}
}
func TestStringColor1(t *testing.T) {
col1, _ := MakeRGBColorSafe("#12f")
col2, _ := MakeRGBColorExtSafe(1*16, 2*16, 15*16)
if deep.Equal(col1, col2) != nil {
t.Errorf("Failed")
}
}
func TestStringColor2(t *testing.T) {
col1, _ := MakeRGBColorSafe("#12fgogogog")
col2, _ := MakeRGBColorExtSafe(1*16, 2*16, 15*16)
if deep.Equal(col1, col2) == nil {
t.Errorf("Failed")
}
}
func TestStringColor3(t *testing.T) {
_, err := MakeRGBColorSafe("#34g")
if err == nil {
t.Errorf("Failed")
}
}
func TestGray881(t *testing.T) {
c := MakeGrayColor("g100")
v, _ := c.ToTCellColor(Mode88Colors)
assert.Equal(t, v.ToTCell(), tcell.Color80)
}
func TestDefault1(t *testing.T) {
c, _ := MakeColorSafe("default")
v, _ := c.ToTCellColor(Mode256Colors)
assert.Equal(t, v.ToTCell(), tcell.ColorDefault)
}
func TestTCell1(t *testing.T) {
c, _ := MakeColorSafe("maroon")
v, _ := c.ToTCellColor(Mode256Colors)
assert.Equal(t, v.ToTCell(), tcell.ColorMaroon)
}
func TestTCell2(t *testing.T) {
c := MakeTCellColorExt(tcell.ColorMaroon)
v, _ := c.ToTCellColor(Mode256Colors)
assert.Equal(t, v.ToTCell(), tcell.ColorMaroon)
}
//======================================================================
// Local Variables:
// mode: Go
// fill-column: 110
// End: