forked from gizak/termui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid_test.go
98 lines (86 loc) · 1.86 KB
/
grid_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2015 Zack Guo <[email protected]>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
package termui
import (
"testing"
"github.com/davecgh/go-spew/spew"
)
var r *row
func TestRowWidth(t *testing.T) {
p0 := NewPar("p0")
p0.Height = 1
p1 := NewPar("p1")
p1.Height = 1
p2 := NewPar("p2")
p2.Height = 1
p3 := NewPar("p3")
p3.Height = 1
/* test against tree:
r
/ \
0:w 1
/ \
10:w 11
/
110:w
/
1100:w
*/
/*
r = &row{
Span: 12,
Cols: []*row{
&row{Widget: p0, Span: 6},
&row{
Span: 6,
Cols: []*row{
&row{Widget: p1, Span: 6},
&row{
Span: 6,
Cols: []*row{
&row{
Span: 12,
Widget: p2,
Cols: []*row{
&row{Span: 12, Widget: p3}}}}}}}}}
*/
r = NewRow(
NewCol(6, 0, p0),
NewCol(6, 0,
NewRow(
NewCol(6, 0, p1),
NewCol(6, 0, p2, p3))))
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()
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")
}
}