matchers

package module
v0.0.0-...-435295e Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2016 License: Apache-2.0 Imports: 5 Imported by: 0

README

Matchers

Build Status Coverage

Matchers is simple package to allow go programmers write java like tests. It is compatible with go test, self described and self tested (see matchers_test.go).

package main

import (
        "testing"

        . "github.com/aandryashin/matchers"
)

func TestSample(t *testing.T) {
        // Assertion
        AssertThat(t, true, Is{true})

        // Expectation
        AssertThat(t, Expect{true, Not{true}}, Fails{})
}

It is easy to implement your own custom matcher and combine it with others.

package main

import (
        "fmt"
        "testing"

        . "github.com/aandryashin/matchers"
)

type Contains struct {
        S string
}

func (m Contains) Match(i interface{}) bool {
        for _, v := range i.([]string) {
                if v == m.S {
                        return true
                }
        }
        return false
}

func (m Contains) String() string {
        return fmt.Sprintf("contains %v", m.S)
}

func TestContains(t *testing.T) {
        AssertThat(t, []string{"one", "two", "three"}, Contains{"two"})
        AssertThat(t, Expect{[]string{"one", "two", "three"}, Contains{"four"}}, Fails{})
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertThat

func AssertThat(t Mortal, i interface{}, m Matcher)

Types

type AllOf

type AllOf []Matcher

func (AllOf) Match

func (all AllOf) Match(v interface{}) bool

func (AllOf) String

func (all AllOf) String() string

type AnyOf

type AnyOf []Matcher

func (AnyOf) Match

func (any AnyOf) Match(v interface{}) bool

func (AnyOf) String

func (any AnyOf) String() string

type Contains

type Contains []interface{}

func (Contains) Match

func (self Contains) Match(vs interface{}) bool

func (Contains) String

func (self Contains) String() string

type ElementsAre

type ElementsAre []interface{}

func (ElementsAre) Match

func (self ElementsAre) Match(vs interface{}) bool

func (ElementsAre) String

func (self ElementsAre) String() string

type EqualTo

type EqualTo struct {
	V interface{}
}

func (EqualTo) Match

func (m EqualTo) Match(i interface{}) bool

func (EqualTo) String

func (m EqualTo) String() string

type Expect

type Expect struct {
	I interface{}
	M Matcher
}

func (Expect) Confirm

func (e Expect) Confirm() (err error)

func (Expect) String

func (m Expect) String() string

type Fails

type Fails struct {
}

func (Fails) Match

func (m Fails) Match(i interface{}) bool

func (Fails) String

func (m Fails) String() string

type Is

type Is struct {
	V interface{}
}

func (Is) Match

func (m Is) Match(i interface{}) bool

func (Is) String

func (m Is) String() string

type Matcher

type Matcher interface {
	Match(interface{}) bool
	String() string
}

type Mortal

type Mortal interface {
	Fatal(args ...interface{})
}

type Not

type Not struct {
	V interface{}
}

func (Not) Match

func (m Not) Match(i interface{}) bool

func (Not) String

func (m Not) String() string

type Protect

type Protect struct {
	*testing.T
}

func (Protect) Fatal

func (t Protect) Fatal(args ...interface{})

type TypeOf

type TypeOf struct {
	V interface{}
}

func (TypeOf) Match

func (m TypeOf) Match(i interface{}) bool

func (TypeOf) String

func (m TypeOf) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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