termui/pos_test.go

39 lines
889 B
Go
Raw Normal View History

2017-01-14 06:07:43 +00:00
// Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
2016-01-27 01:45:18 +00:00
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
2015-10-13 05:00:15 +00:00
package termui
import (
"image"
"testing"
)
func TestAlignArea(t *testing.T) {
p := image.Rect(0, 0, 100, 100)
c := image.Rect(10, 10, 20, 20)
nc := AlignArea(p, c, AlignLeft)
if nc.Min.X != 0 || nc.Max.Y != 20 {
t.Errorf("AlignLeft failed:\n%+v", nc)
}
nc = AlignArea(p, c, AlignCenter)
if nc.Min.X != 45 || nc.Max.Y != 55 {
t.Error("AlignCenter failed")
}
nc = AlignArea(p, c, AlignBottom|AlignRight)
if nc.Min.X != 90 || nc.Max.Y != 100 {
t.Errorf("AlignBottom|AlignRight failed\n%+v", nc)
}
}
func TestMoveArea(t *testing.T) {
a := image.Rect(10, 10, 20, 20)
a = MoveArea(a, 5, 10)
if a.Min.X != 15 || a.Min.Y != 20 || a.Max.X != 25 || a.Max.Y != 30 {
t.Error("MoveArea failed")
}
}