String

func String(expected string) TestDeep

String operator allows to compare a string (or convertible), []byte (or convertible), error or fmt.Stringer interface (error interface is tested before fmt.Stringer).

err := errors.New("error!")
td.Cmp(t, err, td.String("error!")) // succeeds

bstr := bytes.NewBufferString("fmt.Stringer!")
td.Cmp(t, bstr, td.String("fmt.Stringer!")) // succeeds

See also String godoc.

Examples

Base example
Stringer example
Error example

CmpString shortcut

func CmpString(t TestingT, got interface{}, expected string, args ...interface{}) bool

CmpString is a shortcut for:

td.Cmp(t, got, td.String(expected), args...)

See above for details.

Returns true if the test is OK, false if it fails.

args… are optional and allow to name the test. This name is used in case of failure to qualify the test. If len(args) > 1 and the first item of args is a string and contains a ‘%’ rune then fmt.Fprintf is used to compose the name, else args are passed to fmt.Fprint. Do not forget it is the name of the test, not the reason of a potential failure.

See also CmpString godoc.

Examples

Base example
Stringer example
Error example

T.String shortcut

func (t *T) String(got interface{}, expected string, args ...interface{}) bool

String is a shortcut for:

t.Cmp(got, td.String(expected), args...)

See above for details.

Returns true if the test is OK, false if it fails.

args… are optional and allow to name the test. This name is used in case of failure to qualify the test. If len(args) > 1 and the first item of args is a string and contains a ‘%’ rune then fmt.Fprintf is used to compose the name, else args are passed to fmt.Fprint. Do not forget it is the name of the test, not the reason of a potential failure.

See also T.String godoc.

Examples

Base example
Stringer example
Error example