match

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package match contains match functions which can be used to create expressions that evaluate to a truth value.

All functions in this package result in a Match type which is simply a function with one generic input and a bool return value. The combination functions Match.And and Match.Or can be used to combine two Match expressions. Not will negate a Match expression.

Example
package main

import (
	"fmt"

	"github.com/becheran/smock/match"
)

func main() {
	fmt.Println(match.Eq("foo").Or(match.Eq("bar"))("foo"))
	fmt.Println(match.Eq(1).Or(match.Eq(2))(3))
	fmt.Println(match.Not(match.Eq(1))(1))
}
Output:

true
false
false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Match

type Match[T any] func(e T) bool

Match is a simple expression which evaluates to be either 'true' or 'false'

func Any

func Any[T any]() Match[T]

Any is the verbose version of 'nil' and will always evaluate to true when passed as expression

func AnyOf

func AnyOf[T comparable](other ...T) Match[T]

EAnyOfq returns a function which will be true if any value of `other` is equal to the input

func DeepEqual

func DeepEqual[T any](other T) Match[T]

DeepEqual returns a function which will be true if `other` is equal to the input using to the reflect.DeepEqual function

func Eq

func Eq[T comparable](other T) Match[T]

Eq returns a function which will be true if `other` is equal to the input

func MapEq

func MapEq[T ~map[K]V, K, V comparable](other T) Match[T]

MapEq returns a function which will be true if `other` contains the same key/value pairs as in the input

func Not

func Not[T any](o Match[T]) Match[T]

Not negates a logical expression

func SliceEq

func SliceEq[T ~[]E, E comparable](other T) Match[T]

Eq returns a function which will be true if all elements of `other` are equal to the input

func (Match[T]) And

func (m Match[T]) And(o Match[T]) Match[T]

And combines two expressions with a logical AND `&&`

func (Match[T]) Or

func (m Match[T]) Or(o Match[T]) Match[T]

Or combines two expressions with a logical OR `||`

Jump to

Keyboard shortcuts

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