forked from Otann/powerline-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerline-shell_test.go
113 lines (90 loc) · 2.96 KB
/
powerline-shell_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
package main
import (
"github.com/sanyatuning/powerline-go/powerline"
"github.com/stretchr/testify/assert"
"strings"
"testing"
"time"
)
var shell = "test"
func Symbols() powerline.Symbols {
return powerline.Symbols{
Branch: "ß",
CommitsAhead: "^",
CommitsBehind: "v",
Ellipsis: "...",
Lock: "L",
NewLine: "\n",
GitDiff: "▲",
Separator: "->",
SeparatorRight: "<-",
}
}
func Test_root(t *testing.T) {
username := "root"
cwd := "/home/username/dirname"
cwdParts := strings.Split(cwd, "/")
theme := powerline.Dark()
symbols := Symbols()
p := powerline.NewPowerline(shell, symbols, theme)
builder := powerline.NewSegmentBuilder(theme, symbols)
testNow, _ := time.Parse(time.RFC3339Nano, "2013-06-05T14:10:43.678Z")
width := "80"
p.AppendLeft(builder.UserSegment(username))
p.AppendLeft(builder.HostSegment("hostname"))
p.AppendLeft(builder.PathSegment(cwdParts))
p.AppendLeft(builder.LockSegment(cwd))
p.AppendRight(builder.TimeSegment(testNow))
p.AppendDown(builder.BashSegment(username))
p.AppendDown(builder.ExitCodeSegment("0"))
rootSegments := p.PrintAll(width)
want := " root -> hostname -> /home/username/dirname -> L .R->.R <- Wed 5 14:10:43 .R\n # .R->.R "
assert.Equal(t, want, rootSegments)
}
func Test_user(t *testing.T) {
cwd := "~/dirname"
cwdParts := strings.Split(cwd, "/")
theme := powerline.Dark()
symbols := Symbols()
p := powerline.NewPowerline(shell, symbols, theme)
builder := powerline.NewSegmentBuilder(theme, symbols)
testNow, _ := time.Parse(time.RFC3339Nano, "2013-06-05T14:10:43.678Z")
width := "80"
username := "user"
p.AppendLeft(builder.UserSegment(username))
p.AppendLeft(builder.HostSegment("hostname"))
p.AppendLeft(builder.PathSegment(cwdParts))
p.AppendLeft(builder.LockSegment(cwd))
p.AppendRight(builder.TimeSegment(testNow))
p.AppendDown(builder.BashSegment(username))
p.AppendDown(builder.ExitCodeSegment("0"))
rootSegments := p.PrintAll(width)
want := " user -> hostname -> ~/dirname -> L .R->.R <- Wed 5 14:10:43 .R\n $ .R->.R "
assert.Equal(t, want, rootSegments)
}
func Test_git(t *testing.T) {
cwd := "~/dirname"
cwdParts := strings.Split(cwd, "/")
theme := powerline.Dark()
symbols := Symbols()
p := powerline.NewPowerline(shell, symbols, theme)
builder := powerline.NewSegmentBuilder(theme, symbols)
gitInfo := powerline.GitInfo{
Branch: "master",
CommitsBehind: 12,
CommitsAhead: 3,
Staged: true,
Tag: "2.0.2",
}
width := "80"
username := "user"
p.AppendLeft(builder.UserSegment(username))
p.AppendLeft(builder.HostSegment("hostname"))
p.AppendLeft(builder.PathSegment(cwdParts))
p.AppendLeft(builder.GitSegment(gitInfo))
p.AppendDown(builder.BashSegment(username))
p.AppendDown(builder.ExitCodeSegment("0"))
rootSegments := p.PrintAll(width)
want := " user -> hostname -> ~/dirname -> ß master \"2.0.2\" 12v 3^ ▲ .R->.R\n $ .R->.R "
assert.Equal(t, want, rootSegments)
}