added ExpectImplements() function to test package

This commit is contained in:
JetSetIlly 2024-03-30 07:09:25 +00:00
parent 1a26231b5e
commit 08f105af6b
3 changed files with 11 additions and 1 deletions

View file

@ -47,7 +47,6 @@ type winSelectROM struct {
currPath string
entries []os.DirEntry
err error
selectedFile string
selectedFileBase string

View file

@ -18,11 +18,14 @@
//
// The ExpectEquality() is the most basic and probably the most useful function.
// It compares like-typed variables for equality and returns true if they match.
// ExpectInequality() is the inverse function.
//
// The ExpectFailure() and ExpectSuccess() functions test for failure and
// success. These two functions work with bool or error and special handling for
// nil.
//
// ExpectImplements() tests whether an instance implements the specified type.
//
// The Writer type meanwhile, implements the io.Writer interface and should be
// used to capture output. The Writer.Compare() function can then be used to
// test for equality.

View file

@ -34,6 +34,14 @@ func ExpectInequality[T comparable](t *testing.T, value T, expectedValue T) {
}
}
// ExpectImplements tests whether an instance is an implementation of type T
func ExpectImplements[T comparable](t *testing.T, instance any, implements T) {
t.Helper()
if _, ok := instance.(T); !ok {
t.Fatalf("implementation test of type %T failed: type %T does not implement %T", instance, instance, implements)
}
}
// ExpectFailure tests argument v for a failure condition suitable for it's
// type. Types bool and error are treated thus:
//