Skip to content

Commit

Permalink
Add custom matcher sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
aandryashin committed Apr 10, 2016
1 parent 64a16d2 commit 8a0f8e9
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Matchers

**Matchers** is simple package to allow go programmers write java like tests.
**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).

```go
package main
Expand All @@ -19,3 +19,38 @@ func TestSample(t *testing.T) {
AssertThat(t, Expect{true, Not{true}}, Fails{})
}
```

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

```go
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"}})
}
```

0 comments on commit 8a0f8e9

Please sign in to comment.