From e980c4bb2b196245994ee6afdf62924ea2b7bdab Mon Sep 17 00:00:00 2001 From: Matthew Coleman Date: Fri, 8 Mar 2024 13:02:01 -0500 Subject: [PATCH] Add tests, clean-up --- container/container_test.go | 54 ++++++++++++++++++++++++++++++++++++- container/options.go | 2 +- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/container/container_test.go b/container/container_test.go index f502654..efe2af5 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -713,7 +713,33 @@ func TestNew(t *testing.T) { }, }, { - desc: "horizontal unequal split", + desc: "horizontal, reversed unequal split", + termSize: image.Point{10, 20}, + container: func(ft *faketerm.Terminal) (*Container, error) { + return New( + ft, + SplitHorizontal( + Top( + Border(linestyle.Light), + ), + Bottom( + Border(linestyle.Light), + ), + SplitPercentFromEnd(20), + ), + ) + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + cvs := testcanvas.MustNew(ft.Area()) + testdraw.MustBorder(cvs, image.Rect(0, 0, 10, 16)) + testdraw.MustBorder(cvs, image.Rect(0, 16, 10, 20)) + testcanvas.MustApply(cvs, ft) + return ft + }, + }, + { + desc: "horizontal fixed splits", termSize: image.Point{10, 20}, container: func(ft *faketerm.Terminal) (*Container, error) { return New( @@ -738,6 +764,32 @@ func TestNew(t *testing.T) { return ft }, }, + { + desc: "horizontal, reversed fixed splits", + termSize: image.Point{10, 20}, + container: func(ft *faketerm.Terminal) (*Container, error) { + return New( + ft, + SplitHorizontal( + Top( + Border(linestyle.Light), + ), + Bottom( + Border(linestyle.Light), + ), + SplitFixedFromEnd(4), + ), + ) + }, + want: func(size image.Point) *faketerm.Terminal { + ft := faketerm.MustNew(size) + cvs := testcanvas.MustNew(ft.Area()) + testdraw.MustBorder(cvs, image.Rect(0, 0, 10, 16)) + testdraw.MustBorder(cvs, image.Rect(0, 16, 10, 20)) + testcanvas.MustApply(cvs, ft) + return ft + }, + }, { desc: "horizontal split, parent and children have borders", termSize: image.Point{10, 10}, diff --git a/container/options.go b/container/options.go index 84726bc..764429f 100644 --- a/container/options.go +++ b/container/options.go @@ -313,7 +313,7 @@ func SplitPercent(p int) SplitOption { // SplitPercentFromEnd sets the relative size of the split as percentage of the // available space. // When using SplitVertical, the provided size is applied to the new right -// container, the new leftcontainer gets the reminder of the size. +// container, the new left container gets the reminder of the size. // When using SplitHorizontal, the provided size is applied to the new bottom // container, the new top container gets the reminder of the size. // The provided value must be a positive number in the range 0 < p < 100.