This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package tst
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Success-path tests for the Ident-prefixed assertions. They exercise the
|
||||
// non-failing branches of each function.
|
||||
|
||||
// --- AssertIdentEqual -----------------------------------------------------
|
||||
|
||||
func TestAssertIdentEqual_Int(t *testing.T) {
|
||||
AssertIdentEqual(t, "value", 1, 1)
|
||||
AssertIdentEqual(t, "value", 0, 0)
|
||||
}
|
||||
|
||||
func TestAssertIdentEqual_String(t *testing.T) {
|
||||
AssertIdentEqual(t, "name", "alice", "alice")
|
||||
}
|
||||
|
||||
func TestAssertIdentEqual_Bool(t *testing.T) {
|
||||
AssertIdentEqual(t, "flag", true, true)
|
||||
AssertIdentEqual(t, "flag", false, false)
|
||||
}
|
||||
|
||||
func TestAssertIdentEqual_EmptyIdent(t *testing.T) {
|
||||
AssertIdentEqual(t, "", 7, 7)
|
||||
}
|
||||
|
||||
// --- AssertIdentNotEqual --------------------------------------------------
|
||||
|
||||
func TestAssertIdentNotEqual_Int(t *testing.T) {
|
||||
AssertIdentNotEqual(t, "value", 1, 2)
|
||||
}
|
||||
|
||||
func TestAssertIdentNotEqual_String(t *testing.T) {
|
||||
AssertIdentNotEqual(t, "name", "alice", "bob")
|
||||
}
|
||||
|
||||
// --- AssertIdentPtrEqual --------------------------------------------------
|
||||
|
||||
func TestAssertIdentPtrEqual_BothNil(t *testing.T) {
|
||||
var a, b *int
|
||||
AssertIdentPtrEqual(t, "ptr", a, b)
|
||||
}
|
||||
|
||||
func TestAssertIdentPtrEqual_SameValue(t *testing.T) {
|
||||
a, b := 10, 10
|
||||
AssertIdentPtrEqual(t, "ptr", &a, &b)
|
||||
}
|
||||
|
||||
func TestAssertIdentPtrEqual_SameStringValue(t *testing.T) {
|
||||
a, b := "x", "x"
|
||||
AssertIdentPtrEqual(t, "ptr", &a, &b)
|
||||
}
|
||||
|
||||
// --- AssertIdentTrue / AssertIdentFalse -----------------------------------
|
||||
|
||||
func TestAssertIdentTrue(t *testing.T) {
|
||||
AssertIdentTrue(t, "ok", true)
|
||||
}
|
||||
|
||||
// AssertIdentFalse has a known quirk in the original implementation:
|
||||
// `if !value { t.Errorf(...) }` — i.e. it only fails when value is false,
|
||||
// which means "true" is the success path. We test the success path as
|
||||
// implemented (we MUST NOT change existing code).
|
||||
func TestAssertIdentFalse_SuccessPathAsImplemented(t *testing.T) {
|
||||
// As coded, AssertIdentFalse fails when value is false. So passing
|
||||
// `true` is the no-failure path according to the current implementation.
|
||||
AssertIdentFalse(t, "ok", true)
|
||||
}
|
||||
Reference in New Issue
Block a user