You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit is focused on PR feedback around codeblock testing and simplifying related code:
1. Use of new `WithOptions(...TermRendererOption) TermRendererOption` to clean up `WithTheme()`
The `glamour` TermRendererOption pattern has a limitation that users cannot compose multiple options without duplicating code or building one-off anonymous functions.
However, this commit takes advantage of an enhancement in cli/glamour#3 that allows users to leverage a helper to avoid building one-offs.
1. Use of new `leaanthony/go-ansi-parser` dependency for parsing ANSI escape sequences and display attributes
In v1 of `markdown_test.go`, the codeblock tests were very simple, testing the result of output of markdown rendering against a string of ANSI escape sequences. The concern raised is that this was testing the result rather than behavior wanted.
In v2 of `markdown_test.go`, the codeblock tests were refactored to use regex to extract and analyze ANSI escape sequences and display attributes. The concern raised was that this was a lot of logic to build and maintain and might benefit from a dependency that could do it.
In v3 of `markdown_test.go`, a combination of v1 and v2 approaches for 1) testing that theme appropriate colors are used and 2) testing that ensures accessible display options are used when accessible experience is enabled
Copy file name to clipboardexpand all lines: pkg/markdown/markdown_test.go
+48-78
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,13 @@ import (
4
4
"fmt"
5
5
"os"
6
6
"path/filepath"
7
-
"regexp"
8
-
"strconv"
9
7
"strings"
10
8
"testing"
11
9
12
10
"github.com/MakeNowJust/heredoc"
11
+
"github.com/alecthomas/chroma/v2/styles"
13
12
"github.com/cli/go-gh/v2/pkg/accessibility"
13
+
ansi "github.com/leaanthony/go-ansi-parser"
14
14
"github.com/stretchr/testify/assert"
15
15
"github.com/stretchr/testify/require"
16
16
)
@@ -22,25 +22,11 @@ const (
22
22
customH2_8bitColorSeq="\x1b[38;5;61;"
23
23
magenta_4bitColorSeq="\x1b[35;"
24
24
brightMagenta_4bitColorSeq="\x1b[95;"
25
-
26
-
// TODO: Include a little more context on SGR including link to https://en.wikipedia.org/wiki/ANSI_escape_code#Select_Graphic_Rendition_parameters for more info
require.NotEmpty(t, sequences, "Failed to find expected SGR sequences in rendered output")
97
-
98
-
// TODO: Review use of a module like https://github.com/leaanthony/go-ansi-parser/blob/main/ansi.go#L264 to do the sequence and attribute parsing such that we just have to iterate over the results
0 commit comments