File: tty_indexed_test.go

package info (click to toggle)
golang-github-alecthomas-chroma-v2 2.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,788 kB
  • sloc: xml: 41,690; javascript: 459; python: 420; makefile: 51; sh: 37
file content (36 lines) | stat: -rw-r--r-- 867 bytes parent folder | download | duplicates (3)
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
package formatters

import (
	"strings"
	"testing"

	assert "github.com/alecthomas/assert/v2"
	"github.com/alecthomas/chroma/v2"
)

func TestClosestColour(t *testing.T) {
	actual := findClosest(ttyTables[256], chroma.MustParseColour("#e06c75"))
	assert.Equal(t, chroma.MustParseColour("#d75f87"), actual)
}

func TestNoneColour(t *testing.T) {
	formatter := TTY256
	tokenType := chroma.None

	style, err := chroma.NewStyle("test", chroma.StyleEntries{
		chroma.Background: "#D0ab1e",
	})
	assert.NoError(t, err)

	stringBuilder := strings.Builder{}
	err = formatter.Format(&stringBuilder, style, chroma.Literator(chroma.Token{
		Type:  tokenType,
		Value: "WORD",
	}))
	assert.NoError(t, err)

	// "178" = #d7af00 approximates #d0ab1e
	//
	// 178 color ref: https://jonasjacek.github.io/colors/
	assert.Equal(t, "\033[38;5;178mWORD\033[0m", stringBuilder.String())
}