[🤖] Add Unit-Tests
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m34s

This commit is contained in:
2026-04-27 10:46:08 +02:00
parent dad0e3240d
commit 02d6894ec6
116 changed files with 18795 additions and 1 deletions
+88
View File
@@ -0,0 +1,88 @@
package sq
import (
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
"strings"
"testing"
)
func TestPPID(t *testing.T) {
id := PPID()
tst.AssertTrue(t, strings.HasPrefix(id, "p_"))
if len(id) != 2+8 {
t.Errorf("expected length 10, got %d (id=%q)", len(id), id)
}
// uniqueness - very high probability with 8 base62 chars
seen := map[string]bool{}
for range 1000 {
x := PPID()
if seen[x] {
t.Errorf("duplicate PPID: %s", x)
}
seen[x] = true
}
}
func TestPPAdd(t *testing.T) {
pp := PP{}
id1 := pp.Add(123)
id2 := pp.Add("hello")
tst.AssertNotEqual(t, id1, id2)
tst.AssertEqual(t, 123, pp[id1])
tst.AssertEqual(t, "hello", pp[id2])
tst.AssertEqual(t, 2, len(pp))
}
func TestPPAddAll(t *testing.T) {
a := PP{"a": 1, "b": 2}
b := PP{"c": 3, "d": 4}
a.AddAll(b)
tst.AssertEqual(t, 4, len(a))
tst.AssertEqual(t, 1, a["a"])
tst.AssertEqual(t, 2, a["b"])
tst.AssertEqual(t, 3, a["c"])
tst.AssertEqual(t, 4, a["d"])
}
func TestPPAddAllOverwrite(t *testing.T) {
a := PP{"a": 1, "b": 2}
b := PP{"a": 99}
a.AddAll(b)
tst.AssertEqual(t, 2, len(a))
tst.AssertEqual(t, 99, a["a"])
tst.AssertEqual(t, 2, a["b"])
}
func TestJoin(t *testing.T) {
a := PP{"a": 1, "b": 2}
b := PP{"c": 3}
c := PP{"d": 4, "a": 99}
r := Join(a, b, c)
tst.AssertEqual(t, 4, len(r))
tst.AssertEqual(t, 99, r["a"])
tst.AssertEqual(t, 2, r["b"])
tst.AssertEqual(t, 3, r["c"])
tst.AssertEqual(t, 4, r["d"])
// Source maps must remain unchanged
tst.AssertEqual(t, 2, len(a))
tst.AssertEqual(t, 1, a["a"])
}
func TestJoinEmpty(t *testing.T) {
r := Join()
tst.AssertEqual(t, 0, len(r))
}
func TestJoinSingle(t *testing.T) {
a := PP{"a": 1}
r := Join(a)
tst.AssertEqual(t, 1, len(r))
tst.AssertEqual(t, 1, r["a"])
}