package module
v3.1.1 Latest Latest

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

Go to latest
Published: Oct 9, 2022 License: MIT Imports: 7 Imported by: 0


Just some random matchers

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

The package provides a matcher interface to match a given value of any types.


  • Go >= 1.18


go get


You could use it in a test or anywhere that needs a value matcher.

package mypackage

import (


func TestValue(t *testing.T) {
	m := matcher.Equal("foobar")
	actual := "FOOBAR"

	result, err := m.Match(actual)

	assert.True(t, result, "got: %s, want: %s", actual, m.Expected())
	assert.NoError(t, err)


If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation


       or scan this



Package matcher provides value matchers.



This section is empty.


View Source
var Any = Func("is anything", func(actual any) (bool, error) {
	return true, nil

Any returns a matcher that matches any value.


This section is empty.


type Callback

type Callback func() Matcher

Callback matches by calling a function.

func (Callback) Expected

func (m Callback) Expected() string

Expected returns the expectation.

func (Callback) Match

func (m Callback) Match(actual any) (bool, error)

Match determines if the actual is expected.

func (Callback) Matcher

func (m Callback) Matcher() Matcher

Matcher returns the matcher.

type Matcher

type Matcher interface {
	Match(actual any) (bool, error)
	Expected() string

Matcher determines if the actual matches the expectation.

func Equal

func Equal(expected any) Matcher

Equal matches two objects.

func Equalf

func Equalf(expected string, args ...any) Matcher

Equalf matches two strings by the formatted expectation.

func Func

func Func(expected string, match func(actual any) (bool, error)) Matcher

Func matches by calling a function.

func IsEmpty

func IsEmpty() Matcher

IsEmpty checks whether the value is empty.

func IsNotEmpty

func IsNotEmpty() Matcher

IsNotEmpty checks whether the value is not empty.

func IsType

func IsType[T any]() Matcher

IsType matches two types.

func JSON

func JSON(expected any) Matcher

JSON matches two json strings with <ignore-diff> support.

func Len

func Len[T ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](expected T) Matcher

Len matches by the length of the value.

func Match

func Match(v any) Matcher

Match returns a matcher according to its type.

func Regex

func Regex[T ~string | *regexp.Regexp | regexp.Regexp](regexp T) Matcher

Regex matches two strings by using regex.

func SameTypeAs

func SameTypeAs(expected any) Matcher

SameTypeAs matches two types.


Path Synopsis
Package mock provides functionalities for mocking matchers.
Package mock provides functionalities for mocking matchers.

Jump to

Keyboard shortcuts

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