Skip to content

aandryashin/matchers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Matchers

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, []string{"one", "two", "three"}, Not{Contains{"four"}})
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages