2021-04-04 11:28:41 -07:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"io/ioutil"
|
2022-01-26 04:09:21 -08:00
|
|
|
|
"oh-my-posh/color"
|
2021-04-04 11:28:41 -07:00
|
|
|
|
"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)
|
2021-04-04 11:28:41 -07:00
|
|
|
|
image := &ImageRenderer{
|
|
|
|
|
ansiString: content,
|
2021-04-20 12:30:46 -07:00
|
|
|
|
ansi: ansi,
|
2021-04-04 11:28:41 -07:00
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-11-08 09:44:06 -08:00
|
|
|
|
prompt := `[38;2;0;55;218;49m[7m\uE0B0[m[0m[48;2;0;55;218m[38;2;255;255;255m oh-my-posh
|
|
|
|
|
[0m[48;2;193;156;0m[38;2;0;55;218m\uE0B0[0m[48;2;193;156;0m[38;2;17;17;17m main ≡ ~4 -8 ?7 [0m[38;2;193;156;0m\uE0B0[0m
|
2021-04-04 11:28:41 -07:00
|
|
|
|
[37m [0m[0m`
|
|
|
|
|
err := runImageTest(prompt)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
}
|