Пример #1
0
// New a terminal color render,
func New(codes ...string) *Renderer {
	return &Renderer{
		enable:   true,
		settings: ansi.Begin(codes...),
		end:      ansi.End(),
	}
}
Пример #2
0
func indexErrorInfo(t testing.TB, skip int, index string, expect, got interface{}, withType bool) {
	var (
		pos        = runtime2.Caller(skip + 1)
		exps, gots string
	)

	const formatT = "%+v(%T)"
	const format = "%+v"

	if !output.IsTTY {
		if withType {
			exps = fmt.Sprintf(formatT, expect, expect)
			gots = fmt.Sprintf(formatT, got, got)
		} else {
			exps = fmt.Sprintf(format, expect)
			gots = fmt.Sprintf(format, got)
		}
	} else {
		var red = ansi.Begin(ansi.Highlight, ansi.FgRed)
		var green = ansi.Begin(ansi.Highlight, ansi.FgGreen)
		var end = ansi.End()

		pos = ansi.Render(pos, ansi.Highlight, ansi.FgBlue)
		if withType {
			exps = fmt.Sprintf(green+formatT+end, expect, expect)
			gots = fmt.Sprintf(red+formatT+end, got, got)
		} else {
			exps = fmt.Sprintf(green+format+end, expect)
			gots = fmt.Sprintf(red+format+end, got)
		}
	}
	if index != "" {
		if output.IsTTY {
			index = ansi.Render(index, ansi.Highlight, ansi.FgYellow)
		}

		pos += ": " + index
	}

	t.Errorf("%s: expect: %s, got: %s", pos, exps, gots)
}