is

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package is has a modified superset of the excellent github.com/matryer/is.

It adds new methods commonly needed in Bud, removes indentation and replaces displaying comments with optional messages that can be formatted.

Learn more in this discussion: https://github.com/livebud/bud/discussions/86

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type I

type I struct {
	// contains filtered or unexported fields
}

func New

func New(t T) *I

func (*I) Equal

func (is *I) Equal(a interface{}, b interface{}, args ...interface{})

Equal asserts that a and b are equal.

func Test(t *testing.T) {
	is := is.New(t)
	a := greet("Mat")
	is.Equal(a, "Hi Mat") // greeting
}

Will output:

your_test.go:123: Hey Mat != Hi Mat // greeting

func (*I) Fail

func (is *I) Fail(args ...interface{})

Fail immediately fails the test.

func Test(t *testing.T) {
	is := is.New(t)
	is.Fail() // TODO: write this test
}

func (*I) Helper

func (is *I) Helper()

Helper marks the calling function as a test helper function. When printing file and line information, that function will be skipped.

Available with Go 1.7 and later.

func (*I) In

func (is *I) In(list interface{}, item interface{}, args ...interface{})

In asserts that item is contained within list.

func (*I) New

func (is *I) New(t T) *I

New is a method wrapper around the New function. It allows you to write subtests using a similar pattern:

func Test(t *testing.T) {
	is := is.New(t)
	t.Run("sub", func(t *testing.T) {
		is := is.New(t)
		// TODO: test
	})
}

func (*I) NoErr

func (is *I) NoErr(err error, args ...interface{})

NoErr asserts that err is nil.

func Test(t *testing.T) {
	is := is.New(t)
	val, err := getVal()
	is.NoErr(err)        // getVal error
	is.True(len(val) > 10) // val cannot be short
}

Will output:

your_test.go:123: err: not found // getVal error

func (*I) NotIn

func (is *I) NotIn(list interface{}, item interface{}, args ...interface{})

NotIn asserts that item is not contained within list

func (*I) True

func (is *I) True(expr bool, args ...interface{})

True asserts that the expression is true. The expression code itself will be reported if the assertion fails.

func Test(t *testing.T) {
	is := is.New(t)
	val := method()
	is.True(val != nil) // val should never be nil
}

Will output:

your_test.go:123: not true: val != nil

type T

type T interface {
	FailNow()
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL