forked from JanDeDobbeleer/oh-my-posh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
segment_test.go
99 lines (89 loc) · 2.03 KB
/
segment_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
package main
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
const (
cwd = "Projects/oh-my-posh3"
)
func TestMapSegmentWriterCanMap(t *testing.T) {
sc := &Segment{
Type: Session,
}
env := new(MockedEnvironment)
err := sc.mapSegmentWithWriter(env)
assert.NotNil(t, sc.props)
assert.NoError(t, err)
assert.NotNil(t, sc.writer)
}
func TestMapSegmentWriterCannotMap(t *testing.T) {
sc := &Segment{
Type: "nilwriter",
}
env := new(MockedEnvironment)
err := sc.mapSegmentWithWriter(env)
assert.Nil(t, sc.props)
assert.Error(t, err)
}
func TestParseTestSettings(t *testing.T) {
segmentJSON :=
`
{
"type": "path",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#ffffff",
"background": "#61AFEF",
"properties": {
"prefix": " \uE5FF ",
"style": "folder",
"ignore_folders": [
"/super/secret/project"
]
}
}
`
segment := &Segment{}
err := json.Unmarshal([]byte(segmentJSON), segment)
assert.NoError(t, err)
cwd := "/super/secret/project"
got := segment.shouldIgnoreFolder(cwd)
assert.True(t, got)
}
func TestShouldIgnoreFolderRegex(t *testing.T) {
segment := &Segment{
Properties: map[Property]interface{}{
IgnoreFolders: []string{"Projects[\\/].*"},
},
}
got := segment.shouldIgnoreFolder(cwd)
assert.True(t, got)
}
func TestShouldIgnoreFolderRegexNonEscaped(t *testing.T) {
segment := &Segment{
Properties: map[Property]interface{}{
IgnoreFolders: []string{"Projects/.*"},
},
}
got := segment.shouldIgnoreFolder(cwd)
assert.True(t, got)
}
func TestShouldIgnoreFolderRegexInverted(t *testing.T) {
segment := &Segment{
Properties: map[Property]interface{}{
IgnoreFolders: []string{"(?!Projects[\\/]).*"},
},
}
got := segment.shouldIgnoreFolder(cwd)
assert.False(t, got)
}
func TestShouldIgnoreFolderRegexInvertedNonEscaped(t *testing.T) {
segment := &Segment{
Properties: map[Property]interface{}{
IgnoreFolders: []string{"(?!Projects/).*"},
},
}
got := segment.shouldIgnoreFolder(cwd)
assert.False(t, got)
}