-
Notifications
You must be signed in to change notification settings - Fork 366
/
glow_test.go
65 lines (60 loc) · 1.07 KB
/
glow_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
package main
import (
"bytes"
"testing"
)
func TestGlowSources(t *testing.T) {
tt := []string{
".",
"README.md",
"github.com/charmbracelet/glow",
"github://charmbracelet/glow",
"https://github.com/charmbracelet/glow",
}
for _, v := range tt {
t.Run(v, func(t *testing.T) {
buf := &bytes.Buffer{}
err := executeArg(rootCmd, v, buf)
if err != nil {
t.Errorf("Error during execution (args: %s): %v", v, err)
}
if buf.Len() == 0 {
t.Errorf("Output buffer should not be empty (args: %s)", v)
}
})
}
}
func TestGlowFlags(t *testing.T) {
tt := []struct {
args []string
check func() bool
}{
{
args: []string{"-p"},
check: func() bool {
return pager
},
},
{
args: []string{"-s", "light"},
check: func() bool {
return style == "light"
},
},
{
args: []string{"-w", "40"},
check: func() bool {
return width == 40
},
},
}
for _, v := range tt {
err := rootCmd.ParseFlags(v.args)
if err != nil {
t.Fatal(err)
}
if !v.check() {
t.Errorf("Parsing flag failed: %s", v.args)
}
}
}