MCPcopy Index your code
hub / github.com/cheat/cheat / TestColorize

Function TestColorize

internal/sheet/colorize_test.go:11–42  ·  view source on GitHub ↗

TestColorize asserts that syntax-highlighting is correctly applied

(t *testing.T)

Source from the content-addressed store, hash-verified

9
10// TestColorize asserts that syntax-highlighting is correctly applied
11func TestColorize(t *testing.T) {
12
13 // mock configs
14 conf := config.Config{
15 Formatter: "terminal16m",
16 Style: "solarized-dark",
17 }
18
19 // mock a sheet
20 original := "echo 'foo'"
21 s := Sheet{
22 Text: original,
23 }
24
25 // colorize the sheet text
26 s.Colorize(conf)
27
28 // assert that the text was modified (colorization applied)
29 if s.Text == original {
30 t.Error("Colorize did not modify sheet text")
31 }
32
33 // assert that ANSI escape codes are present
34 if !strings.Contains(s.Text, "\x1b[") && !strings.Contains(s.Text, "[0m") {
35 t.Errorf("colorized text does not contain ANSI escape codes: %q", s.Text)
36 }
37
38 // assert that the original content is still present within the colorized output
39 if !strings.Contains(s.Text, "echo") || !strings.Contains(s.Text, "foo") {
40 t.Errorf("colorized text lost original content: %q", s.Text)
41 }
42}
43
44// TestColorizeDefaultSyntax asserts that when no syntax is specified, the
45// default ("bash") is used and produces the same output as an explicit "bash"

Callers

nothing calls this directly

Calls 1

ColorizeMethod · 0.95

Tested by

no test coverage detected