forked from mitchellh/ioprogress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_test.go
72 lines (62 loc) · 1.2 KB
/
draw_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
package ioprogress
import (
"bytes"
"testing"
)
func TestDrawTerminal(t *testing.T) {
var buf bytes.Buffer
fn := DrawTerminal(&buf)
if err := fn(0, 100); err != nil {
t.Fatalf("err: %s", err)
}
if err := fn(20, 100); err != nil {
t.Fatalf("err: %s", err)
}
if err := fn(-1, -1); err != nil {
t.Fatalf("err: %s", err)
}
if buf.String() != drawTerminalStr {
t.Fatalf("bad:\n\n%#v", buf.String())
}
}
func TestDrawTextFormatBar(t *testing.T) {
var actual, expected string
f := DrawTextFormatBar(10)
actual = f(5, 10)
expected = "[==== ]"
if actual != expected {
t.Fatalf("bad: %s", actual)
}
actual = f(2, 10)
expected = "[= ]"
if actual != expected {
t.Fatalf("bad: %s", actual)
}
actual = f(10, 10)
expected = "[========]"
if actual != expected {
t.Fatalf("bad: %s", actual)
}
}
func TestDrawTextFormatBytes(t *testing.T) {
cases := []struct {
P, T int64
Output string
}{
{
100, 500,
"100 B/500 B",
},
{
1500, 5000,
"1.5 KB/5 KB",
},
}
for _, tc := range cases {
output := DrawTextFormatBytes(tc.P, tc.T)
if output != tc.Output {
t.Fatalf("Input: %d, %d\n\n%s", tc.P, tc.T, output)
}
}
}
const drawTerminalStr = "0/100\r20/100\r\n"