-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils_test.go
131 lines (115 loc) · 3.17 KB
/
utils_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package tvxwidgets_test
import (
"github.com/gdamore/tcell/v2"
"github.com/navidys/tvxwidgets"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/rivo/tview"
)
var _ = Describe("Utils", func() {
Describe("getColorName", func() {
It("returns color name", func() {
tests := []struct {
color tcell.Color
colorName string
}{
{color: tcell.ColorWhite, colorName: "white"},
{color: tcell.ColorBlack, colorName: "black"},
{color: tcell.NewRGBColor(0, 1, 2), colorName: ""},
}
for _, test := range tests {
Expect(tvxwidgets.GetColorName(test.color)).To(Equal(test.colorName))
}
})
})
Describe("getMessageWidth", func() {
It("returns width size for dialogs based on messages", func() {
tests := []struct {
msg string
width int
}{
{msg: "test", width: 4},
{msg: "test01\ntest001", width: 7},
{msg: "", width: 0},
}
for _, test := range tests {
Expect(tvxwidgets.GetMessageWidth(test.msg)).To(Equal(test.width))
}
})
})
Describe("getMaxFloat64From2dSlice", func() {
It("returns max values in 2D float64 slices.", func() {
tests := []struct {
have [][]float64
wants float64
}{
{have: [][]float64{}, wants: 0},
{have: [][]float64{
{5, -1, 0, -10, 12},
{15, -11, 0, -110, 22},
}, wants: 22},
{have: [][]float64{
{-5, -1, -2, -10, -12},
{-15, -11, -1, -110, -22},
}, wants: -1},
}
for _, test := range tests {
Expect(tvxwidgets.GetMaxFloat64From2dSlice(test.have)).To(Equal(test.wants))
}
})
})
Describe("getMaxFloat64FromSlice", func() {
It("returns max values in float64 slices", func() {
tests := []struct {
have []float64
wants float64
}{
{have: []float64{}, wants: 0},
{have: []float64{5, -1, 0, -10, 12}, wants: 12},
{have: []float64{-10, -20, -9, -1}, wants: -1},
}
for _, test := range tests {
Expect(tvxwidgets.GetMaxFloat64FromSlice(test.have)).To(Equal(test.wants))
}
})
})
Describe("absInt", func() {
It("return absint", func() {
tests := []struct {
have int
wants int
}{
{have: 2, wants: 2},
{have: -2, wants: 2},
{have: 0, wants: 0},
}
for _, test := range tests {
Expect(tvxwidgets.AbsInt(test.have)).To(Equal(test.wants))
}
})
})
Describe("drawLine", func() {
It("draws horizontal or vertival line on screen", func() {
screen := tcell.NewSimulationScreen("UTF-8")
screenWidth := 70
screenHeight := 30
lineStartX := 0
lineStartY := 0
lineLenght := 20
screen.SetSize(screenWidth, screenHeight)
screen.Init()
screen.Clear()
// draw and test horizental line
tvxwidgets.DrawLine(screen, lineStartX, lineStartY, lineLenght, 0, tcell.StyleDefault)
screen.Show()
cellRune, _, _, _ := screen.GetContent(lineStartX, lineStartY)
Expect(cellRune).To(Equal(tview.BoxDrawingsLightTripleDashHorizontal))
// draw and test vertical line
screen.Clear()
tvxwidgets.DrawLine(screen, lineStartX, lineStartY, lineLenght, 1, tcell.StyleDefault)
screen.Show()
cellRune, _, _, _ = screen.GetContent(lineStartX, lineStartY)
Expect(cellRune).To(Equal(tview.BoxDrawingsLightTripleDashVertical))
})
})
})