Categorygithub.com/jacobsa/oglematchers
modulepackage
0.0.0-20150720000706-141901ea67cd
Repository: https://github.com/jacobsa/oglematchers.git
Documentation: pkg.go.dev

# README

GoDoc

oglematchers is a package for the Go programming language containing a set of matchers, useful in a testing or mocking framework, inspired by and mostly compatible with Google Test for C++ and Google JS Test. The package is used by the ogletest testing framework and oglemock mocking framework, which may be more directly useful to you, but can be generically used elsewhere as well.

A "matcher" is simply an object with a Matches method defining a set of golang values matched by the matcher, and a Description method describing that set. For example, here are some matchers:

// Numbers
Equals(17.13)
LessThan(19)

// Strings
Equals("taco")
HasSubstr("burrito")
MatchesRegex("t.*o")

// Combining matchers
AnyOf(LessThan(17), GreaterThan(19))

There are lots more; see here for a reference. You can also add your own simply by implementing the oglematchers.Matcher interface.

Installation

First, make sure you have installed Go 1.0.2 or newer. See here for instructions.

Use the following command to install oglematchers and keep it up to date:

go get -u github.com/jacobsa/oglematchers

Documentation

See here for documentation. Alternatively, you can install the package and then use godoc:

godoc github.com/jacobsa/oglematchers

# Functions

AllOf accepts a set of matchers S and returns a matcher that follows the algorithm below when considering a candidate c: 1.
Any returns a matcher that matches any value.
AnyOf accepts a set of values S and returns a matcher that follows the algorithm below when considering a candidate c: 1.
Return a matcher that matches arrays slices with at least one element that matches the supplied argument.
DeepEquals returns a matcher that matches based on 'deep equality', as defined by the reflect package.
Given a list of arguments M, ElementsAre returns a matcher that matches arrays and slices A where all of the following hold: * A is the same length as M.
Equals(x) returns a matcher that matches values v such that v and x are equivalent.
Error returns a matcher that matches non-nil values implementing the built-in error interface for whom the return value of Error() matches the supplied matcher.
GreaterOrEqual returns a matcher that matches integer, floating point, or strings values v such that v >= x.
GreaterThan returns a matcher that matches integer, floating point, or strings values v such that v > x.
HasSameTypeAs returns a matcher that matches values with exactly the same type as the supplied prototype.
HasSubstr returns a matcher that matches strings containing s as a substring.
IdenticalTo(x) returns a matcher that matches values v with type identical to x such that: 1.
LessOrEqual returns a matcher that matches integer, floating point, or strings values v such that v <= x.
LessThan returns a matcher that matches integer, floating point, or strings values v such that v < x.
MatchesRegexp returns a matcher that matches strings and byte slices whose contents match the supplied regular expression.
NewFatalError creates a FatalError struct with the supplied error text.
Create a matcher with the given description and predicate function, which will be invoked to handle calls to Matchers.
Not returns a matcher that inverts the set of values matched by the wrapped matcher.
Panics matches zero-arg functions which, when invoked, panic with an error that matches the supplied matcher.
Return a matcher that matches non-nil pointers whose pointee matches the wrapped matcher.

# Structs

FatalError is an implementation of the error interface that may be returned from matchers, indicating the error should be propagated.

# Interfaces

A Matcher is some predicate implicitly defining a set of values that it matches.