-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathborder_test.go
More file actions
86 lines (77 loc) · 2.85 KB
/
Copy pathborder_test.go
File metadata and controls
86 lines (77 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2026 the go-widgets/toolkit authors. All rights reserved.
// Use of this source code is governed by a BSD-3-Clause license that can be
// found in the LICENSE file at the root of this repository.
package toolkit
import "testing"
// TestBorderLayout sets all five regions and checks the classic border geometry:
// north/south span the full width, west/east span the band between them, center
// fills the rest. Regions are assigned out of order to prove the precedence is
// structural, not insertion-based.
func TestBorderLayout(t *testing.T) {
n, s, e, w, c := &dockProbe{}, &dockProbe{}, &dockProbe{}, &dockProbe{}, &dockProbe{}
b := NewBorder()
// Assign in a deliberately scrambled order.
b.Center = c
b.East = e
b.NorthSize, b.North = 10, n
b.WestSize, b.West = 12, w
b.SouthSize, b.South = 8, s
b.EastSize = 6
b.SetBounds(Rect{X: 0, Y: 0, W: 100, H: 50})
if got := n.Bounds(); got != (Rect{X: 0, Y: 0, W: 100, H: 10}) {
t.Fatalf("north = %+v", got)
}
if got := s.Bounds(); got != (Rect{X: 0, Y: 42, W: 100, H: 8}) {
t.Fatalf("south = %+v", got)
}
if got := w.Bounds(); got != (Rect{X: 0, Y: 10, W: 12, H: 32}) {
t.Fatalf("west = %+v", got)
}
if got := e.Bounds(); got != (Rect{X: 94, Y: 10, W: 6, H: 32}) {
t.Fatalf("east = %+v", got)
}
if got := c.Bounds(); got != (Rect{X: 12, Y: 10, W: 82, H: 32}) {
t.Fatalf("center = %+v", got)
}
}
// TestBorderPartial checks nil regions are skipped and a lone center fills the
// whole rect, and that a negative size clamps to zero.
func TestBorderPartial(t *testing.T) {
// Center only: fills everything.
c := &dockProbe{}
b := NewBorder()
b.Center = c
b.SetBounds(Rect{X: 3, Y: 4, W: 30, H: 20})
if got := c.Bounds(); got != (Rect{X: 3, Y: 4, W: 30, H: 20}) {
t.Fatalf("lone center = %+v", got)
}
// North with a negative size clamps to 0; no center (that branch stays false).
n := &dockProbe{}
b2 := NewBorder()
b2.North, b2.NorthSize = n, -5
b2.SetBounds(Rect{X: 0, Y: 0, W: 40, H: 40})
if n.Bounds().H != 0 {
t.Fatalf("negative north size not clamped: H=%d", n.Bounds().H)
}
}
// TestBorderDrawEvents checks Draw paints without panic and events route to a
// region, and miss cleanly when outside every region.
func TestBorderDrawEvents(t *testing.T) {
n, c := &dockProbe{}, &dockProbe{}
b := NewBorder()
b.North, b.NorthSize = n, 10
b.Center = c
b.SetBounds(Rect{X: 0, Y: 0, W: 100, H: 50})
b.Draw(newP(makeSurface(100, 50), 100), DefaultLight()) // no panic
b.OnEvent(Event{Kind: EventClick, X: 20, Y: 5}) // in the north band
if !n.got || c.got {
t.Fatalf("north routing: n=%v c=%v", n.got, c.got)
}
n.got = false
b.OnEvent(Event{Kind: EventClick, X: 20, Y: 30}) // in the center
if !c.got || n.got {
t.Fatalf("center routing: n=%v c=%v", n.got, c.got)
}
// A Border with no regions at all: OnEvent is a safe no-op.
NewBorder().OnEvent(Event{Kind: EventClick, X: 1, Y: 1})
}