matcher

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: MIT Imports: 7 Imported by: 1

README

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.

Prerequisites

  • Go >= 1.16

Install

go get github.com/nhatthm/go-matcher

Usage

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

package mypackage

import (
	"testing"

	"github.com/nhatthm/go-matcher"
	"github.com/stretchr/testify/assert"
)

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

	assert.True(t, m.Match(actual), "got: %s, want: %s", actual, m.Expected())
}

Donation

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

Paypal donation

paypal

       or scan this

Documentation

Overview

Package matcher provides value matchers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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 interface{}) (bool, error)

Match determines if the actual is expected.

func (Callback) Matcher

func (m Callback) Matcher() Matcher

Matcher returns the matcher.

type EmptyMatcher added in v1.1.0

type EmptyMatcher struct{}

EmptyMatcher checks whether the value is empty.

func IsEmpty added in v1.1.0

func IsEmpty() EmptyMatcher

IsEmpty checks whether the value is empty.

func (EmptyMatcher) Expected added in v1.1.0

func (EmptyMatcher) Expected() string

Expected returns the expectation.

func (EmptyMatcher) Match added in v1.1.0

func (EmptyMatcher) Match(actual interface{}) (bool, error)

Match determines if the actual is expected.

type ExactMatcher

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

ExactMatcher matches by exact string.

func Exact

func Exact(expected interface{}) ExactMatcher

Exact matches two objects by their exact values.

func Exactf

func Exactf(expected string, args ...interface{}) ExactMatcher

Exactf matches two strings by the formatted expectation.

func (ExactMatcher) Expected

func (m ExactMatcher) Expected() string

Expected returns the expectation.

func (ExactMatcher) Match

func (m ExactMatcher) Match(actual interface{}) (bool, error)

Match determines if the actual is expected.

type JSONMatcher

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

JSONMatcher matches by json with <ignore-diff> support.

func JSON

func JSON(expected interface{}) JSONMatcher

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

func (JSONMatcher) Expected

func (m JSONMatcher) Expected() string

Expected returns the expectation.

func (JSONMatcher) Match

func (m JSONMatcher) Match(actual interface{}) (bool, error)

Match determines if the actual is expected.

type LenMatcher added in v1.2.0

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

LenMatcher matches by the length of the value.

func Len added in v1.2.0

func Len(expected int) LenMatcher

Len matches by the length of the value.

func (LenMatcher) Expected added in v1.2.0

func (m LenMatcher) Expected() string

Expected returns the expectation.

func (LenMatcher) Match added in v1.2.0

func (m LenMatcher) Match(actual interface{}) (_ bool, err error)

Match determines if the actual is expected.

type Matcher

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

Matcher determines if the actual matches the expectation.

func Match

func Match(v interface{}) Matcher

Match returns a matcher according to its type.

type NotEmptyMatcher added in v1.1.0

type NotEmptyMatcher struct{}

NotEmptyMatcher checks whether the value is not empty.

func IsNotEmpty added in v1.1.0

func IsNotEmpty() NotEmptyMatcher

IsNotEmpty checks whether the value is not empty.

func (NotEmptyMatcher) Expected added in v1.1.0

func (NotEmptyMatcher) Expected() string

Expected returns the expectation.

func (NotEmptyMatcher) Match added in v1.1.0

func (NotEmptyMatcher) Match(actual interface{}) (bool, error)

Match determines if the actual is expected.

type RegexMatcher

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

RegexMatcher matches by regex.

func Regex

func Regex(regexp *regexp.Regexp) RegexMatcher

Regex matches two strings by using regex.

func RegexPattern

func RegexPattern(pattern string) RegexMatcher

RegexPattern matches two strings by using regex.

func (RegexMatcher) Expected

func (m RegexMatcher) Expected() string

Expected returns the expectation.

func (RegexMatcher) Match

func (m RegexMatcher) Match(actual interface{}) (bool, error)

Match determines if the actual is expected.

Jump to

Keyboard shortcuts

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