Add tests, clean-up

This commit is contained in:
Matthew Coleman 2024-03-08 13:02:01 -05:00
parent 4b7343b987
commit e980c4bb2b
2 changed files with 54 additions and 2 deletions

View File

@ -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},

View File

@ -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.