1
0
mirror of https://github.com/gizak/termui.git synced 2025-04-27 13:48:51 +08:00
termui/style_parser_test.go
2022-11-07 02:44:37 -08:00

42 lines
833 B
Go

package termui
import (
"strings"
"testing"
)
func TestParseStyles(t *testing.T) {
cells := ParseStyles("test [blue](fg:blue)", NewStyle(ColorWhite))
text := textFromCells(cells)
if text != "test blue" {
t.Fatal("wrong text", text)
}
cells = ParseStyles("[blue](fg:blue) [1]", NewStyle(ColorWhite))
text = textFromCells(cells)
if text != "blue [1]" {
t.Fatal("wrong text", text)
}
cells = ParseStyles("[0]", NewStyle(ColorWhite))
text = textFromCells(cells)
if text != "[0]" {
t.Fatal("wrong text", text)
}
cells = ParseStyles("[", NewStyle(ColorWhite))
text = textFromCells(cells)
if text != "[" {
t.Fatal("wrong text", text)
}
}
func textFromCells(cells []Cell) string {
buff := []string{}
for _, cell := range cells {
buff = append(buff, string(cell.Rune))
}
return strings.Join(buff, "")
}