library/ui/ui_test.go

115 lines
2.8 KiB
Go

package ui
import (
"fmt"
"testing"
)
func TestContainerOneBox(t *testing.T) {
expect := `┌─ box one ────────┐
│ │
│ │
│ │
└──────────────────┘
`
m := &MockScreen{}
one := NewBox("box one", nil, Contents{})
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{}
one := NewBox("one", nil, Contents{})
two := NewBox("two", nil, Contents{})
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()
}
}
func TestContainerThreeBoxesUnevenHStack(t *testing.T) {
expect := `┌─ one ──┐┌─ two ──┐┌─ three
│ ││ ││ │
│ ││ ││ │
│ ││ ││ │
└────────┘└────────┘└───────┘
`
m := &MockScreen{}
one := NewBox("one", nil, Contents{})
two := NewBox("two", nil, Contents{})
three := NewBox("three", nil, Contents{})
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()
}
}
func TestContainerTwoBoxesVStack(t *testing.T) {
expect := `┌─ one ──┐
│ │
│ │
│ │
└────────┘
┌─ two ──┐
│ │
│ │
│ │
└────────┘
`
m := &MockScreen{}
one := NewBox("one", nil, Contents{})
two := NewBox("two", nil, Contents{})
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()
}
}