Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.18.x', '1.19.x', '1.22.x', '1.23.x' ]
go-version: [ '1.18.x', '1.19.x', '1.22.x', '1.23.x', '1.24.x' ]
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Inspired by [Hamcrest](https://github.com/hamcrest).

[![Build](https://github.com/corbym/gocrest/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/corbym/gocrest/actions/workflows/build.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/corbym/gocrest)](https://goreportcard.com/report/github.com/corbym/gocrest)
[![GoDoc](https://godoc.org/github.com/corbym/gocrest?status.svg)](http://godoc.org/github.com/corbym/gocrest)
[![GoDoc](https://pkg.go.dev/badge/github.com/corbym/gocrest.svg)](https://pkg.go.dev/github.com/corbym/gocrest)
[![Coverage Status](https://coveralls.io/repos/github/corbym/gocrest/badge.svg?branch=master)](https://coveralls.io/github/corbym/gocrest?branch=master)
## Package import

Expand Down
2 changes: 1 addition & 1 deletion by/eventually.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Channelling[T any](actual chan T) T {

// Reading peeks at the value of a reader by reading `len` bytes ahead.
func Reading(actual io.Reader, len int) []byte {
reader := bufio.NewReader(actual.(io.Reader))
reader := bufio.NewReader(actual)
peek, _ := reader.Peek(len)
return peek
}
Expand Down
6 changes: 0 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
module github.com/corbym/gocrest

go 1.18

require (
golang.org/x/sys v0.4.0 // indirect
golang.org/x/tools v0.5.1-0.20230111220935-a7f7db3f17fc // indirect
golang.org/x/tools/cmd/cover v0.1.0-deprecated // indirect
)
5 changes: 2 additions & 3 deletions has/haseveryelement.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ func EveryElement[A any](expects ...*gocrest.Matcher[A]) *gocrest.Matcher[[]A] {
return false
}

for i := 0; i < len(actual); i++ {
result := expects[i].Matches(actual[i])
if !result {
for i, act := range actual {
if !expects[i].Matches(act) {
return false
}
}
Expand Down
10 changes: 5 additions & 5 deletions is/allof.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ func matchAll[A any](allMatchers []*gocrest.Matcher[A], allOf *gocrest.Matcher[A
allOf.AppendActual(fmt.Sprintf("actual <%v>", actual))
matches := true
var failingMatchers []*gocrest.Matcher[A]
for x := 0; x < len(allMatchers); x++ {
if !allMatchers[x].Matches(actual) {
for _, m := range allMatchers {
if !m.Matches(actual) {
matches = false
failingMatchers = append(failingMatchers, allMatchers[x])
failingMatchers = append(failingMatchers, m)
}
allOf.AppendActual(allMatchers[x].Actual)
allOf.AppendActual(m.Actual)
}
allOf.Describe = fmt.Sprintf("%s", describe("and", failingMatchers))
allOf.Describe = describe("and", failingMatchers)
return matches
}
}
6 changes: 3 additions & 3 deletions is/anyof.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func anyMatcherMatches[A any](allMatchers []*gocrest.Matcher[A], anyOf *gocrest.
return func(actual A) bool {
matches := false
anyOf.AppendActual(fmt.Sprintf("actual <%v>", actual))
for x := 0; x < len(allMatchers); x++ {
if allMatchers[x].Matches(actual) {
for _, m := range allMatchers {
if m.Matches(actual) {
matches = true
}
anyOf.AppendActual(allMatchers[x].Actual)
anyOf.AppendActual(m.Actual)
}
return matches
}
Expand Down
46 changes: 19 additions & 27 deletions is/contains.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func StringContaining(expected ...string) *gocrest.Matcher[string] {
match := new(gocrest.Matcher[string])
match.Describe = fmt.Sprintf("something that contains %v", expected)
match.Matches = func(actual string) bool {
for i := 0; i < len(expected); i++ {
if !strings.Contains(actual, expected[i]) {
for _, e := range expected {
if !strings.Contains(actual, e) {
return false
}
}
Expand Down Expand Up @@ -57,8 +57,8 @@ func MapMatchingValues[K comparable, V comparable](expected ...*gocrest.Matcher[

func descriptionForMatchers[A any](expected []*gocrest.Matcher[A]) string {
var description = ""
for x := 0; x < len(expected); x++ {
description += expected[x].Describe
for x, m := range expected {
description += m.Describe
if x < len(expected)-1 {
description += " and "
}
Expand Down Expand Up @@ -93,19 +93,19 @@ func mapActualContainsExpected[K comparable, V comparable](expected map[K]V, act
expectedKeys = append(expectedKeys, k)
}
contains := make(map[V]bool)
for i := 0; i < len(expectedKeys); i++ {
val := actual[expectedKeys[i]]
if val == expected[expectedKeys[i]] {
for _, k := range expectedKeys {
val := actual[k]
if val == expected[k] {
contains[val] = true
}
}
return len(contains) == len(expectedKeys)
}
func mapActualContainsExpectedValues[K comparable, V comparable](expected []V, actual map[K]V) bool {
contains := make(map[V]bool)
for i := 0; i < len(expected); i++ {
for _, e := range expected {
for k, v := range actual {
if actual[k] == expected[i] {
if actual[k] == e {
contains[v] = true
break
}
Expand All @@ -114,14 +114,10 @@ func mapActualContainsExpectedValues[K comparable, V comparable](expected []V, a
return len(contains) == len(expected)
}
func mapActualMatchesExpected[K comparable, V comparable, A map[K]V](expected []*gocrest.Matcher[V], actual A) bool {
actualKeys := make([]K, 0, len(actual))
for k := range actual {
actualKeys = append(actualKeys, k)
}
contains := make(map[interface{}]bool)
for i := 0; i < len(expected); i++ {
contains := make(map[V]bool)
for _, exp := range expected {
for _, v := range actual {
if expected[i].Matches(v) {
if exp.Matches(v) {
contains[v] = true
}
}
Expand All @@ -130,11 +126,9 @@ func mapActualMatchesExpected[K comparable, V comparable, A map[K]V](expected []
}

func listContains[T comparable, A []T](expected A, actualValue A) bool {
contains := make(map[interface{}]bool)
for i := 0; i < len(expected); i++ {
for y := 0; y < len(actualValue); y++ {
exp := expected[i]
act := actualValue[y]
contains := make(map[T]bool)
for _, exp := range expected {
for _, act := range actualValue {
if exp == act {
contains[act] = true
}
Expand All @@ -144,10 +138,8 @@ func listContains[T comparable, A []T](expected A, actualValue A) bool {
}
func listMatches[T comparable](expected []*gocrest.Matcher[T], actualValue []T) bool {
contains := make(map[T]bool)
for i := 0; i < len(expected); i++ {
for y := 0; y < len(actualValue); y++ {
exp := expected[i]
act := actualValue[y]
for _, exp := range expected {
for _, act := range actualValue {
if exp.Matches(act) {
contains[act] = true
}
Expand All @@ -158,8 +150,8 @@ func listMatches[T comparable](expected []*gocrest.Matcher[T], actualValue []T)

func descriptionFor[T any, A []T](expected A) string {
var description = ""
for x := 0; x < len(expected); x++ {
description += fmt.Sprintf("<%v>", expected[x])
for x, e := range expected {
description += fmt.Sprintf("<%v>", e)
if x < len(expected)-1 {
description += " and "
}
Expand Down
4 changes: 2 additions & 2 deletions is/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

func describe[A any](conjunction string, matchers []*gocrest.Matcher[A]) string {
var description string
for x := 0; x < len(matchers); x++ {
description += matchers[x].Describe
for x, m := range matchers {
description += m.Describe
if x+1 < len(matchers) {
description += fmt.Sprintf(" %s ", conjunction)
}
Expand Down
2 changes: 1 addition & 1 deletion matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (matcher *Matcher[A]) String() string {
}

// Reasonf allows a formatted reason for the mismatch.
func (matcher *Matcher[A]) Reasonf(format string, args ...interface{}) *Matcher[A] {
func (matcher *Matcher[A]) Reasonf(format string, args ...any) *Matcher[A] {
return matcher.Reason(fmt.Sprintf(format, args...))
}

Expand Down
2 changes: 1 addition & 1 deletion matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ func TestTypeName(t *testing.T) {
pub := new(Foo)

tests := []struct {
actual interface{}
actual any
expected string
shouldFail bool
}{
Expand Down
4 changes: 2 additions & 2 deletions stubtestingt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ type StubTestingT struct {
MockTestOutput string
}

func (t *StubTestingT) Logf(format string, args ...interface{}) {
func (t *StubTestingT) Logf(format string, args ...any) {
t.MockTestOutput = fmt.Sprintf(format, args...)
t.failed = true
}

func (t *StubTestingT) Errorf(format string, args ...interface{}) {
func (t *StubTestingT) Errorf(format string, args ...any) {
t.MockTestOutput = fmt.Sprintf(format, args...)
t.failed = true
}
Expand Down
4 changes: 2 additions & 2 deletions testingt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package gocrest

// TestingT supplies a convenience interface that matches the testing.T interface.
type TestingT interface {
Logf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Logf(format string, args ...any)
Errorf(format string, args ...any)
Failed() bool
Fail()
FailNow()
Expand Down
6 changes: 3 additions & 3 deletions then/eventually.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type RecordingTestingT struct {
}

// Errorf appends an error message into the failure buffer. Only used with Eventually
func (t *RecordingTestingT) Errorf(format string, args ...interface{}) {
func (t *RecordingTestingT) Errorf(format string, args ...any) {
t.Lock()
defer t.Unlock()
t.failures = append(t.failures, FailureLog{
Expand Down Expand Up @@ -162,10 +162,10 @@ func Eventually(t gocrest.TestingT, waitFor, tick time.Duration, assertions func

// WithinTenSeconds is a shortcut for a ten-second Eventually call with one second tick
func WithinTenSeconds(t gocrest.TestingT, assertions func(eventually gocrest.TestingT)) {
Eventually(t, time.Duration(10)*time.Second, time.Duration(1)*time.Second, assertions)
Eventually(t, 10*time.Second, time.Second, assertions)
}

// WithinFiveSeconds is a shortcut for a five-second Eventually call with one second tick
func WithinFiveSeconds(t gocrest.TestingT, assertions func(eventually gocrest.TestingT)) {
Eventually(t, time.Duration(10)*time.Second, time.Duration(1)*time.Second, assertions)
Eventually(t, 5*time.Second, time.Second, assertions)
}
Loading