106 lines
4.7 KiB
Gleam
106 lines
4.7 KiB
Gleam
import gleam/dict
|
|
import gleam/io
|
|
import gleam/string
|
|
import gleeunit
|
|
import gleeunit/should
|
|
import musicplayer/ui/virtual_ansi
|
|
|
|
import musicplayer/ui/layout.{Layout, Percent, Section, Style}
|
|
|
|
pub fn main() -> Nil {
|
|
gleeunit.main()
|
|
}
|
|
|
|
pub fn percent_layout_test() {
|
|
let layout =
|
|
Layout(
|
|
width: 80,
|
|
height: 20,
|
|
nodes: dict.from_list([
|
|
#(
|
|
layout.Root,
|
|
layout.Row(
|
|
content: "container",
|
|
style: Style(dimensions: Percent(width: 100, height: 100)),
|
|
children: [
|
|
Section("Row1"),
|
|
Section("Row2"),
|
|
],
|
|
),
|
|
),
|
|
#(
|
|
Section("Row1"),
|
|
layout.Row(
|
|
content: "row 1",
|
|
style: Style(dimensions: Percent(width: 100, height: 50)),
|
|
children: [
|
|
Section("A"),
|
|
Section("B"),
|
|
],
|
|
),
|
|
),
|
|
#(
|
|
Section("A"),
|
|
layout.Cell(
|
|
content: "cell 1",
|
|
style: Style(dimensions: Percent(width: 50, height: 100)),
|
|
),
|
|
),
|
|
#(
|
|
Section("B"),
|
|
layout.Cell(
|
|
content: "cell 2",
|
|
style: Style(dimensions: Percent(width: 50, height: 100)),
|
|
),
|
|
),
|
|
#(
|
|
Section("Row2"),
|
|
layout.Row(
|
|
content: "row 1",
|
|
style: Style(dimensions: Percent(width: 100, height: 50)),
|
|
children: [],
|
|
),
|
|
),
|
|
]),
|
|
)
|
|
|
|
let expected =
|
|
"
|
|
container──────────────────────────────────────────────────────────────────────┐
|
|
│row 1────────────────────────────────────────────────────────────────────────┐│
|
|
││cell 1───────────────────────────────┐cell 2───────────────────────────────┐││
|
|
│││ ││ │││
|
|
│││ ││ │││
|
|
│││ ││ │││
|
|
│││ ││ │││
|
|
│││ ││ │││
|
|
││└────────────────────────────────────┘└────────────────────────────────────┘││
|
|
│└────────────────────────────────────────────────────────────────────────────┘│
|
|
│row 1────────────────────────────────────────────────────────────────────────┐│
|
|
││ ││
|
|
││ ││
|
|
││ ││
|
|
││ ││
|
|
││ ││
|
|
││ ││
|
|
││ ││
|
|
│└────────────────────────────────────────────────────────────────────────────┘│
|
|
└──────────────────────────────────────────────────────────────────────────────┘
|
|
"
|
|
|
|
let visual = virtual_ansi.render(layout)
|
|
case visual == string.trim(expected) {
|
|
True -> Nil
|
|
False -> {
|
|
io.println("Test failed")
|
|
io.println("Expected:")
|
|
io.println(string.trim(expected))
|
|
|
|
io.println("Got:")
|
|
io.println(visual)
|
|
|
|
should.equal(visual, expected)
|
|
}
|
|
}
|
|
}
|