File size: 1,383 Bytes
5457548
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
package common

import (
	"testing"

	"charm.land/glamour/v2"
	"github.com/charmbracelet/crush/internal/ui/styles"
	"github.com/charmbracelet/x/ansi"
	"github.com/stretchr/testify/require"
)

// TestRenderedInlineCodeHasNoVisibleBackticks guards the display side of the
// inline-code copy fix: codespans render blank padding (a no-break-space
// sentinel), never the backticks themselves. The sentinel is what selection
// copies turn back into backticks (see list.HighlightContent).
func TestRenderedInlineCodeHasNoVisibleBackticks(t *testing.T) {
	t.Parallel()

	sty := styles.CharmtonePantera()

	render := func(t *testing.T, r *glamour.TermRenderer, src string) string {
		t.Helper()
		mu := LockMarkdownRenderer(r)
		mu.Lock()
		defer mu.Unlock()
		rendered, err := r.Render(src)
		require.NoError(t, err)
		return ansi.Strip(rendered)
	}

	for name, r := range map[string]*glamour.TermRenderer{
		"markdown": MarkdownRenderer(&sty, 80),
		"quiet":    QuietMarkdownRenderer(&sty, 80),
	} {
		t.Run(name, func(t *testing.T) {
			t.Parallel()
			actual := render(t, r, `message "this is `+"`code`"+`" ok`)

			require.NotContains(t, actual, "`", "codespan backticks must not render on screen")
			require.Contains(
				t,
				actual,
				`this is `+styles.CodespanPadding+`code`+styles.CodespanPadding+`" ok`,
				"codespan must render with the sentinel padding",
			)
		})
	}
}