@@ -2,6 +2,7 @@ package glamour
22
33import (
44 "bytes"
5+ "errors"
56 "io"
67 "os"
78 "strings"
@@ -43,7 +44,7 @@ func TestTermRendererWriter(t *testing.T) {
4344
4445 // generate
4546 if generate {
46- err := os .WriteFile (testFile , b , 0644 )
47+ err := os .WriteFile (testFile , b , 0o644 )
4748 if err != nil {
4849 t .Fatal (err )
4950 }
@@ -167,6 +168,46 @@ func TestStyles(t *testing.T) {
167168 }
168169}
169170
171+ // TestCustomStyle checks the expected errors with custom styling. We need to
172+ // support built-in styles and custom style sheets.
173+ func TestCustomStyle (t * testing.T ) {
174+ md := "testdata/example.md"
175+ tests := []struct {
176+ name string
177+ stylePath string
178+ err error
179+ expected string
180+ }{
181+ {name : "style exists" , stylePath : "testdata/custom.style" , err : nil , expected : "testdata/custom.style" },
182+ {name : "style doesn't exist" , stylePath : "testdata/notfound.style" , err : os .ErrNotExist , expected : AutoStyle },
183+ {name : "style is empty" , stylePath : "" , err : nil , expected : AutoStyle },
184+ }
185+
186+ for _ , tc := range tests {
187+ t .Run (tc .name , func (t * testing.T ) {
188+ t .Setenv ("GLAMOUR_STYLE" , tc .stylePath )
189+ g , err := NewTermRenderer (
190+ WithEnvironmentConfig (),
191+ )
192+ if ! errors .Is (err , tc .err ) {
193+ t .Fatal (err )
194+ }
195+ if ! errors .Is (tc .err , os .ErrNotExist ) {
196+ w , err := NewTermRenderer (WithStylePath (tc .expected ))
197+ if err != nil {
198+ t .Fatal (err )
199+ }
200+ text , _ := os .ReadFile (md )
201+ want , err := w .RenderBytes (text )
202+ got , err := g .RenderBytes (text )
203+ if ! bytes .Equal (want , got ) {
204+ t .Error ("Wrong style used" )
205+ }
206+ }
207+ })
208+ }
209+ }
210+
170211func TestRenderHelpers (t * testing.T ) {
171212 in , err := os .ReadFile (markdown )
172213 if err != nil {
0 commit comments