oh-my-posh/src/image_test.go

42 lines
946 B
Go
Raw Normal View History

package main
import (
"io/ioutil"
2022-01-26 04:09:21 -08:00
"oh-my-posh/color"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func runImageTest(content string) error {
poshImagePath := "ohmyposh.png"
file, err := ioutil.TempFile("", poshImagePath)
if err != nil {
return err
}
defer os.Remove(file.Name())
2022-01-26 04:09:21 -08:00
ansi := &color.Ansi{}
ansi.Init(plain)
image := &ImageRenderer{
ansiString: content,
2021-04-20 12:30:46 -07:00
ansi: ansi,
}
image.init()
err = image.SavePNG(poshImagePath)
return err
}
func TestStringImageFileWithText(t *testing.T) {
err := runImageTest("foobar")
assert.NoError(t, err)
}
func TestStringImageFileWithANSI(t *testing.T) {
prompt := `\uE0B0 oh-my-posh
\uE0B0 main ~4 -8 ?7 \uE0B0
 `
err := runImageTest(prompt)
assert.NoError(t, err)
}