Pruefe Layout-Validierung systematischer

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Jesko Anschütz 2026-03-22 17:42:30 +01:00
parent ad3d4316b6
commit d87bb2b269

View file

@ -1,6 +1,9 @@
package messagewall
import "testing"
import (
"strings"
"testing"
)
func TestResolveBuildsScenes(t *testing.T) {
request := ResolveRequest{
@ -60,3 +63,87 @@ func TestValidateRejectsOverlappingSlots(t *testing.T) {
t.Fatal("Validate() error = nil, want overlap error")
}
}
func TestValidateRejectsDocumentedInvalidLayouts(t *testing.T) {
tests := []struct {
name string
layout Layout
wantMessage string
}{
{
name: "unsupported version",
layout: Layout{
Version: 2,
CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "grid"},
FitMode: "cover",
Slots: []Slot{{SlotID: "a", X: 0, Y: 0, Width: 100, Height: 100}},
},
wantMessage: "unsupported layout version",
},
{
name: "unsupported unit",
layout: Layout{
Version: 1,
CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "pixel"},
FitMode: "cover",
Slots: []Slot{{SlotID: "a", X: 0, Y: 0, Width: 100, Height: 100}},
},
wantMessage: "unsupported coordinate_space unit",
},
{
name: "unsupported fit mode",
layout: Layout{
Version: 1,
CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "grid"},
FitMode: "stretch",
Slots: []Slot{{SlotID: "a", X: 0, Y: 0, Width: 100, Height: 100}},
},
wantMessage: "unsupported fit_mode",
},
{
name: "empty slots",
layout: Layout{
Version: 1,
CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "grid"},
FitMode: "cover",
},
wantMessage: "layout must contain at least one slot",
},
{
name: "duplicate slot ids",
layout: Layout{
Version: 1,
CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "grid"},
FitMode: "cover",
Slots: []Slot{
{SlotID: "a", X: 0, Y: 0, Width: 50, Height: 100},
{SlotID: "a", X: 50, Y: 0, Width: 50, Height: 100},
},
},
wantMessage: "duplicate slot_id",
},
{
name: "slot exceeds bounds",
layout: Layout{
Version: 1,
CoordinateSpace: CoordinateSpace{Width: 100, Height: 100, Unit: "grid"},
FitMode: "cover",
Slots: []Slot{{SlotID: "a", X: 60, Y: 0, Width: 50, Height: 100}},
},
wantMessage: "exceeds coordinate_space width",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := Validate(tt.layout)
if err == nil {
t.Fatal("Validate() error = nil, want validation error")
}
if !strings.Contains(err.Error(), tt.wantMessage) {
t.Fatalf("Validate() error = %q, want message containing %q", err.Error(), tt.wantMessage)
}
})
}
}