forked from JanDeDobbeleer/oh-my-posh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansi_color_test.go
167 lines (148 loc) · 4.54 KB
/
ansi_color_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
163
164
165
166
167
package main
import (
"testing"
"github.com/gookit/color"
"github.com/stretchr/testify/assert"
)
const (
inputText = "This is white, <#ff5733>this is orange</>, white again"
)
func TestWriteAndRemoveText(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
text := renderer.writeAndRemoveText("#193549", "#fff", "This is white, ", "This is white, ", inputText)
assert.Equal(t, "<#ff5733>this is orange</>, white again", text)
assert.NotContains(t, renderer.string(), "<#ff5733>")
}
func TestWriteAndRemoveTextColored(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
text := renderer.writeAndRemoveText("#193549", "#ff5733", "this is orange", "<#ff5733>this is orange</>", inputText)
assert.Equal(t, "This is white, , white again", text)
assert.NotContains(t, renderer.string(), "<#ff5733>")
}
func TestWriteColorOverride(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
renderer.write("#193549", "#ff5733", inputText)
assert.NotContains(t, renderer.string(), "<#ff5733>")
}
func TestWriteColorOverrideBackground(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
text := "This is white, <,#000000>this is black</>, white again"
renderer.write("#193549", "#ff5733", text)
assert.NotContains(t, renderer.string(), "000000")
}
func TestWriteColorOverrideBackground16(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
text := "This is default <,white> this background is changed</> default again"
renderer.write("#193549", "#ff5733", text)
assert.NotContains(t, renderer.string(), "white")
assert.NotContains(t, renderer.string(), "</>")
assert.NotContains(t, renderer.string(), "<,")
}
func TestWriteColorOverrideBoth(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
text := "This is white, <#000000,#ffffff>this is black</>, white again"
renderer.write("#193549", "#ff5733", text)
assert.NotContains(t, renderer.string(), "ffffff")
assert.NotContains(t, renderer.string(), "000000")
}
func TestWriteColorOverrideBoth16(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
text := "This is white, <black,white>this is black</>, white again"
renderer.write("#193549", "#ff5733", text)
assert.NotContains(t, renderer.string(), "<black,white>")
assert.NotContains(t, renderer.string(), "</>")
}
func TestWriteColorOverrideDouble(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
text := "<#ffffff>jan</>@<#ffffff>Jans-MBP</>"
renderer.write("#193549", "#ff5733", text)
assert.NotContains(t, renderer.string(), "<#ffffff>")
assert.NotContains(t, renderer.string(), "</>")
}
func TestWriteColorTransparent(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
text := "This is white"
renderer.writeColoredText("#193549", Transparent, text)
t.Log(renderer.string())
}
func TestWriteColorName(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
text := "This is white, <red>this is red</>, white again"
renderer.write("#193549", "red", text)
assert.NotContains(t, renderer.string(), "<red>")
}
func TestWriteColorInvalid(t *testing.T) {
ansi := &ansiUtils{}
ansi.init("pwsh")
renderer := &AnsiColor{
ansi: ansi,
}
text := "This is white, <invalid>this is orange</>, white again"
renderer.write("#193549", "invalid", text)
assert.Contains(t, renderer.string(), "<invalid>")
}
func TestGetAnsiFromColorStringBg(t *testing.T) {
renderer := &AnsiColor{}
colorCode := renderer.getAnsiFromColorString("blue", true)
assert.Equal(t, color.BgBlue.String(), colorCode)
}
func TestGetAnsiFromColorStringFg(t *testing.T) {
renderer := &AnsiColor{}
colorCode := renderer.getAnsiFromColorString("red", false)
assert.Equal(t, color.FgRed.String(), colorCode)
}
func TestGetAnsiFromColorStringHex(t *testing.T) {
renderer := &AnsiColor{}
colorCode := renderer.getAnsiFromColorString("#AABBCC", false)
assert.Equal(t, color.HEX("#AABBCC").String(), colorCode)
}
func TestGetAnsiFromColorStringInvalidFg(t *testing.T) {
renderer := &AnsiColor{}
colorCode := renderer.getAnsiFromColorString("invalid", false)
assert.Equal(t, "", colorCode)
}
func TestGetAnsiFromColorStringInvalidBg(t *testing.T) {
renderer := &AnsiColor{}
colorCode := renderer.getAnsiFromColorString("invalid", true)
assert.Equal(t, "", colorCode)
}