Skip to content

Commit

Permalink
start up
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyab committed Apr 26, 2024
1 parent 837c81c commit db05a0a
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
11 changes: 11 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package teq

type Teq struct{}

func (teq *Teq) Equal(t TestingT, a, b interface{}) bool {
ok := a == b
if !ok {
t.Errorf("expected %v, got %v", a, b)
}
return ok
}
48 changes: 48 additions & 0 deletions api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package teq_test

import (
"fmt"
"testing"

"github.com/seiyab/teq"
)

type test struct {
a any
b any
expected []string
}

func TestEqual(t *testing.T) {
assert := teq.Teq{}

tests := primitives()
for _, test := range tests {
name := fmt.Sprintf("%T(%v) == %T(%v)", test.a, test.a, test.b, test.b)
t.Run(name, func(t *testing.T) {
mt := &mockT{}
assert.Equal(mt, test.a, test.b)
if len(mt.errors) != len(test.expected) {
t.Fatalf("expected %d errors, got %d", len(test.expected), len(mt.errors))
}
for i, e := range test.expected {
if mt.errors[i] != e {
t.Errorf("expected %v, got %v at i = %d", e, mt.errors[i], i)
}
}
})
}
}

func primitives() []test {
return []test{
{1, 1, nil},
{1, 2, []string{"expected 1, got 2"}},
{uint8(1), uint8(1), nil},
{uint8(1), uint8(2), []string{"expected 1, got 2"}},
{"a", "a", nil},
{"a", "b", []string{"expected a, got b"}},

{"a", 1, []string{"expected a, got 1"}},
}
}
1 change: 1 addition & 0 deletions equality.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package teq
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/seiyab/teq

go 1.18
9 changes: 9 additions & 0 deletions testingt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package teq

import "testing"

type TestingT interface {
Errorf(format string, args ...interface{})
}

var _ TestingT = &testing.T{}
17 changes: 17 additions & 0 deletions testingt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package teq_test

import (
"fmt"

"github.com/seiyab/teq"
)

type mockT struct {
errors []string
}

var _ teq.TestingT = &mockT{}

func (t *mockT) Errorf(format string, args ...interface{}) {
t.errors = append(t.errors, fmt.Sprintf(format, args...))
}

0 comments on commit db05a0a

Please sign in to comment.