mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-23 12:18:51 +02:00
add tests for TemplateFuncMapAddColors
This commit is contained in:
parent
e8e4fa5957
commit
e58376f9f7
@ -1,7 +1,9 @@
|
|||||||
package style
|
package style
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -157,3 +159,53 @@ func TestMerge(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTemplateFuncMapAddColors(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
name string
|
||||||
|
tmpl string
|
||||||
|
expect string
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
"normal template",
|
||||||
|
"{{ .Foo }}",
|
||||||
|
"bar",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"colored string",
|
||||||
|
"{{ .Foo | red }}",
|
||||||
|
"\x1b[31mbar\x1b[0m",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"string with decorator",
|
||||||
|
"{{ .Foo | bold }}",
|
||||||
|
"\x1b[1mbar\x1b[0m",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"string with color and decorator",
|
||||||
|
"{{ .Foo | bold | red }}",
|
||||||
|
"\x1b[31m\x1b[1mbar\x1b[0m\x1b[0m",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"multiple string with diffrent colors",
|
||||||
|
"{{ .Foo | red }} - {{ .Foo | blue }}",
|
||||||
|
"\x1b[31mbar\x1b[0m - \x1b[34mbar\x1b[0m",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
s := s
|
||||||
|
t.Run(s.name, func(t *testing.T) {
|
||||||
|
tmpl, err := template.New("test template").Funcs(TemplateFuncMapAddColors(template.FuncMap{})).Parse(s.tmpl)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
buff := bytes.NewBuffer(nil)
|
||||||
|
err = tmpl.Execute(buff, struct{ Foo string }{"bar"})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, s.expect, buff.String())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user