hammy

package
v0.0.260421 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Hammy

GoDoc reference example

Hammy is a HamCrest inspired assertion library. The aim is to provide terse compile-time oriented type checking.

Getting Started

package adder

import (
	"testing"

	a "github.com/gogunit/gunit/hammy"
)

func Test_calculator(t *testing.T) {
	assert := a.New(t)
	actual := Add(2, 3)
	assert.Is(a.Number(actual).EqualTo(5))
}

Preferred Style

Prefer Number, String, Slice, Map, Struct, and Float for direct assertions and composed matcher checks:

func Test_add_returns_small_positive_sum(t *testing.T) {
	assert := a.New(t)
	actual := Add(2, 3)

	assert.Is(a.Number(actual).Matches(a.AllOf(
		a.GreaterThan(0),
		a.LessThan(10),
	)))
}

Use Match when no typed wrapper fits or when the value is intentionally held as any.

Generic Matcher Core

func Test_payload_has_expected_type(t *testing.T) {
	assert := a.New(t)
	var payload any = Response{Status: "ok"}

	assert.Is(a.Match(payload, a.TypeOf[Response]()))
}

Map

  • EqualTo
  • HasEntry
  • HasKeyMatching
  • IsEmpty
  • Len
  • WithItem
  • WithKeys
  • WithoutKeys
  • WithValues
  • HasValueMatching

Number

  • CloseTo (via Float)
  • EqualTo
  • GreaterThan
  • GreaterOrEqual
  • IsInf (via Float)
  • IsNaN (via Float)
  • IsZero
  • LessThan
  • LessOrEqual
  • Within

Slice

  • Contains
  • ContainsInAnyOrder
  • ContainsInOrder
  • EqualTo
  • Every
  • HasItem
  • Len

String

  • EqualTo
  • Contains
  • EqualIgnoringCase
  • EqualIgnoringWhitespace
  • HasPrefix
  • HasPrefixIgnoringCase
  • HasSuffix
  • HasSuffixIgnoringCase
  • IsEmpty
  • MatchesRegexp
  • ToLowerEqualTo

Struct

  • EqualTo
  • Having
  • HavingField

Writing a Custom Matcher

package model

import a "github.com/gogunit/gunit/hammy"

func Matcher(model Model) *Matchy {
	return &Matchy{
		model: model,
    }
}

type Matchy struct {
	model Model
}

func (m *Matcher) HasName(expected string) a.AssertionMessage {
	actual := m.model.Name
	return a.Assert(actual == expected, "want Name=<%v> equal to <%v>", actual, expected)
}
assert.Is(Matcher(model).HasName("bar"))

// fails with the message
// want Name=<"foo"> equal to <"bar">

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Join

func Join[T any](a []T, sep string) string

Types

type AssertionMessage

type AssertionMessage struct {
	IsSuccessful bool
	Message      string
}

func Assert

func Assert(isSuccessful bool, str string, args ...any) 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 Floaty

type Floaty interface {
	~float32 | ~float64
}

type Flt

type Flt[F Floaty] struct {
	// contains filtered or unexported fields
}

func Float

func Float[F Floaty](actual F) *Flt[F]

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

type Hammy struct {
	gunit.T
}

func New

func New(t gunit.T) *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

func AllOf[T any](matchers ...Matcher[T]) Matcher[T]
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

func AnyOf[T any](matchers ...Matcher[T]) Matcher[T]
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

func AssignableTo[T any]() Matcher[any]
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

func CloseTo[F Floaty](expected, delta F) Matcher[F]
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

func Contains(expected string) Matcher[string]
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

func ContainsInAnyOrder[T any](matchers ...Matcher[T]) Matcher[[]T]
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

func ContainsInOrder[T any](matchers ...Matcher[T]) Matcher[[]T]
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

func Describe[T any](msg string, matcher Matcher[T]) Matcher[T]
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

func EmptyString() Matcher[string]
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

func EqualIgnoringCase(expected string) Matcher[string]
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

func EqualIgnoringWhitespace(expected string) Matcher[string]
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

func EqualNormalizedWhitespace(expected string) Matcher[string]
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

func EqualTo[T any](expected T) Matcher[T]
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

func Every[T any](matcher Matcher[T]) Matcher[[]T]
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

func GreaterOrEqual[N Numeric](expected N) Matcher[N]
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

func GreaterThan[N Numeric](expected N) Matcher[N]
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

func HasItem[T any](matcher Matcher[T]) Matcher[[]T]
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

func HasPrefix(expected string) Matcher[string]
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

func HasPrefixIgnoringCase(expected string) Matcher[string]
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

func HasSuffix(expected string) Matcher[string]
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

func HasSuffixIgnoringCase(expected string) Matcher[string]
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

func Having[T, U any](selector func(T) U, matcher Matcher[U]) Matcher[T]
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

func HavingField[T, U any](name string, selector func(T) U, matcher Matcher[U]) Matcher[T]
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

func IsInf[F Floaty]() Matcher[F]
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

func IsInfSign[F Floaty](sign int) Matcher[F]
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

func IsNaN[F Floaty]() Matcher[F]
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

func LessOrEqual[N Numeric](expected N) Matcher[N]
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

func LessThan[N Numeric](expected N) Matcher[N]
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

func MatchesRegexp(pattern string) Matcher[string]
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

func Not[T any](matcher Matcher[T]) Matcher[T]
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

func NotEmptyString() Matcher[string]
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

func SamePointer[T any](expected *T) Matcher[*T]
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

func TypeOf[T any]() Matcher[any]
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

func Within[N Numeric](expected N, delta float64) Matcher[N]
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

func Zero[N Numeric]() Matcher[N]
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 Number

func Number[N Numeric](actual N) *Num[N]

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 Numeric

type Numeric interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

type Slc

type Slc[I any] struct {
	// contains filtered or unexported fields
}

func Slice

func Slice[I any](actual []I) *Slc[I]

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 Struct

func Struct[S any](actual S) *St[S]

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 String

func String[S Stringy](actual S) *Str[S]

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

type Stringy

type Stringy interface {
	~string
}

Jump to

Keyboard shortcuts

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