-
Notifications
You must be signed in to change notification settings - Fork 27
/
multibar_test.go
73 lines (60 loc) · 1.83 KB
/
multibar_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
package multibar
import (
"testing"
"github.com/sethgrid/curse"
)
func TestNewLineDetection_EmptyPrintln(t *testing.T) {
bc := &BarContainer{}
bc.Println()
expected := 1
resetLines(expected)
if bc.historicNewlinesCounter != expected {
t.Errorf("empty Println - got %d, want %d newline", bc.historicNewlinesCounter, expected)
}
}
func TestNewLineDetection_Println(t *testing.T) {
bc := &BarContainer{}
bc.Println("Look, ma!\n I printed somethin'\n")
expected := 3
resetLines(expected)
if bc.historicNewlinesCounter != expected {
t.Errorf("Println - got %d, want %d newline", bc.historicNewlinesCounter, expected)
}
}
func TestNewLineDetection_Printf(t *testing.T) {
bc := &BarContainer{}
bc.Printf("Look, ma!\n I printed somethin'\n %s %s", "and\n", "\nI can keep printing")
expected := 4
resetLines(expected)
if bc.historicNewlinesCounter != expected {
t.Errorf("Printf - got %d, want %d newline", bc.historicNewlinesCounter, expected)
}
}
func TestNewLineDetection_Print(t *testing.T) {
bc := &BarContainer{}
bc.Print("Look, ma!\n I printed somethin'\n", "and\n", "\nI can keep printing")
expected := 4
resetLines(expected)
if bc.historicNewlinesCounter != expected {
t.Errorf("Print - got %d, want %d newline", bc.historicNewlinesCounter, expected)
}
}
func TestNewLineDetection_ManyPrints(t *testing.T) {
bc := &BarContainer{}
bc.Print("Look, ma!\n I printed somethin'\n", "and\n", "\nI can keep printing")
bc.Println("and more!")
expected := 5
resetLines(expected)
if bc.historicNewlinesCounter != expected {
t.Errorf("Print - got %d, want %d newline", bc.historicNewlinesCounter, expected)
}
}
// resetLines erases the print output and resets the cursor to the pre-print line
func resetLines(n int) {
c := &curse.Cursor{}
for i := 0; i < n; i++ {
c.EraseCurrentLine()
c.MoveUp(1)
}
c.EraseCurrentLine()
}