2016-11-11 12:25:53 +08:00
|
|
|
// Copyright 2016 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
|
2015-03-21 04:21:50 +08:00
|
|
|
// Use of this source code is governed by a MIT license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
2015-03-20 00:00:38 +08:00
|
|
|
package termui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
|
|
)
|
|
|
|
|
2015-05-05 23:19:08 +08:00
|
|
|
var r *Row
|
2015-03-20 00:00:38 +08:00
|
|
|
|
|
|
|
func TestRowWidth(t *testing.T) {
|
2015-05-13 04:16:08 +08:00
|
|
|
p0 := NewBlock()
|
2015-03-20 00:00:38 +08:00
|
|
|
p0.Height = 1
|
2015-05-13 04:16:08 +08:00
|
|
|
p1 := NewBlock()
|
2015-03-20 00:00:38 +08:00
|
|
|
p1.Height = 1
|
2015-05-13 04:16:08 +08:00
|
|
|
p2 := NewBlock()
|
2015-03-20 00:00:38 +08:00
|
|
|
p2.Height = 1
|
2015-05-13 04:16:08 +08:00
|
|
|
p3 := NewBlock()
|
2015-03-20 00:00:38 +08:00
|
|
|
p3.Height = 1
|
|
|
|
|
|
|
|
/* test against tree:
|
|
|
|
|
|
|
|
r
|
|
|
|
/ \
|
|
|
|
0:w 1
|
|
|
|
/ \
|
|
|
|
10:w 11
|
|
|
|
/
|
|
|
|
110:w
|
|
|
|
/
|
|
|
|
1100:w
|
|
|
|
*/
|
2015-03-20 20:24:48 +08:00
|
|
|
|
|
|
|
r = NewRow(
|
|
|
|
NewCol(6, 0, p0),
|
|
|
|
NewCol(6, 0,
|
|
|
|
NewRow(
|
|
|
|
NewCol(6, 0, p1),
|
|
|
|
NewCol(6, 0, p2, p3))))
|
|
|
|
|
2015-03-20 00:00:38 +08:00
|
|
|
r.assignWidth(100)
|
|
|
|
if r.Width != 100 ||
|
|
|
|
(r.Cols[0].Width) != 50 ||
|
|
|
|
(r.Cols[1].Width) != 50 ||
|
|
|
|
(r.Cols[1].Cols[0].Width) != 25 ||
|
|
|
|
(r.Cols[1].Cols[1].Width) != 25 ||
|
|
|
|
(r.Cols[1].Cols[1].Cols[0].Width) != 25 ||
|
|
|
|
(r.Cols[1].Cols[1].Cols[0].Cols[0].Width) != 25 {
|
|
|
|
t.Error("assignWidth fails")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRowHeight(t *testing.T) {
|
|
|
|
spew.Dump()
|
2015-03-20 20:24:48 +08:00
|
|
|
|
2015-03-20 00:00:38 +08:00
|
|
|
if (r.solveHeight()) != 2 ||
|
|
|
|
(r.Cols[1].Cols[1].Height) != 2 ||
|
|
|
|
(r.Cols[1].Cols[1].Cols[0].Height) != 2 ||
|
|
|
|
(r.Cols[1].Cols[0].Height) != 1 {
|
|
|
|
t.Error("solveHeight fails")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAssignXY(t *testing.T) {
|
|
|
|
r.assignX(0)
|
|
|
|
r.assignY(0)
|
|
|
|
if (r.Cols[0].X) != 0 ||
|
|
|
|
(r.Cols[1].Cols[0].X) != 50 ||
|
|
|
|
(r.Cols[1].Cols[1].X) != 75 ||
|
|
|
|
(r.Cols[1].Cols[1].Cols[0].X) != 75 ||
|
|
|
|
(r.Cols[1].Cols[0].Y) != 0 ||
|
|
|
|
(r.Cols[1].Cols[1].Cols[0].Y) != 0 ||
|
|
|
|
(r.Cols[1].Cols[1].Cols[0].Cols[0].Y) != 1 {
|
|
|
|
t.Error("assignXY fails")
|
|
|
|
}
|
|
|
|
}
|