From 08f105af6b7ae8d723bdf6a3eab8a232c7e2504a Mon Sep 17 00:00:00 2001 From: JetSetIlly Date: Sat, 30 Mar 2024 07:09:25 +0000 Subject: [PATCH] added ExpectImplements() function to test package --- gui/sdlimgui/win_rom_select.go | 1 - test/doc.go | 3 +++ test/expected.go | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gui/sdlimgui/win_rom_select.go b/gui/sdlimgui/win_rom_select.go index be450ed3..bd80bc48 100644 --- a/gui/sdlimgui/win_rom_select.go +++ b/gui/sdlimgui/win_rom_select.go @@ -47,7 +47,6 @@ type winSelectROM struct { currPath string entries []os.DirEntry - err error selectedFile string selectedFileBase string diff --git a/test/doc.go b/test/doc.go index 2cd4af0c..3db15acb 100644 --- a/test/doc.go +++ b/test/doc.go @@ -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. diff --git a/test/expected.go b/test/expected.go index ef046516..200f032f 100644 --- a/test/expected.go +++ b/test/expected.go @@ -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: //