internal

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expect

func Expect[A any](t testing.TB, actual A, m Matcher[A])
Example
package main

import (
	"fmt"

	"github.com/xoctopus/x/testx"
	"github.com/xoctopus/x/testx/internal"
	"github.com/xoctopus/x/testx/testutil"
)

type uncomparable struct {
	x []int
}

func main() {
	t := &testutil.MockTB{}

	t.Reset()
	internal.Expect(t, uncomparable{x: []int{1}}, testx.Equal(uncomparable{x: []int{2}}))
	fmt.Println(t.Output2())

	t.Reset()
	internal.Expect(t, uncomparable{x: []int{1}}, testx.NotEqual(uncomparable{x: []int{1}}))
	fmt.Println(t.Output2())

	t.Reset()
	internal.Expect(t, 1.2, testx.BeAssignableTo[int]())
	fmt.Println(t.Output2())

}
Output:
should Equal, but got
  strings.Join({
  	"internal_test.uncomparable:{x:[",
- 	"2",
+ 	"1",
  	"]}",
  }, "")

should not Equal, but got
{[1]}

should BeAssignableTo[int], but got
1.2

Types

type Matcher

type Matcher[Actual any] interface {
	// Action returns matching action name
	Action() string
	// Match defines matching action
	Match(Actual) bool
	// Negative returns if negative action. eg: Equal, NotEqual
	Negative() bool
}

func NewMatcher

func NewMatcher[A any](action string, match func(A) bool) Matcher[A]

func Not

func Not[Actual any](matcher Matcher[Actual]) Matcher[Actual]

type MatcherNewer

type MatcherNewer[Actual any, Expect any] func(expect Expect) Matcher[Actual]

func NewComparedMatcher

func NewComparedMatcher[Actual any, Expect any](action string, match func(Actual, Expect) bool) MatcherNewer[Actual, Expect]

type NormalizedExpectedMatcher

type NormalizedExpectedMatcher interface {
	NormalizeExpect() any
}

type NormalizedMatcher

type NormalizedMatcher[T any] interface {
	NormalizeActual(T) any
}

Jump to

Keyboard shortcuts

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