forked from cheggaaa/pb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpb_test.go
More file actions
58 lines (51 loc) · 1.09 KB
/
Copy pathpb_test.go
File metadata and controls
58 lines (51 loc) · 1.09 KB
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
package pb
import (
"strings"
"testing"
"github.com/fatih/color"
"github.com/mattn/go-colorable"
)
func Test_IncrementAddsOne(t *testing.T) {
count := 5000
bar := New(count)
expected := 1
actual := bar.Increment()
if actual != expected {
t.Errorf("Expected {%d} was {%d}", expected, actual)
}
}
func Test_Width(t *testing.T) {
count := 5000
bar := New(count)
width := 100
bar.SetWidth(100).Callback = func(out string) {
if len(out) != width {
t.Errorf("Bar width expected {%d} was {%d}", len(out), width)
}
}
bar.Start()
bar.Increment()
bar.Finish()
}
func Test_MultipleFinish(t *testing.T) {
bar := New(5000)
bar.Add(2000)
bar.Finish()
bar.Finish()
}
func Test_Format(t *testing.T) {
bar := New(5000).Format(strings.Join([]string{
color.GreenString("["),
color.New(color.BgGreen).SprintFunc()("o"),
color.New(color.BgHiGreen).SprintFunc()("o"),
color.New(color.BgRed).SprintFunc()("o"),
color.GreenString("]"),
}, "\x00"))
w := colorable.NewColorableStdout()
bar.Callback = func(out string) {
w.Write([]byte(out))
}
bar.Add(2000)
bar.Finish()
bar.Finish()
}