termui/block_test.go

71 lines
1.3 KiB
Go
Raw Normal View History

2017-01-14 14:07:43 +08:00
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2016-01-27 09:45:18 +08:00
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
package termui
2018-09-07 05:48:09 +08:00
import "testing"
2015-10-13 13:00:15 +08:00
func TestBlockFloat(t *testing.T) {
Init()
defer Close()
b := NewBlock()
b.X = 10
b.Y = 20
b.Float = AlignCenter
b.Align()
}
func TestBlockInnerBounds(t *testing.T) {
Init()
defer Close()
b := NewBlock()
b.X = 10
b.Y = 11
b.Width = 12
b.Height = 13
assert := func(name string, x, y, w, h int) {
t.Log(name)
2015-05-13 20:57:11 +08:00
area := b.InnerBounds()
cx := area.Min.X
cy := area.Min.Y
cw := area.Dx()
ch := area.Dy()
2015-10-13 13:00:15 +08:00
if cx != x {
t.Errorf("expected x to be %d but got %d", x, cx)
}
if cy != y {
2015-10-13 13:00:15 +08:00
t.Errorf("expected y to be %d but got %d\n%+v", y, cy, area)
}
if cw != w {
t.Errorf("expected width to be %d but got %d", w, cw)
}
if ch != h {
t.Errorf("expected height to be %d but got %d", h, ch)
}
}
2015-05-13 20:57:11 +08:00
b.Border = false
assert("no border, no padding", 10, 11, 12, 13)
2015-05-13 20:57:11 +08:00
b.Border = true
assert("border, no padding", 11, 12, 10, 11)
b.PaddingBottom = 2
assert("border, 2b padding", 11, 12, 10, 9)
b.PaddingTop = 3
assert("border, 2b 3t padding", 11, 15, 10, 6)
b.PaddingLeft = 4
assert("border, 2b 3t 4l padding", 15, 15, 6, 6)
b.PaddingRight = 5
assert("border, 2b 3t 4l 5r padding", 15, 15, 1, 6)
}