Debian Codegraph @

ansi/background_test.go

raw
1 package ansi_test
2
3 import (
4 "testing"
5
6 "github.com/charmbracelet/x/ansi"
7 "github.com/lucasb-eyer/go-colorful"
8 )
9
10 func TestSetForegroundColorNil(t *testing.T) {
11 s := ansi.SetForegroundColor("")
12 if s != "\x1b]10;\x07" {
13 t.Errorf("Unexpected string for SetForegroundColor: got %q", s)
14 }
15 }
16
17 func TestStringImplementations(t *testing.T) {
18 brightMagenta, ok := colorful.MakeColor(ansi.BrightMagenta)
19 if !ok {
20 t.Fatalf("Failed to create color for BrightMagenta: %v", ansi.BrightMagenta)
21 }
22 color255, ok := colorful.MakeColor(ansi.ExtendedColor(255))
23 if !ok {
24 t.Fatalf("Failed to create color for ExtendedColor(255): %v", ansi.ExtendedColor(255))
25 }
26 hexColor := ansi.HexColor("#ffeeaa")
27 foregroundColor := ansi.SetForegroundColor(brightMagenta.Hex())
28 backgroundColor := ansi.SetBackgroundColor(color255.Hex())
29 cursorColor := ansi.SetCursorColor(hexColor.Hex())
30
31 if foregroundColor != "\x1b]10;#ff00ff\x07" {
32 t.Errorf("Unexpected string for SetForegroundColor: got %q",
33 foregroundColor)
34 }
35 if backgroundColor != "\x1b]11;#eeeeee\x07" {
36 t.Errorf("Unexpected string for SetBackgroundColor: got %q",
37 backgroundColor)
38 }
39 if cursorColor != "\x1b]12;#ffeeaa\x07" {
40 t.Errorf("Unexpected string for SetCursorColor: got %q",
41 cursorColor)
42 }
43 }