oh-my-posh/src/engine/image_test.go
2022-08-09 11:19:43 +02:00

64 lines
1.7 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package engine
import (
"io/ioutil" //nolint:staticcheck,nolintlint
"oh-my-posh/color"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
var cases = []struct {
Case string
Config string
}{
{Case: ".omp.json suffix", Config: "~/jandedobbeleer.omp.json"},
{Case: ".omp.yaml suffix", Config: "~/jandedobbeleer.omp.yaml"},
{Case: ".omp.yml suffix", Config: "~/jandedobbeleer.omp.yml"},
{Case: ".omp.toml suffix", Config: "~/jandedobbeleer.omp.toml"},
{Case: ".json suffix", Config: "~/jandedobbeleer.json"},
{Case: ".yaml suffix", Config: "~/jandedobbeleer.yaml"},
{Case: ".yml suffix", Config: "~/jandedobbeleer.yml"},
{Case: ".toml suffix", Config: "~/jandedobbeleer.toml"},
}
func runImageTest(config, content string) (string, error) {
poshImagePath := "jandedobbeleer.png"
file, err := ioutil.TempFile("", poshImagePath)
if err != nil {
return "", err
}
defer os.Remove(file.Name())
ansi := &color.Ansi{}
ansi.InitPlain()
image := &ImageRenderer{
AnsiString: content,
Ansi: ansi,
}
image.Init(config)
err = image.SavePNG()
if err == nil {
os.Remove(image.Path)
}
return filepath.Base(image.Path), err
}
func TestStringImageFileWithText(t *testing.T) {
for _, tc := range cases {
filename, err := runImageTest(tc.Config, "foobar")
assert.Equal(t, "jandedobbeleer.png", filename, tc.Case)
assert.NoError(t, err)
}
}
func TestStringImageFileWithANSI(t *testing.T) {
prompt := ` jan  `
for _, tc := range cases {
filename, err := runImageTest(tc.Config, prompt)
assert.Equal(t, "jandedobbeleer.png", filename, tc.Case)
assert.NoError(t, err)
}
}