2021-07-04 01:25:32 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestContainerOneBox(t *testing.T) {
|
|
|
|
expect := `┌─ box one ────────┐
|
|
|
|
│ │
|
|
|
|
│ │
|
|
|
|
│ │
|
|
|
|
└──────────────────┘
|
|
|
|
`
|
|
|
|
m := &MockScreen{}
|
2021-07-13 22:32:01 +00:00
|
|
|
one := NewBox("box one", nil, Contents{}, 0, false)
|
2021-07-04 01:25:32 +00:00
|
|
|
container := NewContainer(
|
|
|
|
Contents{{Container: one}},
|
|
|
|
LayoutHorizontalEven,
|
|
|
|
)
|
|
|
|
m.Init()
|
|
|
|
m.Resize(0, 0, 5, 20)
|
|
|
|
container.SetSize(0, 0, 5, 20)
|
|
|
|
container.Draw(m)
|
|
|
|
result := m.DumpContents()
|
|
|
|
if result != expect {
|
|
|
|
fmt.Printf("expected:\n%+v", expect)
|
|
|
|
fmt.Printf("actual:\n%+v", result)
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContainerTwoBoxesHStack(t *testing.T) {
|
|
|
|
expect := `┌─ one ──┐┌─ two ──┐
|
|
|
|
│ ││ │
|
|
|
|
│ ││ │
|
|
|
|
│ ││ │
|
|
|
|
└────────┘└────────┘
|
|
|
|
`
|
|
|
|
m := &MockScreen{}
|
2021-07-13 22:32:01 +00:00
|
|
|
one := NewBox("one", nil, Contents{}, 0, false)
|
|
|
|
two := NewBox("two", nil, Contents{}, 0, false)
|
2021-07-04 01:25:32 +00:00
|
|
|
container := NewContainer(
|
|
|
|
Contents{{Container: one}, {Container: two}},
|
|
|
|
LayoutHorizontalEven,
|
|
|
|
)
|
|
|
|
m.Init()
|
|
|
|
m.Resize(0, 0, 5, 20)
|
|
|
|
container.SetSize(0, 0, 5, 20)
|
|
|
|
container.Draw(m)
|
|
|
|
result := m.DumpContents()
|
|
|
|
if result != expect {
|
|
|
|
fmt.Printf("expected:\n%+v", expect)
|
|
|
|
fmt.Printf("actual:\n%+v", result)
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
2021-07-04 17:49:53 +00:00
|
|
|
|
2021-07-04 13:41:22 +00:00
|
|
|
func TestContainerThreeBoxesUnevenHStack(t *testing.T) {
|
|
|
|
expect := `┌─ one ──┐┌─ two ──┐┌─ three
|
|
|
|
│ ││ ││ │
|
|
|
|
│ ││ ││ │
|
|
|
|
│ ││ ││ │
|
|
|
|
└────────┘└────────┘└───────┘
|
|
|
|
`
|
|
|
|
m := &MockScreen{}
|
2021-07-13 22:32:01 +00:00
|
|
|
one := NewBox("one", nil, Contents{}, 0, false)
|
|
|
|
two := NewBox("two", nil, Contents{}, 0, false)
|
|
|
|
three := NewBox("three", nil, Contents{}, 0, false)
|
2021-07-04 13:41:22 +00:00
|
|
|
container := NewContainer(
|
|
|
|
Contents{{Container: one}, {Container: two}, {Container: three}},
|
|
|
|
LayoutHorizontalEven,
|
|
|
|
)
|
|
|
|
m.Init()
|
|
|
|
m.Resize(0, 0, 5, 29)
|
|
|
|
container.SetSize(0, 0, 5, 29)
|
|
|
|
container.Draw(m)
|
|
|
|
result := m.DumpContents()
|
|
|
|
if result != expect {
|
|
|
|
fmt.Printf("expected:\n%+v", expect)
|
|
|
|
fmt.Printf("actual:\n%+v", result)
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
2021-07-04 01:25:32 +00:00
|
|
|
|
2021-07-04 17:49:53 +00:00
|
|
|
func TestContainerTwoBoxesHPercentStack(t *testing.T) {
|
|
|
|
expect := `┌─ one ──────┐┌─ two ┐
|
|
|
|
│ ││ │
|
|
|
|
│ ││ │
|
|
|
|
│ ││ │
|
|
|
|
└────────────┘└──────┘
|
|
|
|
`
|
|
|
|
m := &MockScreen{}
|
2021-07-13 22:32:01 +00:00
|
|
|
one := NewBox("one", nil, Contents{}, 0, false)
|
|
|
|
two := NewBox("two", nil, Contents{}, 0, false)
|
2021-07-04 17:49:53 +00:00
|
|
|
container := NewContainer(
|
|
|
|
Contents{
|
|
|
|
{Container: one, Offsets: Offsets{Percent: 2}},
|
|
|
|
{Container: two, Offsets: Offsets{Percent: 1}}},
|
|
|
|
LayoutHorizontalPercent,
|
|
|
|
)
|
|
|
|
m.Init()
|
|
|
|
m.Resize(0, 0, 5, 22)
|
|
|
|
container.SetSize(0, 0, 5, 22)
|
|
|
|
container.Draw(m)
|
|
|
|
result := m.DumpContents()
|
|
|
|
if result != expect {
|
|
|
|
fmt.Printf("expected:\n%+v", expect)
|
|
|
|
fmt.Printf("actual:\n%+v", result)
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-04 01:25:32 +00:00
|
|
|
func TestContainerTwoBoxesVStack(t *testing.T) {
|
|
|
|
expect := `┌─ one ──┐
|
|
|
|
│ │
|
|
|
|
│ │
|
|
|
|
│ │
|
|
|
|
└────────┘
|
|
|
|
┌─ two ──┐
|
|
|
|
│ │
|
|
|
|
│ │
|
|
|
|
│ │
|
|
|
|
└────────┘
|
|
|
|
`
|
|
|
|
m := &MockScreen{}
|
2021-07-13 22:32:01 +00:00
|
|
|
one := NewBox("one", nil, Contents{}, 0, false)
|
|
|
|
two := NewBox("two", nil, Contents{}, 0, false)
|
2021-07-04 01:25:32 +00:00
|
|
|
container := NewContainer(
|
|
|
|
Contents{{Container: one}, {Container: two}},
|
|
|
|
LayoutVerticalEven,
|
|
|
|
)
|
|
|
|
m.Init()
|
|
|
|
m.Resize(0, 0, 10, 10)
|
|
|
|
container.SetSize(0, 0, 10, 10)
|
|
|
|
container.Draw(m)
|
|
|
|
result := m.DumpContents()
|
|
|
|
if result != expect {
|
|
|
|
fmt.Printf("expected:\n%+v", expect)
|
|
|
|
fmt.Printf("actual:\n%+v", result)
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
2021-07-04 17:49:53 +00:00
|
|
|
|
|
|
|
func TestContainerTwoBoxesPercentageVStack(t *testing.T) {
|
|
|
|
expect := `┌─ one ──┐
|
|
|
|
│ │
|
|
|
|
│ │
|
|
|
|
│ │
|
|
|
|
│ │
|
|
|
|
└────────┘
|
|
|
|
┌─ two ──┐
|
|
|
|
│ │
|
|
|
|
│ │
|
|
|
|
└────────┘
|
|
|
|
`
|
|
|
|
m := &MockScreen{}
|
2021-07-13 22:32:01 +00:00
|
|
|
one := NewBox("one", nil, Contents{}, 0, false)
|
|
|
|
two := NewBox("two", nil, Contents{}, 0, false)
|
2021-07-04 17:49:53 +00:00
|
|
|
container := NewContainer(
|
|
|
|
Contents{
|
|
|
|
{Container: one, Offsets: Offsets{Percent: 2}},
|
|
|
|
{Container: two, Offsets: Offsets{Percent: 1}}},
|
|
|
|
LayoutVerticalPercent,
|
|
|
|
)
|
|
|
|
m.Init()
|
|
|
|
m.Resize(0, 0, 10, 10)
|
|
|
|
container.SetSize(0, 0, 10, 10)
|
|
|
|
container.Draw(m)
|
|
|
|
result := m.DumpContents()
|
|
|
|
if result != expect {
|
|
|
|
fmt.Printf("expected:\n%+v", expect)
|
|
|
|
fmt.Printf("actual:\n%+v", result)
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|