-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpositioned_extended_test.go
More file actions
79 lines (71 loc) · 1.67 KB
/
positioned_extended_test.go
File metadata and controls
79 lines (71 loc) · 1.67 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
package layout
import (
"math"
"testing"
)
func TestPositionSticky(t *testing.T) {
// Test sticky positioning (treated as relative without scroll context)
root := &Node{
Style: Style{
Width: Px(400),
Height: Px(300),
},
Children: []*Node{
{
Style: Style{
Position: PositionSticky,
Top: Px(10),
Left: Px(20),
Width: Px(100),
Height: Px(100),
},
},
},
}
constraints := Loose(500, 400)
ctx := NewLayoutContext(800, 600, 16)
Layout(root, constraints, ctx)
LayoutWithPositioning(root, constraints, root.Rect, ctx)
child := root.Children[0]
// Sticky should offset like relative
if child.Rect.X < 20 {
t.Errorf("Expected X >= 20, got %.2f", child.Rect.X)
}
if child.Rect.Y < 10 {
t.Errorf("Expected Y >= 10, got %.2f", child.Rect.Y)
}
}
func TestLayoutWithPositioning(t *testing.T) {
// Test the LayoutWithPositioning helper function
root := &Node{
Style: Style{
Width: Px(400),
Height: Px(300),
},
Children: []*Node{
{
Style: Style{
Position: PositionAbsolute,
Left: Px(50),
Top: Px(50),
Width: Px(100),
Height: Px(100),
},
},
},
}
constraints := Loose(500, 400)
viewport := Rect{X: 0, Y: 0, Width: 500, Height: 400}
ctx := NewLayoutContext(800, 600, 16)
size := LayoutWithPositioning(root, constraints, viewport, ctx)
if size.Width <= 0 || size.Height <= 0 {
t.Error("LayoutWithPositioning should return valid size")
}
child := root.Children[0]
if math.Abs(child.Rect.X-50.0) > 1.0 {
t.Errorf("Expected X=50, got %.2f", child.Rect.X)
}
if math.Abs(child.Rect.Y-50.0) > 1.0 {
t.Errorf("Expected Y=50, got %.2f", child.Rect.Y)
}
}