代码拉取完成,页面将自动刷新
package color
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNew(t *testing.T) {
is := assert.New(t)
s := New(Red)
is.Equal("31", s.String())
s.Add(OpBold)
is.Equal("31;1", s.String())
s.Add(BgCyan)
is.Equal("31;1;46", s.String())
}
func TestStyle(t *testing.T) {
// force open color render for testing
buf := forceOpenColorRender()
defer resetColorRender()
is := assert.New(t)
// IsEmpty
s := Style{}
is.True(s.IsEmpty())
is.Equal("", s.String())
is.Equal("97;40", Light.Code())
is.Equal("97;40", Light.String())
str := Light.Render("msg")
is.Contains(str, "97")
str = Danger.Sprint("msg")
is.Contains(str, FgRed.String())
str = Question.Render("msg")
is.Contains(str, FgMagenta.String())
str = Question.Render("msg", "More")
is.Contains(str, FgMagenta.String())
is.Contains(str, "msgMore")
str = Question.Renderln("msg", "More")
is.Contains(str, FgMagenta.String())
is.Contains(str, "msg More")
str = Secondary.Sprintf("m%s", "sg")
is.Contains(str, FgDarkGray.String())
// Style.Print
Info.Print("MSG")
is.Equal("\x1b[0;32mMSG\x1b[0m", buf.String())
buf.Reset()
// Style.Printf
Info.Printf("A %s", "MSG")
is.Equal("\x1b[0;32mA MSG\x1b[0m", buf.String())
buf.Reset()
// Style.Println
Info.Println("MSG")
is.Equal("\x1b[0;32mMSG\x1b[0m\n", buf.String())
buf.Reset()
Info.Println("MSG", "OK")
is.Equal("\x1b[0;32mMSG OK\x1b[0m\n", buf.String())
buf.Reset()
s = GetStyle("err")
is.False(s.IsEmpty())
if isLikeInCmd {
s.Print("msg")
s.Printf("M%s", "sg")
s.Println("Msg")
is.Equal("\x1b[97;41mmsg\x1b[0m\x1b[97;41mMsg\x1b[0m\x1b[97;41mMsg\x1b[0m\n", buf.String())
buf.Reset()
}
// add new
s = GetStyle("new0")
is.True(s.IsEmpty())
AddStyle("new0", Style{OpFastBlink})
s = GetStyle("new0")
is.False(s.IsEmpty())
delete(Styles, "new0")
// add new
s = GetStyle("new1")
is.True(s.IsEmpty())
New(OpStrikethrough).Save("new1")
s = GetStyle("new1")
is.False(s.IsEmpty())
delete(Styles, "new1")
}
func TestThemes(t *testing.T) {
// force open color render for testing
buf := forceOpenColorRender()
defer resetColorRender()
is := assert.New(t)
// Theme.Tips
Info.Tips("MSG")
is.Equal("\x1b[0;32mINFO: \x1b[0mMSG\n", buf.String())
buf.Reset()
// Theme.Prompt
Info.Prompt("MSG")
is.Equal("\x1b[0;32mINFO: MSG\x1b[0m\n", buf.String())
buf.Reset()
// Theme.Block
Info.Block("MSG")
is.Equal("\x1b[0;32mINFO:\n MSG\x1b[0m\n", buf.String())
buf.Reset()
theme := GetTheme("info")
is.NotNil(theme)
theme = GetTheme("not-exist")
is.Nil(theme)
// add new
AddTheme("new0", Style{OpFastBlink})
theme = GetTheme("new0")
is.NotNil(theme)
delete(Themes, "new0")
theme = GetTheme("new0")
is.Nil(theme)
// add new
theme = GetTheme("new1")
is.Nil(theme)
theme = NewTheme("new1", Style{OpFastBlink})
theme.Save()
theme = GetTheme("new1")
is.NotNil(theme)
delete(Themes, "new1")
theme = GetTheme("new1")
is.Nil(theme)
}
func TestStyleFunc(t *testing.T) {
// force open color render for testing
buf := forceOpenColorRender()
defer resetColorRender()
Infoln("color message")
assert.Equal(t, "\x1b[0;32mcolor message\x1b[0m\n", buf.String())
buf.Reset()
Infof("color %s", "message")
assert.Equal(t, "\x1b[0;32mcolor message\x1b[0m", buf.String())
buf.Reset()
Warnln("color message")
assert.Equal(t, "\x1b[1;33mcolor message\x1b[0m\n", buf.String())
buf.Reset()
Warnf("color %s", "message")
assert.Equal(t, "\x1b[1;33mcolor message\x1b[0m", buf.String())
buf.Reset()
Errorln("color message")
assert.Equal(t, "\x1b[97;41mcolor message\x1b[0m\n", buf.String())
buf.Reset()
Errorf("color %s", "message")
assert.Equal(t, "\x1b[97;41mcolor message\x1b[0m", buf.String())
buf.Reset()
}
func TestSimplePrinter_Print(t *testing.T) {
sp := &SimplePrinter{}
sp.Printf("simple %s\n", "printer")
sp.Infof("simple %s\n", "printer")
sp.Warnf("simple %s\n", "printer")
sp.Errorf("simple %s\n", "printer")
sp.Print("simple printer\n")
sp.Println("simple printer")
sp.Infoln("simple printer")
sp.Warnln("simple printer")
sp.Errorln("simple printer")
}
func TestNewScheme(t *testing.T) {
cs := NewDefaultScheme("test")
cs.Infof("color %s\n", "scheme")
cs.Warnf("color %s\n", "scheme")
cs.Errorf("color %s\n", "scheme")
cs.Infoln("color scheme")
cs.Warnln("color scheme")
cs.Errorln("color scheme")
cs.Style("info").Println("color scheme")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。