File: background_test.go

package info (click to toggle)
golang-github-charmbracelet-x 0.0~git20251028.0cf22f8%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,940 kB
  • sloc: sh: 124; makefile: 5
file content (43 lines) | stat: -rw-r--r-- 1,263 bytes parent folder | download
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
package ansi_test

import (
	"testing"

	"github.com/charmbracelet/x/ansi"
	"github.com/lucasb-eyer/go-colorful"
)

func TestSetForegroundColorNil(t *testing.T) {
	s := ansi.SetForegroundColor("")
	if s != "\x1b]10;\x07" {
		t.Errorf("Unexpected string for SetForegroundColor: got %q", s)
	}
}

func TestStringImplementations(t *testing.T) {
	brightMagenta, ok := colorful.MakeColor(ansi.BrightMagenta)
	if !ok {
		t.Fatalf("Failed to create color for BrightMagenta: %v", ansi.BrightMagenta)
	}
	color255, ok := colorful.MakeColor(ansi.ExtendedColor(255))
	if !ok {
		t.Fatalf("Failed to create color for ExtendedColor(255): %v", ansi.ExtendedColor(255))
	}
	hexColor := ansi.HexColor("#ffeeaa")
	foregroundColor := ansi.SetForegroundColor(brightMagenta.Hex())
	backgroundColor := ansi.SetBackgroundColor(color255.Hex())
	cursorColor := ansi.SetCursorColor(hexColor.Hex())

	if foregroundColor != "\x1b]10;#ff00ff\x07" {
		t.Errorf("Unexpected string for SetForegroundColor: got %q",
			foregroundColor)
	}
	if backgroundColor != "\x1b]11;#eeeeee\x07" {
		t.Errorf("Unexpected string for SetBackgroundColor: got %q",
			backgroundColor)
	}
	if cursorColor != "\x1b]12;#ffeeaa\x07" {
		t.Errorf("Unexpected string for SetCursorColor: got %q",
			cursorColor)
	}
}