diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-03-03 17:06:42 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-03-03 17:06:42 -0500 |
| commit | b3064e570fab92cb4fa6b4c9265be5a4cbcf80e4 (patch) | |
| tree | abd242d315aaf90e073c3536c72eb30a2457e4e1 | |
| parent | 3bf8aad8aa51a2e3eed979ffdf182f4676a665b3 (diff) | |
| download | gui-b3064e570fab92cb4fa6b4c9265be5a4cbcf80e4.zip | |
lay/strain: use synctest
| -rw-r--r-- | lay/strain/solve_test.go | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/lay/strain/solve_test.go b/lay/strain/solve_test.go index a2cec87..d360c53 100644 --- a/lay/strain/solve_test.go +++ b/lay/strain/solve_test.go @@ -5,6 +5,7 @@ import ( "image" "slices" "testing" + "testing/synctest" "github.com/lithdew/casso" "golang.org/x/exp/shiny/unit" @@ -79,8 +80,9 @@ func TestTrivial(t *testing.T) { // One field that occupies the whole container. func TestSingleField(t *testing.T) { - // Setup t.Parallel() + + // Setup constraints := make(chan strain.Constraint) st := newSolverTest(t, []<-chan strain.Constraint{constraints}) defer st.Close() @@ -105,43 +107,45 @@ func TestSingleField(t *testing.T) { } } -// Solver with only layout constaints, no field constraints. -func TestLayConstrs(t *testing.T) { +// Widget gives its minimum size. +func TestFieldMinSize(t *testing.T) { t.Parallel() - - st := newSolverTest(t, nil) - defer st.Close() - - t.Fail() // TODO + synctest.Test(t, func(t *testing.T) { + // Setup + constraints := make(chan strain.Constraint) + st := newSolverTest(t, []<-chan strain.Constraint{constraints}) + defer st.Close() + defer close(constraints) + + // Add widget constraints + minWidth := unit.Value{32, unit.Ch} + minHeight := unit.Value{1.5, unit.Em} + constraints <- strain.Constraint{strain.Width, casso.GTE, minWidth} + constraints <- strain.Constraint{strain.Height, casso.GTE, minHeight} + synctest.Wait() + + // Solve + st.solve(image.Rect(12, 34, 800, 600), func(fields []image.Rectangle) error { + if len(fields) != 1 { + return fmt.Errorf("got %d fields; want %d", len(fields), 1) + } + field := fields[0] + if fixed.I(field.Dx()) < st.Style.Pixels(minWidth) { + return fmt.Errorf("dx = %v; want >= %v", field.Dx(), st.Style.Pixels(minWidth)) + } else if fixed.I(field.Dy()) < st.Style.Pixels(minHeight) { + return fmt.Errorf("dy = %v; want >= %v", field.Dy(), st.Style.Pixels(minHeight)) + } + return nil + }) + }) } -// Widget gives its minimum size. -func TestFieldMinSize(t *testing.T) { +// Solver with only layout constaints, no field constraints. +func TestLayConstrs(t *testing.T) { t.Parallel() - // Setup - constraints := make(chan strain.Constraint) - st := newSolverTest(t, []<-chan strain.Constraint{constraints}) + st := newSolverTest(t, nil) defer st.Close() - defer close(constraints) - // Add widget constraints - minWidth := unit.Value{32, unit.Ch} - minHeight := unit.Value{1.5, unit.Em} - constraints <- strain.Constraint{strain.Width, casso.GTE, minWidth} - constraints <- strain.Constraint{strain.Height, casso.GTE, minHeight} - - // Solve - st.solve(image.Rect(12, 34, 800, 600), func(fields []image.Rectangle) error { - if len(fields) != 1 { - return fmt.Errorf("got %d fields; want %d", len(fields), 1) - } - field := fields[0] - if fixed.I(field.Dx()) < st.Style.Pixels(minWidth) { - return fmt.Errorf("dx = %v; want >= %v", field.Dx(), st.Style.Pixels(minWidth)) - } else if fixed.I(field.Dy()) < st.Style.Pixels(minHeight) { - return fmt.Errorf("dy = %v; want >= %v", field.Dy(), st.Style.Pixels(minHeight)) - } - return nil - }) + t.Fail() // TODO: more tests } |