mirror of
https://github.com/manifoldco/promptui.git
synced 2026-03-14 14:25:53 +01:00
30 lines
791 B
Go
30 lines
791 B
Go
package promptui
|
|
|
|
import "testing"
|
|
|
|
func TestStyler(t *testing.T) {
|
|
t.Run("renders a single code", func(t *testing.T) {
|
|
red := Styler(FGRed)("hi")
|
|
expected := "\033[31mhi\033[0m"
|
|
if red != expected {
|
|
t.Errorf("style did not match: %s != %s", red, expected)
|
|
}
|
|
})
|
|
|
|
t.Run("combines multiple codes", func(t *testing.T) {
|
|
boldRed := Styler(FGRed, FGBold)("hi")
|
|
expected := "\033[31;1mhi\033[0m"
|
|
if boldRed != expected {
|
|
t.Errorf("style did not match: %s != %s", boldRed, expected)
|
|
}
|
|
})
|
|
|
|
t.Run("should not repeat reset codes for nested styles", func(t *testing.T) {
|
|
red := Styler(FGRed)("hi")
|
|
boldRed := Styler(FGBold)(red)
|
|
expected := "\033[1m\033[31mhi\033[0m"
|
|
if boldRed != expected {
|
|
t.Errorf("style did not match: %s != %s", boldRed, expected)
|
|
}
|
|
})
|
|
}
|