v0.0.99
This commit is contained in:
65
tst/assertions.go
Normal file
65
tst/assertions.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package tst
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func AssertEqual[T comparable](t *testing.T, actual T, expected T) {
|
||||
if actual != expected {
|
||||
t.Errorf("values differ: Actual: '%v', Expected: '%v'", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func AssertNotEqual[T comparable](t *testing.T, actual T, expected T) {
|
||||
if actual == expected {
|
||||
t.Errorf("values do not differ: Actual: '%v', Expected: '%v'", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func AssertDeRefEqual[T comparable](t *testing.T, actual *T, expected T) {
|
||||
if actual == nil {
|
||||
t.Errorf("values differ: Actual: NIL, Expected: '%v'", expected)
|
||||
}
|
||||
if *actual != expected {
|
||||
t.Errorf("values differ: Actual: '%v', Expected: '%v'", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func AssertPtrEqual[T comparable](t *testing.T, actual *T, expected *T) {
|
||||
if actual == nil && expected == nil {
|
||||
return
|
||||
}
|
||||
if actual != nil && expected != nil {
|
||||
if *actual != *expected {
|
||||
t.Errorf("values differ: Actual: '%v', Expected: '%v'", *actual, *expected)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
if actual == nil && expected != nil {
|
||||
t.Errorf("values differ: Actual: nil, Expected: not-nil")
|
||||
}
|
||||
if actual != nil && expected == nil {
|
||||
t.Errorf("values differ: Actual: not-nil, Expected: nil")
|
||||
}
|
||||
}
|
||||
|
||||
func AssertHexEqual(t *testing.T, expected string, actual []byte) {
|
||||
actualStr := hex.EncodeToString(actual)
|
||||
if actualStr != expected {
|
||||
t.Errorf("values differ: Actual: '%v', Expected: '%v'", actualStr, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func AssertTrue(t *testing.T, value bool) {
|
||||
if !value {
|
||||
t.Error("value should be true")
|
||||
}
|
||||
}
|
||||
|
||||
func AssertFalse(t *testing.T, value bool) {
|
||||
if value {
|
||||
t.Error("value should be false")
|
||||
}
|
||||
}
|
48
tst/identAssertions.go
Normal file
48
tst/identAssertions.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package tst
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func AssertIdentEqual[T comparable](t *testing.T, ident string, actual T, expected T) {
|
||||
if actual != expected {
|
||||
t.Errorf("[%s] values differ: Actual: '%v', Expected: '%v'", ident, actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func AssertIdentNotEqual[T comparable](t *testing.T, ident string, actual T, expected T) {
|
||||
if actual == expected {
|
||||
t.Errorf("[%s] values do not differ: Actual: '%v', Expected: '%v'", ident, actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func AssertIdentPtrEqual[T comparable](t *testing.T, ident string, actual *T, expected *T) {
|
||||
if actual == nil && expected == nil {
|
||||
return
|
||||
}
|
||||
if actual != nil && expected != nil {
|
||||
if *actual != *expected {
|
||||
t.Errorf("[%s] values differ: Actual: '%v', Expected: '%v'", ident, *actual, *expected)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
if actual == nil && expected != nil {
|
||||
t.Errorf("[%s] values differ: Actual: nil, Expected: not-nil", ident)
|
||||
}
|
||||
if actual != nil && expected == nil {
|
||||
t.Errorf("[%s] values differ: Actual: not-nil, Expected: nil", ident)
|
||||
}
|
||||
}
|
||||
|
||||
func AssertIdentTrue(t *testing.T, ident string, value bool) {
|
||||
if !value {
|
||||
t.Errorf("[%s] value should be true", ident)
|
||||
}
|
||||
}
|
||||
|
||||
func AssertIdentFalse(t *testing.T, ident string, value bool) {
|
||||
if !value {
|
||||
t.Errorf("[%s] value should be false", ident)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user