oh-my-posh/segment_test.go
2020-10-05 17:19:05 +02:00

56 lines
1 KiB
Go
Executable file

package main
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMapSegmentWriterCanMap(t *testing.T) {
sc := &Segment{
Type: Session,
}
env := new(MockedEnvironment)
props, err := sc.mapSegmentWithWriter(env)
assert.NotNil(t, props)
assert.NoError(t, err)
assert.NotNil(t, sc.writer)
}
func TestMapSegmentWriterCannotMap(t *testing.T) {
sc := &Segment{
Type: "nilwriter",
}
env := new(MockedEnvironment)
props, err := sc.mapSegmentWithWriter(env)
assert.Nil(t, props)
assert.Error(t, err)
}
func TestParseTestSettings(t *testing.T) {
segmentJSON :=
`
{
"type": "path",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#ffffff",
"background": "#61AFEF",
"properties": {
"prefix": "  ",
"style": "folder",
"ignore_folders": [
"go-my-psh"
]
}
}
`
segment := &Segment{}
err := json.Unmarshal([]byte(segmentJSON), segment)
assert.NoError(t, err)
expected := "go-my-psh"
got := segment.hasValue(IgnoreFolders, expected)
assert.True(t, got)
}