summaryrefslogtreecommitdiff
path: root/tests/gobang.go
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-10-17 13:10:11 -0300
committerEuAndreh <eu@euandre.org>2024-10-17 13:10:11 -0300
commit2a848c002a6d7863ffa25434d1ce6ccdd14d981f (patch)
tree37251d6fc16cc375d8d80f446b15944e429b1b21 /tests/gobang.go
parentsrc/gobang.go: ValidSQLTablePrefix() -> ValidateSQLTablePrefix() (diff)
downloadgobang-2a848c002a6d7863ffa25434d1ce6ccdd14d981f.tar.gz
gobang-2a848c002a6d7863ffa25434d1ce6ccdd14d981f.tar.xz
src/gobang.go: Add WrapErrors()
Diffstat (limited to 'tests/gobang.go')
-rw-r--r--tests/gobang.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/gobang.go b/tests/gobang.go
index be33eb4..9d42ca9 100644
--- a/tests/gobang.go
+++ b/tests/gobang.go
@@ -3,6 +3,7 @@ package gobang
import (
"encoding/json"
"errors"
+ "fmt"
"log/slog"
"os"
"strings"
@@ -48,6 +49,32 @@ func test_ValidateSQLTablePrefix() {
})
}
+func test_WrapErrors() {
+ TestStart("WrapErrors()")
+
+ Testing("nil for empty args", func() {
+ TAssertEqual(WrapErrors(), nil)
+ })
+
+ Testing("nil when all args are nil", func() {
+ TAssertEqual(WrapErrors(nil, nil, nil), nil)
+ })
+
+ Testing("if only 1 is an error, return it", func() {
+ err := errors.New("my error")
+ TAssertEqual(WrapErrors(nil, nil, err), err)
+ })
+
+ Testing("otherwise wrap them, from right to left", func() {
+ err1 := errors.New("error 1")
+ err2 := errors.New("error 2")
+ expected1 := fmt.Errorf("error %w on top of %w", err1, err2)
+ expected2 := fmt.Errorf("error %w on top of %w", err2, err1)
+ TAssertEqual(WrapErrors(nil, err1, nil, err2), expected1)
+ TAssertEqual(WrapErrors(err2, nil, nil, err1), expected2)
+ })
+}
+
func test_SomeError() {
TestStart("SomeError()")
@@ -763,8 +790,10 @@ func test_setHostname() {
}
+
func MainTest() {
test_ValidateSQLTablePrefix()
+ test_WrapErrors()
test_SomeError()
test_SomeFnError()
test_Random()