forked from charmbracelet/lipgloss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer_test.go
53 lines (47 loc) · 1.06 KB
/
renderer_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
package lipgloss
import (
"io"
"os"
"testing"
"github.com/muesli/termenv"
)
func TestRendererHasDarkBackground(t *testing.T) {
r1 := NewRenderer(os.Stdout)
r1.SetHasDarkBackground(false)
if r1.HasDarkBackground() {
t.Error("Expected renderer to have light background")
}
r2 := NewRenderer(os.Stdout)
r2.SetHasDarkBackground(true)
if !r2.HasDarkBackground() {
t.Error("Expected renderer to have dark background")
}
}
func TestRendererWithOutput(t *testing.T) {
f, err := os.Create(t.Name())
if err != nil {
t.Fatal(err)
}
defer f.Close()
defer os.Remove(f.Name())
r := NewRenderer(f)
r.SetColorProfile(termenv.TrueColor)
if r.ColorProfile() != termenv.TrueColor {
t.Error("Expected renderer to use true color")
}
}
func TestRace(t *testing.T) {
r := NewRenderer(io.Discard)
o := r.Output()
for i := 0; i < 100; i++ {
t.Run("SetColorProfile", func(t *testing.T) {
t.Parallel()
r.SetHasDarkBackground(false)
r.HasDarkBackground()
r.SetOutput(o)
r.SetColorProfile(termenv.ANSI256)
r.SetHasDarkBackground(true)
r.Output()
})
}
}