Documentation
¶
Index ¶
- func Join[T any](a []T, sep string) string
- type AssertionMessage
- func Assert(isSuccessful bool, str string, args ...any) AssertionMessage
- func Error(err error) AssertionMessage
- func ErrorAs[T any](err error, target *T) AssertionMessage
- func ErrorIs(err error, target error) AssertionMessage
- func False(actual bool) AssertionMessage
- func Match[T any](actual T, matcher Matcher[T]) AssertionMessage
- func Nil(actual any) AssertionMessage
- func NilError(err error) AssertionMessage
- func NotNil(actual any) AssertionMessage
- func True(actual bool) AssertionMessage
- type Floaty
- type Flt
- type Hammy
- type Mappy
- func (m Mappy[K, V]) EqualTo(expected map[K]V) AssertionMessage
- func (m Mappy[K, V]) HasEntry(keyMatcher Matcher[K], valueMatcher Matcher[V]) AssertionMessage
- func (m Mappy[K, V]) HasKey(key K) AssertionMessage
- func (m Mappy[K, V]) HasKeyMatching(matcher Matcher[K]) AssertionMessage
- func (m Mappy[K, V]) HasValueMatching(matcher Matcher[V]) AssertionMessage
- func (m Mappy[K, V]) IsEmpty() AssertionMessage
- func (m Mappy[K, V]) KeysExactly(expected ...K) AssertionMessage
- func (m Mappy[K, V]) Len(expected int) AssertionMessage
- func (m Mappy[K, V]) Matches(matcher Matcher[map[K]V]) AssertionMessage
- func (m Mappy[K, V]) NotContains(values ...V) AssertionMessage
- func (m Mappy[K, V]) NotEmpty() AssertionMessage
- func (m Mappy[K, V]) NotHasKey(key K) AssertionMessage
- func (m Mappy[K, V]) WithItem(k K, expected V) AssertionMessage
- func (m Mappy[K, V]) WithKeys(expected ...K) AssertionMessage
- func (m Mappy[K, V]) WithValues(values ...V) AssertionMessage
- func (m Mappy[K, V]) WithoutKeys(keys ...K) AssertionMessage
- type Matcher
- func AllOf[T any](matchers ...Matcher[T]) Matcher[T]
- func AnyOf[T any](matchers ...Matcher[T]) Matcher[T]
- func AssignableTo[T any]() Matcher[any]
- func CloseTo[F Floaty](expected, delta F) Matcher[F]
- func Contains(expected string) Matcher[string]
- func ContainsInAnyOrder[T any](matchers ...Matcher[T]) Matcher[[]T]
- func ContainsInOrder[T any](matchers ...Matcher[T]) Matcher[[]T]
- func Describe[T any](msg string, matcher Matcher[T]) Matcher[T]
- func EmptyString() Matcher[string]
- func EqualIgnoringCase(expected string) Matcher[string]
- func EqualIgnoringWhitespace(expected string) Matcher[string]
- func EqualNormalizedWhitespace(expected string) Matcher[string]
- func EqualTo[T any](expected T) Matcher[T]
- func Every[T any](matcher Matcher[T]) Matcher[[]T]
- func GreaterOrEqual[N Numeric](expected N) Matcher[N]
- func GreaterThan[N Numeric](expected N) Matcher[N]
- func HasEntry[K comparable, V any](keyMatcher Matcher[K], valueMatcher Matcher[V]) Matcher[map[K]V]
- func HasItem[T any](matcher Matcher[T]) Matcher[[]T]
- func HasKeyMatching[K comparable, V any](matcher Matcher[K]) Matcher[map[K]V]
- func HasPrefix(expected string) Matcher[string]
- func HasPrefixIgnoringCase(expected string) Matcher[string]
- func HasSuffix(expected string) Matcher[string]
- func HasSuffixIgnoringCase(expected string) Matcher[string]
- func HasValueMatching[K comparable, V any](matcher Matcher[V]) Matcher[map[K]V]
- func Having[T, U any](selector func(T) U, matcher Matcher[U]) Matcher[T]
- func HavingField[T, U any](name string, selector func(T) U, matcher Matcher[U]) Matcher[T]
- func IsInf[F Floaty]() Matcher[F]
- func IsInfSign[F Floaty](sign int) Matcher[F]
- func IsNaN[F Floaty]() Matcher[F]
- func LessOrEqual[N Numeric](expected N) Matcher[N]
- func LessThan[N Numeric](expected N) Matcher[N]
- func MatchFunc[T any](fn func(actual T) AssertionMessage) Matcher[T]
- func MatchesRegexp(pattern string) Matcher[string]
- func Not[T any](matcher Matcher[T]) Matcher[T]
- func NotEmptyString() Matcher[string]
- func SamePointer[T any](expected *T) Matcher[*T]
- func TypeOf[T any]() Matcher[any]
- func Within[N Numeric](expected N, delta float64) Matcher[N]
- func Zero[N Numeric]() Matcher[N]
- type MatcherFunc
- type Num
- func (n *Num[N]) EqualTo(expected N) AssertionMessage
- func (n *Num[N]) GreaterOrEqual(expected N) AssertionMessage
- func (n *Num[N]) GreaterThan(expected N) AssertionMessage
- func (n *Num[N]) IsZero() AssertionMessage
- func (n *Num[N]) LessOrEqual(expected N) AssertionMessage
- func (n *Num[N]) LessThan(expected N) AssertionMessage
- func (n *Num[N]) Matches(matcher Matcher[N]) AssertionMessage
- func (n *Num[N]) NotEqual(expected N) AssertionMessage
- func (n *Num[N]) Within(expected N, error float64) AssertionMessage
- type Numeric
- type Slc
- func (a *Slc[I]) Contains(expected ...I) AssertionMessage
- func (a *Slc[I]) ContainsExactly(expected ...I) AssertionMessage
- func (a *Slc[I]) ContainsInAnyOrder(matchers ...Matcher[I]) AssertionMessage
- func (a *Slc[I]) ContainsInOrder(matchers ...Matcher[I]) AssertionMessage
- func (a *Slc[I]) EqualTo(expected ...I) AssertionMessage
- func (a *Slc[I]) Every(matcher Matcher[I]) AssertionMessage
- func (a *Slc[I]) HasItem(matcher Matcher[I]) AssertionMessage
- func (a *Slc[I]) IsEmpty() AssertionMessage
- func (a *Slc[I]) Len(expected int) AssertionMessage
- func (a *Slc[I]) Matches(matcher Matcher[[]I]) AssertionMessage
- func (a *Slc[I]) NotContains(expected ...I) AssertionMessage
- func (a *Slc[I]) NotEmpty() AssertionMessage
- type St
- type Str
- func (s *Str[S]) Contains(expected string) AssertionMessage
- func (s *Str[S]) EqualIgnoringCase(expected string) AssertionMessage
- func (s *Str[S]) EqualIgnoringWhitespace(expected string) AssertionMessage
- func (s *Str[S]) EqualNormalizedWhitespace(expected string) AssertionMessage
- func (s *Str[S]) EqualTo(expected S) AssertionMessage
- func (s *Str[S]) HasPrefix(expected string) AssertionMessage
- func (s *Str[S]) HasPrefixIgnoringCase(expected string) AssertionMessage
- func (s *Str[S]) HasSuffix(expected string) AssertionMessage
- func (s *Str[S]) HasSuffixIgnoringCase(expected string) AssertionMessage
- func (s *Str[S]) IsEmpty() AssertionMessage
- func (s *Str[S]) Matches(matcher Matcher[string]) AssertionMessage
- func (s *Str[S]) MatchesRegexp(pattern string) AssertionMessage
- func (s *Str[S]) NotContains(expected string) AssertionMessage
- func (s *Str[S]) NotEmpty() AssertionMessage
- func (s *Str[S]) ToLowerEqualTo(expected string) AssertionMessage
- type Stringy
Examples ¶
- AllOf
- AnyOf
- AssignableTo
- CloseTo
- Contains
- ContainsInAnyOrder
- ContainsInOrder
- Describe
- EmptyString
- EqualIgnoringCase
- EqualIgnoringWhitespace
- EqualNormalizedWhitespace
- EqualTo
- Error
- ErrorAs
- ErrorIs
- Every
- False
- Flt.CloseTo
- Flt.IsInf
- Flt.IsInfSign
- Flt.IsNaN
- Flt.Matches
- GreaterOrEqual
- GreaterThan
- HasEntry
- HasItem
- HasKeyMatching
- HasPrefix
- HasPrefixIgnoringCase
- HasSuffix
- HasSuffixIgnoringCase
- HasValueMatching
- Having
- HavingField
- IsInf
- IsInfSign
- IsNaN
- LessOrEqual
- LessThan
- Mappy.EqualTo
- Mappy.HasEntry
- Mappy.HasKey
- Mappy.HasKeyMatching
- Mappy.HasValueMatching
- Mappy.IsEmpty
- Mappy.KeysExactly
- Mappy.Len
- Mappy.Matches
- Mappy.NotContains
- Mappy.NotEmpty
- Mappy.NotHasKey
- Mappy.WithItem
- Mappy.WithKeys
- Mappy.WithValues
- Mappy.WithoutKeys
- Match
- MatchFunc
- MatchesRegexp
- Nil
- NilError
- Not
- NotEmptyString
- NotNil
- Num.EqualTo
- Num.GreaterOrEqual
- Num.GreaterThan
- Num.IsZero
- Num.LessOrEqual
- Num.LessThan
- Num.Matches
- Num.NotEqual
- Num.Within
- SamePointer
- Slc.Contains
- Slc.ContainsExactly
- Slc.ContainsInAnyOrder
- Slc.ContainsInOrder
- Slc.EqualTo
- Slc.Every
- Slc.HasItem
- Slc.IsEmpty
- Slc.Len
- Slc.Matches
- Slc.NotContains
- Slc.NotEmpty
- St.EqualTo
- St.Matches
- Str.Contains
- Str.EqualIgnoringCase
- Str.EqualIgnoringWhitespace
- Str.EqualNormalizedWhitespace
- Str.EqualTo
- Str.HasPrefix
- Str.HasPrefixIgnoringCase
- Str.HasSuffix
- Str.HasSuffixIgnoringCase
- Str.IsEmpty
- Str.Matches
- Str.MatchesRegexp
- Str.NotContains
- Str.NotEmpty
- Str.ToLowerEqualTo
- True
- TypeOf
- Within
- Zero
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AssertionMessage ¶
func Error ¶
func Error(err error) AssertionMessage
Example ¶
package main
import (
"errors"
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Error(errors.New("boom")))
}
Output: message="got boom, want error" success=true
func ErrorAs ¶
func ErrorAs[T any](err error, target *T) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
type exampleError struct{}
func (exampleError) Error() string {
return "example error"
}
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
err := fmt.Errorf("wrapped: %w", exampleError{})
var target exampleError
printExample(a.ErrorAs(err, &target))
}
Output: message="got <wrapped: example error>, want error assignable to <*hammy_test.exampleError>" success=true
func ErrorIs ¶
func ErrorIs(err error, target error) AssertionMessage
Example ¶
package main
import (
"errors"
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
target := errors.New("timeout")
err := fmt.Errorf("request failed: %w", target)
printExample(a.ErrorIs(err, target))
}
Output: message="got <request failed: timeout>, want error matching <timeout>" success=true
func False ¶
func False(actual bool) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.False(false))
}
Output: message="got true, wanted false" success=true
func Match ¶
func Match[T any](actual T, matcher Matcher[T]) AssertionMessage
Match evaluates a generic matcher against an actual value and returns the resulting AssertionMessage.
This is a package-level function rather than a method on Hammy because Go does not support generic methods on non-generic types. A receiver form such as:
func (h *Hammy) Matches[T any](actual T, matcher Matcher[T])
is not legal Go. Keeping Match as a generic package function preserves the compile-time type safety between actual values and Matcher[T] instances while still composing naturally with assertions:
assert := hammy.New(t) assert.Is(hammy.Match(value, hammy.EqualTo(expected)))
Prefer the typed wrappers for direct assertions and composed matcher checks on known domains:
assert.Is(hammy.Number(actual).Matches(hammy.AllOf( hammy.GreaterThan(0), hammy.LessThan(10), )))
Match remains useful when no dedicated wrapper exists or when the actual value is intentionally held as any.
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Match(5, a.GreaterThan(3)))
}
Output: message="got <5>, wanted greater than <3>" success=true
func Nil ¶
func Nil(actual any) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
var value any = nil
printExample(a.Nil(value))
}
Output: message="got <<nil>>, wanted nil" success=true
func NilError ¶
func NilError(err error) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.NilError(nil))
}
Output: message="got <<nil>>, want nil error" success=true
func NotNil ¶
func NotNil(actual any) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
value := 42
printExample(a.NotNil(&value))
}
Output: message="got nil, wanted <*int>" success=true
func True ¶
func True(actual bool) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.True(true))
}
Output: message="got false, wanted true" success=true
type Flt ¶
type Flt[F Floaty] struct { // contains filtered or unexported fields }
func (*Flt[F]) CloseTo ¶
func (f *Flt[F]) CloseTo(expected, delta F) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Float(10.0).CloseTo(10.1, 0.2))
}
Output: message="got <10>, wanted within <0.2> of <10.1>" success=true
func (*Flt[F]) IsInf ¶
func (f *Flt[F]) IsInf() AssertionMessage
Example ¶
package main
import (
"fmt"
"math"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Float(math.Inf(1)).IsInf())
}
Output: message="got <+Inf>, wanted infinity" success=true
func (*Flt[F]) IsInfSign ¶
func (f *Flt[F]) IsInfSign(sign int) AssertionMessage
Example ¶
package main
import (
"fmt"
"math"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Float(math.Inf(-1)).IsInfSign(-1))
}
Output: message="got <-Inf>, wanted infinity with sign <-1>" success=true
func (*Flt[F]) IsNaN ¶
func (f *Flt[F]) IsNaN() AssertionMessage
Example ¶
package main
import (
"fmt"
"math"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Float(math.NaN()).IsNaN())
}
Output: message="got <NaN>, wanted NaN" success=true
func (*Flt[F]) Matches ¶
func (f *Flt[F]) Matches(matcher Matcher[F]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Float(10.0).Matches(a.CloseTo(10.1, 0.2)))
}
Output: message="got <10>, wanted within <0.2> of <10.1>" success=true
type Hammy ¶
func (*Hammy) Is ¶
func (h *Hammy) Is(a AssertionMessage)
func (*Hammy) IsNot ¶
func (h *Hammy) IsNot(a AssertionMessage)
func (*Hammy) That ¶
func (h *Hammy) That(msg string, a AssertionMessage)
type Mappy ¶
type Mappy[K comparable, V any] struct { // contains filtered or unexported fields }
func Map ¶
func Map[K comparable, V any](actual map[K]V) *Mappy[K, V]
func (Mappy[K, V]) EqualTo ¶
func (m Mappy[K, V]) EqualTo(expected map[K]V) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1}).EqualTo(map[string]int{"alpha": 1}))
}
Output: message="Map mismatch (-want +got):\n" success=true
func (Mappy[K, V]) HasEntry ¶
func (m Mappy[K, V]) HasEntry(keyMatcher Matcher[K], valueMatcher Matcher[V]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1, "beta": 2}).HasEntry(
a.EqualTo("beta"),
a.GreaterThan(1),
))
}
Output: message="found matching entry for key <beta>" success=true
func (Mappy[K, V]) HasKey ¶
func (m Mappy[K, V]) HasKey(key K) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1}).HasKey("alpha"))
}
Output: message="got key absent <alpha>, wanted present in map" success=true
func (Mappy[K, V]) HasKeyMatching ¶
func (m Mappy[K, V]) HasKeyMatching(matcher Matcher[K]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1}).HasKeyMatching(a.HasSuffix("pha")))
}
Output: message="found matching key <alpha>" success=true
func (Mappy[K, V]) HasValueMatching ¶
func (m Mappy[K, V]) HasValueMatching(matcher Matcher[V]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 3}).HasValueMatching(a.GreaterThan(2)))
}
Output: message="found matching value for key <alpha>" success=true
func (Mappy[K, V]) IsEmpty ¶
func (m Mappy[K, V]) IsEmpty() AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{}).IsEmpty())
}
Output: message="got len=<0>, wanted empty map" success=true
func (Mappy[K, V]) KeysExactly ¶
func (m Mappy[K, V]) KeysExactly(expected ...K) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1, "beta": 2}).KeysExactly("alpha", "beta"))
}
Output: message="got extra keys <[]> and missing keys <[]>, wanted exact key set" success=true
func (Mappy[K, V]) Len ¶
func (m Mappy[K, V]) Len(expected int) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1}).Len(1))
}
Output: message="got len=<1>, wanted <1>" success=true
func (Mappy[K, V]) Matches ¶
func (m Mappy[K, V]) Matches(matcher Matcher[map[K]V]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1, "beta": 2}).Matches(a.HasEntry(
a.EqualTo("beta"),
a.GreaterThan(1),
)))
}
Output: message="found matching entry for key <beta>" success=true
func (Mappy[K, V]) NotContains ¶
func (m Mappy[K, V]) NotContains(values ...V) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1, "beta": 2}).NotContains(3, 4))
}
Output: message="got values <[]>, wanted absent from map" success=true
func (Mappy[K, V]) NotEmpty ¶
func (m Mappy[K, V]) NotEmpty() AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1}).NotEmpty())
}
Output: message="got len=<1>, wanted non-empty map" success=true
func (Mappy[K, V]) NotHasKey ¶
func (m Mappy[K, V]) NotHasKey(key K) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1}).NotHasKey("beta"))
}
Output: message="got key present <beta>, wanted absent from map" success=true
func (Mappy[K, V]) WithItem ¶
func (m Mappy[K, V]) WithItem(k K, expected V) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1}).WithItem("alpha", 1))
}
Output: message="got value=<1> for key=<hi>, wanted <1>" success=true
func (Mappy[K, V]) WithKeys ¶
func (m Mappy[K, V]) WithKeys(expected ...K) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1, "beta": 2}).WithKeys("alpha", "beta"))
}
Output: message="got <[alpha beta]>, wanted keys <[]>" success=true
func (Mappy[K, V]) WithValues ¶
func (m Mappy[K, V]) WithValues(values ...V) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1, "beta": 2}).WithValues(1, 2))
}
Output: message="got <[1 2]>, wanted values <[]>" success=true
func (Mappy[K, V]) WithoutKeys ¶
func (m Mappy[K, V]) WithoutKeys(keys ...K) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1}).WithoutKeys("beta"))
}
Output: message="got keys <[]>, wanted absent from map" success=true
type Matcher ¶
type Matcher[T any] interface { Match(actual T) AssertionMessage }
func AllOf ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(5).Matches(a.AllOf(
a.GreaterThan(0),
a.LessThan(10),
)))
}
Output: message="matched all 2 matchers" success=true
func AnyOf ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(10).Matches(a.AnyOf(
a.EqualTo(7),
a.EqualTo(10),
)))
}
Output: message="matched one of 2 matchers" success=true
func AssignableTo ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
type exampleGreeter interface {
Greet() string
}
type exampleGreeterImpl struct{}
func (exampleGreeterImpl) Greet() string {
return "hello"
}
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
var value any = exampleGreeterImpl{}
printExample(a.Match(value, a.AssignableTo[exampleGreeter]()))
}
Output: message="got dynamic type <hammy_test.exampleGreeterImpl>, wanted assignable to <hammy_test.exampleGreeter>" success=true
func CloseTo ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Float(10.0).Matches(a.CloseTo(10.1, 0.2)))
}
Output: message="got <10>, wanted within <0.2> of <10.1>" success=true
func Contains ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello world").Matches(a.Contains("world")))
}
Output: message="got <hello world>, wanted substring <world>" success=true
func ContainsInAnyOrder ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{2, 1, 2}).Matches(a.ContainsInAnyOrder(
a.EqualTo(2),
a.EqualTo(2),
a.EqualTo(1),
)))
}
Output: message="all 3 items matched in any order" success=true
func ContainsInOrder ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]string{"alpha", "beta"}).Matches(a.ContainsInOrder(
a.EqualTo("alpha"),
a.HasSuffix("ta"),
)))
}
Output: message="all 2 items matched in order" success=true
func Describe ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(2).Matches(a.Describe("age check", a.GreaterThan(18))))
}
Output: message="age check: got <2>, wanted greater than <18>" success=false
func EmptyString ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("").Matches(a.EmptyString()))
}
Output: message="got <>, wanted an empty string" success=true
func EqualIgnoringCase ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("HeLLo").Matches(a.EqualIgnoringCase("hello")))
}
Output: message="got <HeLLo>, wanted equal to <hello> ignoring case" success=true
func EqualIgnoringWhitespace ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String(" hello\tworld \n").Matches(a.EqualIgnoringWhitespace("hello world")))
}
Output: message="got < hello\tworld \n>, wanted equal to <hello world> ignoring whitespace" success=true
func EqualNormalizedWhitespace ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String(" hello\tworld \n").Matches(a.EqualNormalizedWhitespace("hello world")))
}
Output: message="got < hello\tworld \n>, wanted equal to <hello world> ignoring whitespace" success=true
func EqualTo ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello").Matches(a.EqualTo("hello")))
}
Output: message="got <hello>, wanted equal to <hello>" success=true
func Every ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{2, 4, 6}).Matches(a.Every(a.GreaterThan(1))))
}
Output: message="all 3 items matched" success=true
func GreaterOrEqual ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(5).Matches(a.GreaterOrEqual(5)))
}
Output: message="got <5>, wanted greater or equal to <5>" success=true
func GreaterThan ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(5).Matches(a.GreaterThan(3)))
}
Output: message="got <5>, wanted greater than <3>" success=true
func HasEntry ¶
func HasEntry[K comparable, V any](keyMatcher Matcher[K], valueMatcher Matcher[V]) Matcher[map[K]V]
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1, "beta": 2}).Matches(a.HasEntry(
a.EqualTo("beta"),
a.GreaterThan(1),
)))
}
Output: message="found matching entry for key <beta>" success=true
func HasItem ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]string{"alpha", "beta"}).Matches(a.HasItem(a.HasPrefix("bet"))))
}
Output: message="found matching item at index 1" success=true
func HasKeyMatching ¶
func HasKeyMatching[K comparable, V any](matcher Matcher[K]) Matcher[map[K]V]
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 1}).Matches(a.HasKeyMatching[string, int](a.HasSuffix("pha"))))
}
Output: message="found matching key <alpha>" success=true
func HasPrefix ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello world").Matches(a.HasPrefix("hello")))
}
Output: message="got <hello world>, wanted prefix <hello>" success=true
func HasPrefixIgnoringCase ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("Hello world").Matches(a.HasPrefixIgnoringCase("heL")))
}
Output: message="got <Hello world>, wanted prefix <heL> ignoring case" success=true
func HasSuffix ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello world").Matches(a.HasSuffix("world")))
}
Output: message="got <hello world>, wanted suffix <world>" success=true
func HasSuffixIgnoringCase ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("Hello world").Matches(a.HasSuffixIgnoringCase("WOrLD")))
}
Output: message="got <Hello world>, wanted suffix <WOrLD> ignoring case" success=true
func HasValueMatching ¶
func HasValueMatching[K comparable, V any](matcher Matcher[V]) Matcher[map[K]V]
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Map(map[string]int{"alpha": 3}).Matches(a.HasValueMatching[string, int](a.GreaterThan(2))))
}
Output: message="found matching value for key <alpha>" success=true
func Having ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
type examplePerson struct {
Name string
Age int
}
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
person := examplePerson{Name: "Ada", Age: 37}
printExample(a.Struct(person).Matches(a.Having(func(actual examplePerson) int {
return actual.Age
}, a.GreaterThan(30))))
}
Output: message="got <37>, wanted greater than <30>" success=true
func HavingField ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
type examplePerson struct {
Name string
Age int
}
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
person := examplePerson{Name: "Ada", Age: 37}
printExample(a.Struct(person).Matches(a.HavingField("Name", func(actual examplePerson) string {
return actual.Name
}, a.EqualIgnoringCase("ada"))))
}
Output: message="got <Ada>, wanted equal to <ada> ignoring case" success=true
func IsInf ¶
Example ¶
package main
import (
"fmt"
"math"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
actual := math.Inf(1)
printExample(a.Float(actual).Matches(a.IsInf[float64]()))
}
Output: message="got <+Inf>, wanted infinity" success=true
func IsInfSign ¶
Example ¶
package main
import (
"fmt"
"math"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
actual := math.Inf(-1)
printExample(a.Float(actual).Matches(a.IsInfSign[float64](-1)))
}
Output: message="got <-Inf>, wanted infinity with sign <-1>" success=true
func IsNaN ¶
Example ¶
package main
import (
"fmt"
"math"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
actual := math.NaN()
printExample(a.Float(actual).Matches(a.IsNaN[float64]()))
}
Output: message="got <NaN>, wanted NaN" success=true
func LessOrEqual ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(5).Matches(a.LessOrEqual(5)))
}
Output: message="got <5>, wanted less or equal to <5>" success=true
func LessThan ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(3).Matches(a.LessThan(5)))
}
Output: message="got <3>, wanted less than <5>" success=true
func MatchFunc ¶
func MatchFunc[T any](fn func(actual T) AssertionMessage) Matcher[T]
MatchFunc adapts a closure into a Matcher without requiring a dedicated type.
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
matcher := a.MatchFunc(func(actual int) a.AssertionMessage {
return a.Assert(actual%2 == 0, "got <%d>, wanted an even number", actual)
})
printExample(a.Number(4).Matches(matcher))
}
Output: message="got <4>, wanted an even number" success=true
func MatchesRegexp ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello-42").Matches(a.MatchesRegexp(`^hello-\d+$`)))
}
Output: message="got <hello-42>, wanted regexp <^hello-\\d+$>" success=true
func Not ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello").Matches(a.Not(a.Contains("bye"))))
}
Output: message="not(got <hello>, wanted substring <bye>)" success=true
func NotEmptyString ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello").Matches(a.NotEmptyString()))
}
Output: message="got an empty string, wanted non-empty string" success=true
func SamePointer ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
value := 42
printExample(a.Match(&value, a.SamePointer(&value)))
}
Output: message="got pointer <0xPTR>, wanted same pointer as <0xPTR>" success=true
func TypeOf ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
type examplePerson struct {
Name string
Age int
}
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
var value any = examplePerson{Name: "Ada"}
printExample(a.Match(value, a.TypeOf[examplePerson]()))
}
Output: message="got dynamic type <hammy_test.examplePerson>, wanted <hammy_test.examplePerson>" success=true
func Within ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(10.1).Matches(a.Within(10.0, 0.2)))
}
Output: message="got <10.1>, wanted within <0.2> of <10>" success=true
func Zero ¶
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
var actual int = 0
printExample(a.Number(actual).Matches(a.Zero[int]()))
}
Output: message="got <0>, wanted equal to zero" success=true
type MatcherFunc ¶
type MatcherFunc[T any] func(actual T) AssertionMessage
func (MatcherFunc[T]) Match ¶
func (m MatcherFunc[T]) Match(actual T) AssertionMessage
type Num ¶
type Num[N Numeric] struct { // contains filtered or unexported fields }
func (*Num[N]) EqualTo ¶
func (n *Num[N]) EqualTo(expected N) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(42).EqualTo(42))
}
Output: message="want <42> equal to <42>" success=true
func (*Num[N]) GreaterOrEqual ¶
func (n *Num[N]) GreaterOrEqual(expected N) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(42).GreaterOrEqual(42))
}
Output: message="want <42> greater or equal to <42>" success=true
func (*Num[N]) GreaterThan ¶
func (n *Num[N]) GreaterThan(expected N) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(42).GreaterThan(7))
}
Output: message="want <42> greater than <7>" success=true
func (*Num[N]) IsZero ¶
func (n *Num[N]) IsZero() AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(0).IsZero())
}
Output: message="want <0> equal to zero" success=true
func (*Num[N]) LessOrEqual ¶
func (n *Num[N]) LessOrEqual(expected N) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(7).LessOrEqual(7))
}
Output: message="want <7> less or equal to <7>" success=true
func (*Num[N]) LessThan ¶
func (n *Num[N]) LessThan(expected N) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(7).LessThan(42))
}
Output: message="want <7> less than <42>" success=true
func (*Num[N]) Matches ¶
func (n *Num[N]) Matches(matcher Matcher[N]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(5).Matches(a.AllOf(
a.GreaterThan(0),
a.LessThan(10),
)))
}
Output: message="matched all 2 matchers" success=true
func (*Num[N]) NotEqual ¶
func (n *Num[N]) NotEqual(expected N) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(42).NotEqual(7))
}
Output: message="want <42> not equal to <7>" success=true
func (*Num[N]) Within ¶
func (n *Num[N]) Within(expected N, error float64) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Number(10.0).Within(10.1, 0.2))
}
Output: message="want <10> greater or equal to <10.1>" success=true
type Slc ¶
type Slc[I any] struct { // contains filtered or unexported fields }
func (*Slc[I]) Contains ¶
func (a *Slc[I]) Contains(expected ...I) AssertionMessage
Contains asserts whether the slice contains the expected elements in any order.
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{1, 2, 3}).Contains(2, 3))
}
Output: message="got 0 unmatched items, wanted array containing the 2 items. Items at index were missing" success=true
func (*Slc[I]) ContainsExactly ¶
func (a *Slc[I]) ContainsExactly(expected ...I) AssertionMessage
ContainsExactly asserts that the slice contains the exact number of elements in any order.
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{3, 2, 1}).ContainsExactly(1, 2, 3))
}
Output: message="got 0 unmatched items, wanted array containing the 3 items. Items at index were missing" success=true
func (*Slc[I]) ContainsInAnyOrder ¶
func (a *Slc[I]) ContainsInAnyOrder(matchers ...Matcher[I]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{2, 1, 2}).ContainsInAnyOrder(
a.EqualTo(2),
a.EqualTo(2),
a.EqualTo(1),
))
}
Output: message="all 3 items matched in any order" success=true
func (*Slc[I]) ContainsInOrder ¶
func (a *Slc[I]) ContainsInOrder(matchers ...Matcher[I]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]string{"alpha", "beta"}).ContainsInOrder(
a.EqualTo("alpha"),
a.HasSuffix("ta"),
))
}
Output: message="all 2 items matched in order" success=true
func (*Slc[I]) EqualTo ¶
func (a *Slc[I]) EqualTo(expected ...I) AssertionMessage
EqualTo asserts whether the slice is equal to the expected items in both order and values.
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{1, 2, 3}).EqualTo(1, 2, 3))
}
Output: message="slice mismatch (-want +got):\\n" success=true
func (*Slc[I]) Every ¶
func (a *Slc[I]) Every(matcher Matcher[I]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{2, 4, 6}).Every(a.GreaterThan(1)))
}
Output: message="all 3 items matched" success=true
func (*Slc[I]) HasItem ¶
func (a *Slc[I]) HasItem(matcher Matcher[I]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]string{"alpha", "beta"}).HasItem(a.HasPrefix("bet")))
}
Output: message="found matching item at index 1" success=true
func (*Slc[I]) IsEmpty ¶
func (a *Slc[I]) IsEmpty() AssertionMessage
IsEmpty asserts that the slice contains no elements.
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{}).IsEmpty())
}
Output: message="got len()=0, wanted 0" success=true
func (*Slc[I]) Len ¶
func (a *Slc[I]) Len(expected int) AssertionMessage
Len asserts that the slice contains exactly the number of elements specified.
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{1, 2, 3}).Len(3))
}
Output: message="got len()=3, wanted 3" success=true
func (*Slc[I]) Matches ¶
func (a *Slc[I]) Matches(matcher Matcher[[]I]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{2, 1}).Matches(a.ContainsInAnyOrder(
a.EqualTo(1),
a.EqualTo(2),
)))
}
Output: message="all 2 items matched in any order" success=true
func (*Slc[I]) NotContains ¶
func (a *Slc[I]) NotContains(expected ...I) AssertionMessage
NotContains asserts that none of the expected elements are present.
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{1, 2, 3}).NotContains(4, 5))
}
Output: message="got items at expected index present in slice, wanted all absent" success=true
func (*Slc[I]) NotEmpty ¶
func (a *Slc[I]) NotEmpty() AssertionMessage
NotEmpty asserts that the slice contains at least one element.
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Slice([]int{1}).NotEmpty())
}
Output: message="got len()=1, wanted > 0" success=true
type St ¶
type St[S any] struct { // contains filtered or unexported fields }
func (*St[S]) EqualTo ¶
func (s *St[S]) EqualTo(expected S) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
type examplePerson struct {
Name string
Age int
}
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Struct(examplePerson{Name: "Ada", Age: 37}).EqualTo(examplePerson{Name: "Ada", Age: 37}))
}
Output: message="Structs are not equal (+got -want):\n" success=true
func (*St[S]) Matches ¶
func (s *St[S]) Matches(matcher Matcher[S]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
type examplePerson struct {
Name string
Age int
}
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.Struct(examplePerson{Name: "Ada", Age: 37}).Matches(a.HavingField("Age", func(actual examplePerson) int {
return actual.Age
}, a.GreaterThan(30))))
}
Output: message="got <37>, wanted greater than <30>" success=true
type Str ¶
type Str[S Stringy] struct { // contains filtered or unexported fields }
func (*Str[S]) Contains ¶
func (s *Str[S]) Contains(expected string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello world").Contains("world"))
}
Output: message="got <hello world>, wanted substring <world>" success=true
func (*Str[S]) EqualIgnoringCase ¶
func (s *Str[S]) EqualIgnoringCase(expected string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("HeLLo").EqualIgnoringCase("hello"))
}
Output: message="got <HeLLo>, wanted equal to <hello> ignoring case" success=true
func (*Str[S]) EqualIgnoringWhitespace ¶
func (s *Str[S]) EqualIgnoringWhitespace(expected string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String(" hello\tworld \n").EqualIgnoringWhitespace("hello world"))
}
Output: message="got < hello\tworld \n>, wanted equal to <hello world> ignoring whitespace" success=true
func (*Str[S]) EqualNormalizedWhitespace ¶
func (s *Str[S]) EqualNormalizedWhitespace(expected string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String(" hello\tworld \n").EqualNormalizedWhitespace("hello world"))
}
Output: message="got < hello\tworld \n>, wanted equal to <hello world> ignoring whitespace" success=true
func (*Str[S]) EqualTo ¶
func (s *Str[S]) EqualTo(expected S) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello").EqualTo("hello"))
}
Output: message="got <hello>, wanted equal to <hello>" success=true
func (*Str[S]) HasPrefix ¶
func (s *Str[S]) HasPrefix(expected string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello world").HasPrefix("hello"))
}
Output: message="got <hello world>, wanted prefix <hello>" success=true
func (*Str[S]) HasPrefixIgnoringCase ¶
func (s *Str[S]) HasPrefixIgnoringCase(expected string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("Hello world").HasPrefixIgnoringCase("heL"))
}
Output: message="got <Hello world>, wanted prefix <heL> ignoring case" success=true
func (*Str[S]) HasSuffix ¶
func (s *Str[S]) HasSuffix(expected string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello world").HasSuffix("world"))
}
Output: message="got <hello world>, wanted suffix <world>" success=true
func (*Str[S]) HasSuffixIgnoringCase ¶
func (s *Str[S]) HasSuffixIgnoringCase(expected string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("Hello world").HasSuffixIgnoringCase("WOrLD"))
}
Output: message="got <Hello world>, wanted suffix <WOrLD> ignoring case" success=true
func (*Str[S]) IsEmpty ¶
func (s *Str[S]) IsEmpty() AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("").IsEmpty())
}
Output: message="got <>, wanted an empty string" success=true
func (*Str[S]) Matches ¶
func (s *Str[S]) Matches(matcher Matcher[string]) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello").Matches(a.EqualIgnoringCase("HELLO")))
}
Output: message="got <hello>, wanted equal to <HELLO> ignoring case" success=true
func (*Str[S]) MatchesRegexp ¶
func (s *Str[S]) MatchesRegexp(pattern string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello-42").MatchesRegexp(`^hello-\d+$`))
}
Output: message="got <hello-42>, wanted regexp <^hello-\\d+$>" success=true
func (*Str[S]) NotContains ¶
func (s *Str[S]) NotContains(expected string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello world").NotContains("bye"))
}
Output: message="got <hello world>, wanted no substring <bye>" success=true
func (*Str[S]) NotEmpty ¶
func (s *Str[S]) NotEmpty() AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("hello").NotEmpty())
}
Output: message="got an empty string, wanted non-empty string" success=true
func (*Str[S]) ToLowerEqualTo ¶
func (s *Str[S]) ToLowerEqualTo(expected string) AssertionMessage
Example ¶
package main
import (
"fmt"
"regexp"
a "github.com/gogunit/gunit/hammy"
)
var pointerPattern = regexp.MustCompile(`0x[0-9a-fA-F]+`)
func printExample(result a.AssertionMessage) {
message := pointerPattern.ReplaceAllString(result.Message, "0xPTR")
fmt.Printf("message=%q\nsuccess=%t\n", message, result.IsSuccessful)
}
func main() {
printExample(a.String("HeLLo").ToLowerEqualTo("hello"))
}
Output: message="got <hello>, wanted equal to <hello>" success=true