refactor: move properties to interface

This commit is contained in:
Jan De Dobbeleer 2022-01-01 20:08:08 +01:00 committed by Jan De Dobbeleer
parent e8f1e5e2d4
commit 29e019511a
88 changed files with 283 additions and 233 deletions

View file

@ -48,7 +48,7 @@ func (n *new) string() string {
return text
}
func (n *new) init(props properties, env environmentInfo) {
func (n *new) init(props Properties, env environmentInfo) {
n.props = props
n.env = env
}

View file

@ -188,7 +188,7 @@ func getDefaultConfig(info string) *Config {
PowerlineSymbol: "\uE0B0",
Background: "#ff479c",
Foreground: "#ffffff",
Properties: map[Property]interface{}{
Properties: properties{
Prefix: " \uE5FF ",
Style: "folder",
},
@ -199,7 +199,7 @@ func getDefaultConfig(info string) *Config {
PowerlineSymbol: "\uE0B0",
Background: "#fffb38",
Foreground: "#193549",
Properties: map[Property]interface{}{
Properties: properties{
FetchStashCount: true,
FetchUpstreamIcon: true,
},
@ -210,7 +210,7 @@ func getDefaultConfig(info string) *Config {
PowerlineSymbol: "\uE0B0",
Background: "#f36943",
Foreground: "#193549",
Properties: map[Property]interface{}{
Properties: properties{
ColorBackground: true,
ChargedColor: "#4caf50",
ChargingColor: "#40c4ff",
@ -224,7 +224,7 @@ func getDefaultConfig(info string) *Config {
PowerlineSymbol: "\uE0B0",
Background: "#6CA35E",
Foreground: "#ffffff",
Properties: map[Property]interface{}{
Properties: properties{
Prefix: " \uE718",
FetchVersion: false,
},
@ -235,7 +235,7 @@ func getDefaultConfig(info string) *Config {
PowerlineSymbol: "\uE0B0",
Background: "#0077c2",
Foreground: "#ffffff",
Properties: map[Property]interface{}{
Properties: properties{
Prefix: " \uFCB5 ",
},
},
@ -252,7 +252,7 @@ func getDefaultConfig(info string) *Config {
PowerlineSymbol: "\uE0B0",
Background: "#ffffff",
Foreground: "#111111",
Properties: map[Property]interface{}{
Properties: properties{
TextProperty: info,
},
},
@ -263,7 +263,7 @@ func getDefaultConfig(info string) *Config {
Foreground: "#ffffff",
LeadingDiamond: "<transparent,#2e9599>\uE0B0</>",
TrailingDiamond: "\uE0B4",
Properties: map[Property]interface{}{
Properties: properties{
DisplayExitCode: false,
AlwaysEnabled: true,
ErrorColor: "#f1184c",

View file

@ -12,101 +12,101 @@ const (
)
func TestGetString(t *testing.T) {
var properties properties = map[Property]interface{}{TextProperty: expected}
var properties properties = properties{TextProperty: expected}
value := properties.getString(TextProperty, "err")
assert.Equal(t, expected, value)
}
func TestGetStringNoEntry(t *testing.T) {
var properties properties = map[Property]interface{}{}
var properties properties = properties{}
value := properties.getString(TextProperty, expected)
assert.Equal(t, expected, value)
}
func TestGetStringNoTextEntry(t *testing.T) {
var properties properties = map[Property]interface{}{TextProperty: true}
var properties properties = properties{TextProperty: true}
value := properties.getString(TextProperty, expected)
assert.Equal(t, expected, value)
}
func TestGetHexColor(t *testing.T) {
expected := expectedColor
var properties properties = map[Property]interface{}{UserColor: expected}
var properties properties = properties{UserColor: expected}
value := properties.getColor(UserColor, "#789123")
assert.Equal(t, expected, value)
}
func TestGetColor(t *testing.T) {
expected := "yellow"
var properties properties = map[Property]interface{}{UserColor: expected}
var properties properties = properties{UserColor: expected}
value := properties.getColor(UserColor, "#789123")
assert.Equal(t, expected, value)
}
func TestDefaultColorWithInvalidColorCode(t *testing.T) {
expected := expectedColor
var properties properties = map[Property]interface{}{UserColor: "invalid"}
var properties properties = properties{UserColor: "invalid"}
value := properties.getColor(UserColor, expected)
assert.Equal(t, expected, value)
}
func TestDefaultColorWithUnavailableProperty(t *testing.T) {
expected := expectedColor
var properties properties = map[Property]interface{}{}
var properties properties = properties{}
value := properties.getColor(UserColor, expected)
assert.Equal(t, expected, value)
}
func TestGetPaletteColor(t *testing.T) {
expected := "p:red"
var properties properties = map[Property]interface{}{Background: expected}
var properties properties = properties{Background: expected}
value := properties.getColor(Background, "white")
assert.Equal(t, expected, value)
}
func TestGetBool(t *testing.T) {
expected := true
var properties properties = map[Property]interface{}{DisplayHost: expected}
var properties properties = properties{DisplayHost: expected}
value := properties.getBool(DisplayHost, false)
assert.True(t, value)
}
func TestGetBoolPropertyNotInMap(t *testing.T) {
var properties properties = map[Property]interface{}{}
var properties properties = properties{}
value := properties.getBool(DisplayHost, false)
assert.False(t, value)
}
func TestGetBoolInvalidProperty(t *testing.T) {
var properties properties = map[Property]interface{}{DisplayHost: "borked"}
var properties properties = properties{DisplayHost: "borked"}
value := properties.getBool(DisplayHost, false)
assert.False(t, value)
}
func TestGetFloat64(t *testing.T) {
expected := float64(1337)
var properties properties = map[Property]interface{}{"myfloat": expected}
var properties properties = properties{"myfloat": expected}
value := properties.getFloat64("myfloat", 9001)
assert.Equal(t, expected, value)
}
func TestGetFloat64PropertyNotInMap(t *testing.T) {
expected := float64(1337)
var properties properties = map[Property]interface{}{}
var properties properties = properties{}
value := properties.getFloat64(ThresholdProperty, expected)
assert.Equal(t, expected, value)
}
func TestGetFloat64InvalidStringProperty(t *testing.T) {
expected := float64(1337)
var properties properties = map[Property]interface{}{ThresholdProperty: "invalid"}
var properties properties = properties{ThresholdProperty: "invalid"}
value := properties.getFloat64(ThresholdProperty, expected)
assert.Equal(t, expected, value)
}
func TestGetFloat64InvalidBoolProperty(t *testing.T) {
expected := float64(1337)
var properties properties = map[Property]interface{}{ThresholdProperty: true}
var properties properties = properties{ThresholdProperty: true}
value := properties.getFloat64(ThresholdProperty, expected)
assert.Equal(t, expected, value)
}

View file

@ -35,7 +35,7 @@ func (s *ScmStatus) String() string {
}
type scm struct {
props properties
props Properties
env environmentInfo
}
@ -48,7 +48,7 @@ const (
FullBranchPath Property = "full_branch_path"
)
func (s *scm) init(props properties, env environmentInfo) {
func (s *scm) init(props Properties, env environmentInfo) {
s.props = props
s.env = env
}
@ -68,11 +68,10 @@ func (s *scm) truncateBranch(branch string) string {
}
func (s *scm) shouldIgnoreRootRepository(rootDir string) bool {
value, ok := s.props[ExcludeFolders]
if !ok {
excludedFolders := s.props.getStringArray(ExcludeFolders, []string{})
if len(excludedFolders) == 0 {
return false
}
excludedFolders := parseStringArray(value)
return dirMatchesOneOf(s.env, rootDir, excludedFolders)
}

View file

@ -104,7 +104,7 @@ func TestTruncateBranch(t *testing.T) {
}
for _, tc := range cases {
var props properties = map[Property]interface{}{
props := properties{
BranchMaxLength: tc.MaxLength,
FullBranchPath: tc.FullBranch,
}
@ -140,7 +140,7 @@ func TestTruncateBranchWithSymbol(t *testing.T) {
}
for _, tc := range cases {
var props properties = map[Property]interface{}{
props := properties{
BranchMaxLength: tc.MaxLength,
TruncateSymbol: tc.TruncateSymbol,
FullBranchPath: tc.FullBranch,
@ -167,7 +167,7 @@ func TestScmShouldIgnoreRootRepository(t *testing.T) {
}
for _, tc := range cases {
var props properties = map[Property]interface{}{
props := properties{
ExcludeFolders: []string{
"/home/bill",
"/home/gates.*",

View file

@ -37,11 +37,26 @@ type SegmentTiming struct {
stringDuration time.Duration
}
type Properties interface {
getColor(property Property, defaultColor string) string
getBool(property Property, defaultValue bool) bool
getString(property Property, defaultValue string) string
getFloat64(property Property, defaultValue float64) float64
getInt(property Property, defaultValue int) int
getKeyValueMap(property Property, defaultValue map[string]string) map[string]string
getStringArray(property Property, defaultValue []string) []string
// for legacy purposes
getOneOfBool(property, legacyProperty Property, defaultValue bool) bool
getOneOfString(property, legacyProperty Property, defaultValue string) string
hasOneOf(properties ...Property) bool
set(property Property, value interface{})
}
// SegmentWriter is the interface used to define what and if to write to the prompt
type SegmentWriter interface {
enabled() bool
string() string
init(props properties, env environmentInfo)
init(props Properties, env environmentInfo)
}
// SegmentStyle the syle of segment, for more information, see the constants

View file

@ -13,7 +13,7 @@ func (a *angular) string() string {
return a.language.string()
}
func (a *angular) init(props properties, env environmentInfo) {
func (a *angular) init(props Properties, env environmentInfo) {
a.language = language{
env: env,
props: props,

View file

@ -30,7 +30,7 @@ func TestAngularCliVersionDisplayed(t *testing.T) {
env.On("hasFilesInDir", "/usr/home/dev/my-app/node_modules/@angular/core", "package.json").Return(true)
env.On("getFileContent", "/usr/home/dev/my-app/node_modules/@angular/core/package.json").Return(ta.Version)
var props properties = map[Property]interface{}{}
props := properties{}
angular := &angular{}
angular.init(props, env)
assert.True(t, angular.enabled(), fmt.Sprintf("Failed in case: %s", ta.Case))

View file

@ -6,7 +6,7 @@ import (
)
type aws struct {
props properties
props Properties
env environmentInfo
Profile string
Region string
@ -16,7 +16,7 @@ const (
defaultUser = "default"
)
func (a *aws) init(props properties, env environmentInfo) {
func (a *aws) init(props Properties, env environmentInfo) {
a.props = props
a.env = env
}

View file

@ -54,7 +54,7 @@ func TestAWSSegment(t *testing.T) {
env.On("getenv", "AWS_CONFIG_FILE").Return(tc.ConfigFile)
env.On("getFileContent", "/usr/home/.aws/config").Return("")
env.On("homeDir", nil).Return("/usr/home")
var props properties = map[Property]interface{}{
props := properties{
DisplayDefault: tc.DisplayDefault,
}
if tc.Template != "" {

View file

@ -7,7 +7,7 @@ import (
)
type az struct {
props properties
props Properties
env environmentInfo
AzureSubscription
@ -91,7 +91,7 @@ func (a *az) string() string {
return text
}
func (a *az) init(props properties, env environmentInfo) {
func (a *az) init(props Properties, env environmentInfo) {
a.props = props
a.env = env
}

View file

@ -8,7 +8,7 @@ func (az *azfunc) string() string {
return az.language.string()
}
func (az *azfunc) init(props properties, env environmentInfo) {
func (az *azfunc) init(props Properties, env environmentInfo) {
az.language = language{
env: env,
props: props,

View file

@ -60,7 +60,7 @@ func TestAzSegment(t *testing.T) {
env.On("getFileContent", filepath.Join(home, ".azure/azureProfile.json")).Return(azureProfile)
env.On("getFileContent", filepath.Join(home, ".azure/AzureRmContext.json")).Return(azureRmContext)
var props properties = map[Property]interface{}{
props := properties{
SegmentTemplate: tc.Template,
}
az := &az{

View file

@ -7,7 +7,7 @@ import (
)
type batt struct {
props properties
props Properties
env environmentInfo
battery.Battery
@ -118,7 +118,7 @@ func (b *batt) string() string {
return text
}
func (b *batt) init(props properties, env environmentInfo) {
func (b *batt) init(props Properties, env environmentInfo) {
b.props = props
b.env = env
}

View file

@ -13,7 +13,7 @@ import (
// segment struct, makes templating easier
type brewfather struct {
props properties
props Properties
env environmentInfo
Batch
@ -335,7 +335,7 @@ func (bf *brewfather) SGToPlato(sg float64) float64 {
return math.Round(100*((135.997*sg*sg*sg)-(630.272*sg*sg)+(1111.14*sg)-616.868)) / 100 // 2 decimal places
}
func (bf *brewfather) init(props properties, env environmentInfo) {
func (bf *brewfather) init(props Properties, env environmentInfo) {
bf.props = props
bf.env = env
}

View file

@ -137,7 +137,7 @@ func TestBrewfatherSegment(t *testing.T) {
for _, tc := range cases {
env := &MockedEnvironment{}
var props properties = map[Property]interface{}{
props := properties{
CacheTimeout: tc.CacheTimeout,
BFBatchID: BFFakeBatchID,
BFAPIKey: "FAKE",

View file

@ -3,7 +3,7 @@ package main
import "strings"
type command struct {
props properties
props Properties
env environmentInfo
value string
}
@ -48,7 +48,7 @@ func (c *command) string() string {
return c.value
}
func (c *command) init(props properties, env environmentInfo) {
func (c *command) init(props Properties, env environmentInfo) {
c.props = props
c.env = env
}

View file

@ -14,7 +14,7 @@ func TestExecuteCommand(t *testing.T) {
env.init(&args{
Debug: &debug,
})
var props properties = map[Property]interface{}{
props := properties{
Command: "echo hello",
}
c := &command{
@ -32,7 +32,7 @@ func TestExecuteMultipleCommandsOrFirst(t *testing.T) {
env.init(&args{
Debug: &debug,
})
var props properties = map[Property]interface{}{
props := properties{
Command: "exit 1 || echo hello",
}
c := &command{
@ -50,7 +50,7 @@ func TestExecuteMultipleCommandsOrSecond(t *testing.T) {
env.init(&args{
Debug: &debug,
})
var props properties = map[Property]interface{}{
props := properties{
Command: "echo hello || echo world",
}
c := &command{
@ -68,7 +68,7 @@ func TestExecuteMultipleCommandsAnd(t *testing.T) {
env.init(&args{
Debug: &debug,
})
var props properties = map[Property]interface{}{
props := properties{
Command: "echo hello && echo world",
}
c := &command{
@ -86,7 +86,7 @@ func TestExecuteSingleCommandEmpty(t *testing.T) {
env.init(&args{
Debug: &debug,
})
var props properties = map[Property]interface{}{
props := properties{
Command: "",
}
c := &command{
@ -119,7 +119,7 @@ func TestExecuteMultipleCommandsAndDisabled(t *testing.T) {
env.init(&args{
Debug: &debug,
})
var props properties = map[Property]interface{}{
props := properties{
Command: "echo && echo",
}
c := &command{
@ -136,7 +136,7 @@ func TestExecuteMultipleCommandsOrDisabled(t *testing.T) {
env.init(&args{
Debug: &debug,
})
var props properties = map[Property]interface{}{
props := properties{
Command: "echo|| echo",
}
c := &command{

View file

@ -8,7 +8,7 @@ func (c *crystal) string() string {
return c.language.string()
}
func (c *crystal) init(props properties, env environmentInfo) {
func (c *crystal) init(props Properties, env environmentInfo) {
c.language = language{
env: env,
props: props,

View file

@ -8,7 +8,7 @@ func (d *dart) string() string {
return d.language.string()
}
func (d *dart) init(props properties, env environmentInfo) {
func (d *dart) init(props Properties, env environmentInfo) {
d.language = language{
env: env,
props: props,

View file

@ -42,6 +42,10 @@ func (p properties) hasOneOf(properties ...Property) bool {
return false
}
func (p properties) set(property Property, value interface{}) {
p[property] = value
}
// GIT Segement
const (
@ -117,9 +121,9 @@ func (g *git) deprecatedString(statusColorsEnabled bool) string {
func (g *git) SetStatusColor() {
if g.props.getBool(ColorBackground, true) {
g.props[BackgroundOverride] = g.getStatusColor(g.props.getColor(BackgroundOverride, ""))
g.props.set(BackgroundOverride, g.getStatusColor(g.props.getColor(BackgroundOverride, "")))
} else {
g.props[ForegroundOverride] = g.getStatusColor(g.props.getColor(ForegroundOverride, ""))
g.props.set(ForegroundOverride, g.getStatusColor(g.props.getColor(ForegroundOverride, "")))
}
}
@ -178,10 +182,10 @@ const (
func (e *exit) deprecatedString() string {
colorBackground := e.props.getBool(ColorBackground, false)
if e.Code != 0 && !colorBackground {
e.props[ForegroundOverride] = e.props.getColor(ErrorColor, e.props.getColor(ForegroundOverride, ""))
e.props.set(ForegroundOverride, e.props.getColor(ErrorColor, e.props.getColor(ForegroundOverride, "")))
}
if e.Code != 0 && colorBackground {
e.props[BackgroundOverride] = e.props.getColor(ErrorColor, e.props.getColor(BackgroundOverride, ""))
e.props.set(BackgroundOverride, e.props.getColor(ErrorColor, e.props.getColor(BackgroundOverride, "")))
}
if e.Code == 0 {
return e.props.getString(SuccessIcon, "")
@ -228,9 +232,9 @@ func (b *batt) colorSegment() {
}
colorBackground := b.props.getBool(ColorBackground, false)
if colorBackground {
b.props[BackgroundOverride] = b.props.getColor(colorProperty, b.props.getColor(BackgroundOverride, ""))
b.props.set(BackgroundOverride, b.props.getColor(colorProperty, b.props.getColor(BackgroundOverride, "")))
} else {
b.props[ForegroundOverride] = b.props.getColor(colorProperty, b.props.getColor(ForegroundOverride, ""))
b.props.set(ForegroundOverride, b.props.getColor(colorProperty, b.props.getColor(ForegroundOverride, "")))
}
}
@ -383,10 +387,10 @@ func (l *language) string() string {
func (l *language) colorMismatch() {
if l.props.getBool(ColorBackground, false) {
l.props[BackgroundOverride] = l.props.getColor(VersionMismatchColor, l.props.getColor(BackgroundOverride, ""))
l.props.set(BackgroundOverride, l.props.getColor(VersionMismatchColor, l.props.getColor(BackgroundOverride, "")))
return
}
l.props[ForegroundOverride] = l.props.getColor(VersionMismatchColor, l.props.getColor(ForegroundOverride, ""))
l.props.set(ForegroundOverride, l.props.getColor(VersionMismatchColor, l.props.getColor(ForegroundOverride, "")))
}
// Python
@ -417,7 +421,7 @@ const (
// Environment Variable
type envvar struct {
props properties
props Properties
env environmentInfo
Value string
}
@ -450,7 +454,7 @@ func (e *envvar) string() string {
return text
}
func (e *envvar) init(props properties, env environmentInfo) {
func (e *envvar) init(props Properties, env environmentInfo) {
e.props = props
e.env = env
}

View file

@ -17,7 +17,11 @@ func TestGetStatusDetailStringDefault(t *testing.T) {
Added: 1,
},
}
g := &git{}
g := &git{
scm: scm{
props: properties{},
},
}
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
}
@ -28,7 +32,7 @@ func TestGetStatusDetailStringDefaultColorOverride(t *testing.T) {
Added: 1,
},
}
var props properties = map[Property]interface{}{
props := properties{
WorkingColor: "#123456",
}
g := &git{
@ -46,7 +50,7 @@ func TestGetStatusDetailStringDefaultColorOverrideAndIconColorOverride(t *testin
Added: 1,
},
}
var props properties = map[Property]interface{}{
props := properties{
WorkingColor: "#123456",
LocalWorkingIcon: "<#789123>work</>",
}
@ -65,7 +69,7 @@ func TestGetStatusDetailStringDefaultColorOverrideNoIconColorOverride(t *testing
Added: 1,
},
}
var props properties = map[Property]interface{}{
props := properties{
WorkingColor: "#123456",
LocalWorkingIcon: "work",
}
@ -84,7 +88,7 @@ func TestGetStatusDetailStringNoStatus(t *testing.T) {
Added: 1,
},
}
var props properties = map[Property]interface{}{
props := properties{
DisplayStatusDetail: false,
}
g := &git{
@ -102,7 +106,7 @@ func TestGetStatusDetailStringNoStatusColorOverride(t *testing.T) {
Added: 1,
},
}
var props properties = map[Property]interface{}{
props := properties{
DisplayStatusDetail: false,
WorkingColor: "#123456",
}
@ -116,7 +120,7 @@ func TestGetStatusDetailStringNoStatusColorOverride(t *testing.T) {
func TestGetStatusColorLocalChangesStaging(t *testing.T) {
expected := changesColor
var props properties = map[Property]interface{}{
props := properties{
LocalChangesColor: expected,
}
g := &git{
@ -135,7 +139,7 @@ func TestGetStatusColorLocalChangesStaging(t *testing.T) {
func TestGetStatusColorLocalChangesWorking(t *testing.T) {
expected := changesColor
var props properties = map[Property]interface{}{
props := properties{
LocalChangesColor: expected,
}
g := &git{
@ -154,7 +158,7 @@ func TestGetStatusColorLocalChangesWorking(t *testing.T) {
func TestGetStatusColorAheadAndBehind(t *testing.T) {
expected := changesColor
var props properties = map[Property]interface{}{
props := properties{
AheadAndBehindColor: expected,
}
g := &git{
@ -171,7 +175,7 @@ func TestGetStatusColorAheadAndBehind(t *testing.T) {
func TestGetStatusColorAhead(t *testing.T) {
expected := changesColor
var props properties = map[Property]interface{}{
props := properties{
AheadColor: expected,
}
g := &git{
@ -188,7 +192,7 @@ func TestGetStatusColorAhead(t *testing.T) {
func TestGetStatusColorBehind(t *testing.T) {
expected := changesColor
var props properties = map[Property]interface{}{
props := properties{
BehindColor: expected,
}
g := &git{
@ -205,7 +209,7 @@ func TestGetStatusColorBehind(t *testing.T) {
func TestGetStatusColorDefault(t *testing.T) {
expected := changesColor
var props properties = map[Property]interface{}{
props := properties{
BehindColor: changesColor,
}
g := &git{
@ -222,7 +226,7 @@ func TestGetStatusColorDefault(t *testing.T) {
func TestSetStatusColorForeground(t *testing.T) {
expected := changesColor
var props properties = map[Property]interface{}{
props := properties{
LocalChangesColor: changesColor,
ColorBackground: false,
}
@ -238,12 +242,12 @@ func TestSetStatusColorForeground(t *testing.T) {
Working: &GitStatus{},
}
g.SetStatusColor()
assert.Equal(t, expected, g.props[ForegroundOverride])
assert.Equal(t, expected, g.props.getColor(ForegroundOverride, ""))
}
func TestSetStatusColorBackground(t *testing.T) {
expected := changesColor
var props properties = map[Property]interface{}{
props := properties{
LocalChangesColor: changesColor,
ColorBackground: true,
}
@ -259,7 +263,7 @@ func TestSetStatusColorBackground(t *testing.T) {
},
}
g.SetStatusColor()
assert.Equal(t, expected, g.props[BackgroundOverride])
assert.Equal(t, expected, g.props.getColor(BackgroundOverride, ""))
}
func TestStatusColorsWithoutDisplayStatus(t *testing.T) {
@ -279,21 +283,22 @@ func TestStatusColorsWithoutDisplayStatus(t *testing.T) {
env.On("hasFilesInDir", "", "sequencer/todo").Return(false)
env.mockGitCommand("", "describe", "--tags", "--exact-match")
env.mockGitCommand(status, "status", "-unormal", "--branch", "--porcelain=2")
props := properties{
DisplayStatus: false,
StatusColorsEnabled: true,
LocalChangesColor: expected,
}
g := &git{
scm: scm{
env: env,
props: map[Property]interface{}{
DisplayStatus: false,
StatusColorsEnabled: true,
LocalChangesColor: expected,
},
env: env,
props: props,
},
gitWorkingFolder: "",
}
g.Working = &GitStatus{}
g.Staging = &GitStatus{}
g.string()
assert.Equal(t, expected, g.props[BackgroundOverride])
assert.Equal(t, expected, g.props.getColor(BackgroundOverride, ""))
}
// EXIT Segement
@ -320,7 +325,7 @@ func TestExitWriterDeprecatedString(t *testing.T) {
for _, tc := range cases {
env := new(MockedEnvironment)
env.On("lastErrorCode", nil).Return(tc.ExitCode)
var props properties = map[Property]interface{}{
props := properties{
SuccessIcon: tc.SuccessIcon,
ErrorIcon: tc.ErrorIcon,
DisplayExitCode: tc.DisplayExitCode,
@ -424,7 +429,7 @@ func TestBatterySegmentSingle(t *testing.T) {
for _, tc := range cases {
env := &MockedEnvironment{}
var props properties = map[Property]interface{}{
props := properties{
ChargingIcon: "charging ",
ChargedIcon: "charged ",
DischargingIcon: "going down ",
@ -455,9 +460,9 @@ func TestBatterySegmentSingle(t *testing.T) {
if len(tc.ExpectedColor) == 0 {
continue
}
actualColor := b.props[ForegroundOverride]
actualColor := b.props.getColor(ForegroundOverride, "")
if tc.ColorBackground {
actualColor = b.props[BackgroundOverride]
actualColor = b.props.getColor(BackgroundOverride, "")
}
assert.Equal(t, tc.ExpectedColor, actualColor, tc.Case)
}
@ -637,7 +642,7 @@ func TestPropertySessionSegment(t *testing.T) {
env.On("getenv", "SSH_CLIENT").Return(SSHSession)
env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserNameEnv)
env.On("isRunningAsRoot", nil).Return(tc.Root)
var props properties = map[Property]interface{}{
props := properties{
UserInfoSeparator: " at ",
SSHIcon: "ssh ",
DefaultUserName: tc.DefaultUserName,
@ -674,7 +679,7 @@ func TestLanguageVersionMismatch(t *testing.T) {
{Case: "No mismatch", Enabled: true, Mismatch: false},
}
for _, tc := range cases {
props := map[Property]interface{}{
props := properties{
EnableVersionMismatch: tc.Enabled,
VersionMismatchColor: tc.ExpectedColor,
ColorBackground: tc.ColorBackground,
@ -709,7 +714,7 @@ func TestLanguageVersionMismatch(t *testing.T) {
assert.True(t, lang.enabled(), tc.Case)
assert.Equal(t, universion, lang.string(), tc.Case)
if tc.ColorBackground {
assert.Equal(t, tc.ExpectedColor, lang.props[BackgroundOverride], tc.Case)
assert.Equal(t, tc.ExpectedColor, lang.props.getColor(BackgroundOverride, ""), tc.Case)
return
}
assert.Equal(t, tc.ExpectedColor, lang.props.getColor(ForegroundOverride, ""), tc.Case)
@ -751,7 +756,7 @@ func TestPythonVirtualEnv(t *testing.T) {
env.On("getPathSeperator", nil).Return("")
env.On("getcwd", nil).Return("/usr/home/project")
env.On("homeDir", nil).Return("/usr/home")
var props properties = map[Property]interface{}{
props := properties{
FetchVersion: tc.FetchVersion,
DisplayVirtualEnv: true,
DisplayDefault: tc.DisplayDefault,
@ -772,7 +777,7 @@ func TestEnvvarAvailable(t *testing.T) {
env.On("getenv", name).Return(expected)
e := &envvar{
env: env,
props: map[Property]interface{}{
props: properties{
VarName: name,
},
}
@ -787,7 +792,7 @@ func TestEnvvarNotAvailable(t *testing.T) {
env.On("getenv", name).Return(expected)
e := &envvar{
env: env,
props: map[Property]interface{}{
props: properties{
VarName: name,
},
}

View file

@ -21,7 +21,7 @@ func (d *dotnet) string() string {
return version
}
func (d *dotnet) init(props properties, env environmentInfo) {
func (d *dotnet) init(props Properties, env environmentInfo) {
d.language = language{
env: env,
props: props,

View file

@ -28,7 +28,7 @@ func bootStrapDotnetTest(args *dotnetArgs) *dotnet {
env.On("getPathSeperator", nil).Return("")
env.On("getcwd", nil).Return("/usr/home/project")
env.On("homeDir", nil).Return("/usr/home")
var props properties = map[Property]interface{}{
props := properties{
FetchVersion: args.displayVersion,
UnsupportedDotnetVersionIcon: args.unsupportedIcon,
}

View file

@ -9,7 +9,7 @@ import (
)
type executiontime struct {
props properties
props Properties
env environmentInfo
FormattedMs string
@ -63,7 +63,7 @@ func (t *executiontime) string() string {
return t.FormattedMs
}
func (t *executiontime) init(props properties, env environmentInfo) {
func (t *executiontime) init(props Properties, env environmentInfo) {
t.props = props
t.env = env
}

View file

@ -11,7 +11,8 @@ func TestExecutionTimeWriterDefaultThresholdEnabled(t *testing.T) {
env := new(MockedEnvironment)
env.On("executionTime", nil).Return(1337)
executionTime := &executiontime{
env: env,
env: env,
props: properties{},
}
assert.True(t, executionTime.enabled())
}
@ -20,7 +21,8 @@ func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) {
env := new(MockedEnvironment)
env.On("executionTime", nil).Return(1)
executionTime := &executiontime{
env: env,
env: env,
props: properties{},
}
assert.False(t, executionTime.enabled())
}
@ -28,7 +30,7 @@ func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) {
func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
env := new(MockedEnvironment)
env.On("executionTime", nil).Return(99)
var props properties = map[Property]interface{}{
props := properties{
ThresholdProperty: float64(10),
}
executionTime := &executiontime{
@ -41,7 +43,7 @@ func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
func TestExecutionTimeWriterCustomThresholdDisabled(t *testing.T) {
env := new(MockedEnvironment)
env.On("executionTime", nil).Return(99)
var props properties = map[Property]interface{}{
props := properties{
ThresholdProperty: float64(100),
}
executionTime := &executiontime{
@ -57,7 +59,8 @@ func TestExecutionTimeWriterDuration(t *testing.T) {
env := new(MockedEnvironment)
env.On("executionTime", nil).Return(input)
executionTime := &executiontime{
env: env,
env: env,
props: properties{},
}
executionTime.enabled()
assert.Equal(t, expected, executionTime.FormattedMs)
@ -69,7 +72,8 @@ func TestExecutionTimeWriterDuration2(t *testing.T) {
env := new(MockedEnvironment)
env.On("executionTime", nil).Return(input)
executionTime := &executiontime{
env: env,
env: env,
props: properties{},
}
executionTime.enabled()
assert.Equal(t, expected, executionTime.FormattedMs)

View file

@ -3,7 +3,7 @@ package main
import "strconv"
type exit struct {
props properties
props Properties
env environmentInfo
Code int
@ -21,7 +21,7 @@ func (e *exit) string() string {
return e.getFormattedText()
}
func (e *exit) init(props properties, env environmentInfo) {
func (e *exit) init(props Properties, env environmentInfo) {
e.props = props
e.env = env
}

View file

@ -20,7 +20,8 @@ func TestExitWriterEnabled(t *testing.T) {
env := new(MockedEnvironment)
env.On("lastErrorCode", nil).Return(tc.ExitCode)
e := &exit{
env: env,
env: env,
props: properties{},
}
assert.Equal(t, tc.Expected, e.enabled())
}
@ -76,7 +77,7 @@ func TestExitWriterTemplateString(t *testing.T) {
for _, tc := range cases {
env := new(MockedEnvironment)
env.On("lastErrorCode", nil).Return(tc.ExitCode)
var props properties = map[Property]interface{}{
props := properties{
SegmentTemplate: tc.Template,
}
e := &exit{

View file

@ -21,7 +21,8 @@ func TestEnabledGitNotFound(t *testing.T) {
env.On("isWsl", nil).Return(false)
g := &git{
scm: scm{
env: env,
env: env,
props: properties{},
},
}
assert.False(t, g.enabled())
@ -41,7 +42,8 @@ func TestEnabledInWorkingDirectory(t *testing.T) {
env.On("hasParentFilePath", ".git").Return(fileInfo, nil)
g := &git{
scm: scm{
env: env,
env: env,
props: properties{},
},
}
assert.True(t, g.enabled())
@ -64,7 +66,8 @@ func TestEnabledInWorkingTree(t *testing.T) {
env.On("getFileContent", "/dev/real_folder/.git/worktrees/folder_worktree/gitdir").Return("/dev/folder_worktree.git\n")
g := &git{
scm: scm{
env: env,
env: env,
props: properties{},
},
}
assert.True(t, g.enabled())
@ -88,7 +91,8 @@ func TestEnabledInSubmodule(t *testing.T) {
env.On("getFileContent", "/dev/parent/.git/modules/test-submodule").Return("/dev/folder_worktree.git\n")
g := &git{
scm: scm{
env: env,
env: env,
props: properties{},
},
}
assert.True(t, g.enabled())
@ -107,7 +111,8 @@ func TestGetGitOutputForCommand(t *testing.T) {
env.On("getRuntimeGOOS", nil).Return("unix")
g := &git{
scm: scm{
env: env,
env: env,
props: properties{},
},
}
got := g.getGitCommandOutput(commandArgs...)
@ -256,7 +261,7 @@ func TestSetGitHEADContextClean(t *testing.T) {
g := &git{
scm: scm{
env: env,
props: map[Property]interface{}{
props: properties{
BranchIcon: "branch ",
CommitIcon: "commit ",
RebaseIcon: "rebase ",
@ -298,7 +303,7 @@ func TestSetPrettyHEADName(t *testing.T) {
g := &git{
scm: scm{
env: env,
props: map[Property]interface{}{
props: properties{
BranchIcon: "branch ",
CommitIcon: "commit ",
TagIcon: "tag ",
@ -476,7 +481,7 @@ func TestGitUpstream(t *testing.T) {
env.On("runCommand", "git", []string{"-C", "", "--no-optional-locks", "-c", "core.quotepath=false",
"-c", "color.status=false", "remote", "get-url", "origin"}).Return(tc.Upstream, nil)
env.On("getRuntimeGOOS", nil).Return("unix")
var props properties = map[Property]interface{}{
props := properties{
GithubIcon: "GH",
GitlabIcon: "GL",
BitbucketIcon: "BB",
@ -512,7 +517,7 @@ func TestGetBranchStatus(t *testing.T) {
}
for _, tc := range cases {
var props properties = map[Property]interface{}{
props := properties{
BranchAheadIcon: "up",
BranchBehindIcon: "down",
BranchIdenticalIcon: "equal",
@ -544,7 +549,7 @@ func TestShouldIgnoreRootRepository(t *testing.T) {
}
for _, tc := range cases {
var props properties = map[Property]interface{}{
props := properties{
ExcludeFolders: []string{
"/home/bill",
"/home/gates.*",
@ -730,7 +735,7 @@ func TestGitTemplateString(t *testing.T) {
}
for _, tc := range cases {
var props properties = map[Property]interface{}{
props := properties{
FetchStatus: true,
}
tc.Git.props = props

View file

@ -16,7 +16,7 @@ func (g *golang) string() string {
return g.language.string()
}
func (g *golang) init(props properties, env environmentInfo) {
func (g *golang) init(props Properties, env environmentInfo) {
g.language = language{
env: env,
props: props,

View file

@ -23,7 +23,7 @@ func getMockedLanguageEnv(params *mockedLanguageParams) (*MockedEnvironment, pro
env.On("hasFiles", params.extension).Return(true)
env.On("getcwd", nil).Return("/usr/home/project")
env.On("homeDir", nil).Return("/usr/home")
var props properties = map[Property]interface{}{
props := properties{
FetchVersion: true,
}
return env, props

View file

@ -1,7 +1,7 @@
package main
type ipify struct {
props properties
props Properties
env environmentInfo
IP string
}
@ -66,7 +66,7 @@ func (i *ipify) getResult() (string, error) {
return response, nil
}
func (i *ipify) init(props properties, env environmentInfo) {
func (i *ipify) init(props Properties, env environmentInfo) {
i.props = props
i.env = env
}

View file

@ -43,7 +43,7 @@ func TestIpifySegment(t *testing.T) {
for _, tc := range cases {
env := &MockedEnvironment{}
var props properties = map[Property]interface{}{
props := properties{
CacheTimeout: 0,
}

View file

@ -10,7 +10,7 @@ func (j *java) string() string {
return j.language.string()
}
func (j *java) init(props properties, env environmentInfo) {
func (j *java) init(props Properties, env environmentInfo) {
javaRegex := `(?: JRE)(?: \(.*\))? \((?P<version>(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?(?:\.(?P<patch>[0-9]+))?).*\),`
javaCmd := &cmd{
executable: "java",

View file

@ -66,7 +66,7 @@ func TestJava(t *testing.T) {
} else {
env.On("getenv", "JAVA_HOME").Return("")
}
var props properties = map[Property]interface{}{
props := properties{
FetchVersion: true,
}
j := &java{}

View file

@ -8,7 +8,7 @@ func (j *julia) string() string {
return j.language.string()
}
func (j *julia) init(props properties, env environmentInfo) {
func (j *julia) init(props Properties, env environmentInfo) {
j.language = language{
env: env,
props: props,

View file

@ -10,7 +10,7 @@ import (
const ParseKubeConfig Property = "parse_kubeconfig"
type kubectl struct {
props properties
props Properties
env environmentInfo
Context string
KubeContext
@ -44,7 +44,7 @@ func (k *kubectl) string() string {
return text
}
func (k *kubectl) init(props properties, env environmentInfo) {
func (k *kubectl) init(props Properties, env environmentInfo) {
k.props = props
k.env = env
}

View file

@ -128,7 +128,7 @@ func TestKubectlSegment(t *testing.T) {
k := &kubectl{
env: env,
props: map[Property]interface{}{
props: properties{
SegmentTemplate: tc.Template,
DisplayError: tc.DisplayError,
ParseKubeConfig: tc.ParseKubeConfig,

View file

@ -47,7 +47,7 @@ func (c *cmd) parse(versionInfo string) (*version, error) {
}
type language struct {
props properties
props Properties
env environmentInfo
extensions []string
commands []*cmd

View file

@ -20,7 +20,7 @@ type languageArgs struct {
enabledCommands []string
versionURLTemplate string
expectedError error
properties map[Property]interface{}
properties Properties
matchesVersionFile matchesVersionFile
inHome bool
}
@ -50,6 +50,9 @@ func bootStrapLanguageTest(args *languageArgs) *language {
}
env.On("getcwd", nil).Return(cwd)
env.On("homeDir", nil).Return(home)
if args.properties == nil {
args.properties = properties{}
}
l := &language{
props: args.properties,
env: env,
@ -78,7 +81,7 @@ func TestLanguageFilesFoundButNoCommandAndVersionAndDisplayVersion(t *testing.T)
}
func TestLanguageFilesFoundButNoCommandAndVersionAndDontDisplayVersion(t *testing.T) {
props := map[Property]interface{}{
props := properties{
FetchVersion: false,
}
args := &languageArgs{
@ -228,7 +231,7 @@ func TestLanguageEnabledAllExtensionsFound(t *testing.T) {
}
func TestLanguageEnabledNoVersion(t *testing.T) {
props := map[Property]interface{}{
props := properties{
FetchVersion: false,
}
args := &languageArgs{
@ -251,7 +254,7 @@ func TestLanguageEnabledNoVersion(t *testing.T) {
}
func TestLanguageEnabledMissingCommand(t *testing.T) {
props := map[Property]interface{}{
props := properties{
FetchVersion: false,
}
args := &languageArgs{
@ -268,7 +271,7 @@ func TestLanguageEnabledMissingCommand(t *testing.T) {
}
func TestLanguageEnabledNoVersionData(t *testing.T) {
props := map[Property]interface{}{
props := properties{
FetchVersion: true,
}
args := &languageArgs{
@ -292,7 +295,7 @@ func TestLanguageEnabledNoVersionData(t *testing.T) {
func TestLanguageEnabledMissingCommandCustomText(t *testing.T) {
expected := "missing"
props := map[Property]interface{}{
props := properties{
MissingCommandText: expected,
}
args := &languageArgs{
@ -309,7 +312,7 @@ func TestLanguageEnabledMissingCommandCustomText(t *testing.T) {
}
func TestLanguageEnabledMissingCommandCustomTextHideError(t *testing.T) {
props := map[Property]interface{}{
props := properties{
MissingCommandText: "missing",
DisplayError: false,
}
@ -349,7 +352,7 @@ func TestLanguageEnabledCommandExitCode(t *testing.T) {
}
func TestLanguageHyperlinkEnabled(t *testing.T) {
props := map[Property]interface{}{
props := properties{
EnableHyperlink: true,
}
args := &languageArgs{
@ -378,7 +381,7 @@ func TestLanguageHyperlinkEnabled(t *testing.T) {
}
func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) {
props := map[Property]interface{}{
props := properties{
EnableHyperlink: true,
}
args := &languageArgs{
@ -407,7 +410,7 @@ func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) {
}
func TestLanguageHyperlinkEnabledLessParamInTemplate(t *testing.T) {
props := map[Property]interface{}{
props := properties{
EnableHyperlink: true,
}
args := &languageArgs{
@ -445,7 +448,7 @@ func TestLanguageEnabledInHome(t *testing.T) {
{Case: "Context disabled", HomeEnabled: false, ExpectedEnabled: false},
}
for _, tc := range cases {
props := map[Property]interface{}{
props := properties{
HomeEnabled: tc.HomeEnabled,
}
args := &languageArgs{
@ -469,7 +472,7 @@ func TestLanguageEnabledInHome(t *testing.T) {
}
func TestLanguageHyperlinkEnabledMoreParamInTemplate(t *testing.T) {
props := map[Property]interface{}{
props := properties{
EnableHyperlink: true,
}
args := &languageArgs{

View file

@ -5,7 +5,7 @@ import (
)
type nbgv struct {
props properties
props Properties
env environmentInfo
nbgv *versionInfo
}
@ -52,7 +52,7 @@ func (n *nbgv) string() string {
return text
}
func (n *nbgv) init(props properties, env environmentInfo) {
func (n *nbgv) init(props Properties, env environmentInfo) {
n.props = props
n.env = env
}

View file

@ -62,7 +62,7 @@ func TestNbgv(t *testing.T) {
env.On("runCommand", "nbgv", []string{"get-version", "--format=json"}).Return(tc.Response, tc.Error)
nbgv := &nbgv{
env: env,
props: map[Property]interface{}{
props: properties{
SegmentTemplate: tc.SegmentTemplate,
},
}

View file

@ -8,7 +8,7 @@ import (
// segment struct, makes templating easier
type nightscout struct {
props properties
props Properties
env environmentInfo
NightscoutData
@ -148,7 +148,7 @@ func (ns *nightscout) getResult() (*NightscoutData, error) {
return data, nil
}
func (ns *nightscout) init(props properties, env environmentInfo) {
func (ns *nightscout) init(props Properties, env environmentInfo) {
ns.props = props
ns.env = env
}

View file

@ -130,7 +130,7 @@ func TestNSSegment(t *testing.T) {
for _, tc := range cases {
env := &MockedEnvironment{}
var props properties = map[Property]interface{}{
props := properties{
CacheTimeout: tc.CacheTimeout,
URL: "FAKE",
}

View file

@ -26,7 +26,7 @@ func (n *node) string() string {
return n.language.renderTemplate(segmentTemplate, n)
}
func (n *node) init(props properties, env environmentInfo) {
func (n *node) init(props Properties, env environmentInfo) {
n.language = language{
env: env,
props: props,

View file

@ -67,7 +67,7 @@ func TestNodeInContext(t *testing.T) {
node := &node{
language: language{
env: env,
props: map[Property]interface{}{
props: properties{
YarnIcon: "yarn",
NPMIcon: "npm",
DisplayPackageManager: tc.PkgMgrEnabled,

View file

@ -5,7 +5,7 @@ import (
)
type osInfo struct {
props properties
props Properties
env environmentInfo
OS string
}
@ -145,7 +145,7 @@ func (n *osInfo) getDistroName(distro, defaultName string) string {
return n.props.getString(Linux, "\uF17C")
}
func (n *osInfo) init(props properties, env environmentInfo) {
func (n *osInfo) init(props Properties, env environmentInfo) {
n.props = props
n.env = env
}

View file

@ -66,7 +66,7 @@ func TestOSInfo(t *testing.T) {
env.On("getPlatform", nil).Return(tc.Platform)
osInfo := &osInfo{
env: env,
props: map[Property]interface{}{
props: properties{
WSL: "WSL",
WSLSeparator: " at ",
DisplayDistroName: tc.DisplayDistroName,

View file

@ -7,7 +7,7 @@ import (
)
type owm struct {
props properties
props Properties
env environmentInfo
Temperature float64
Weather string
@ -173,7 +173,7 @@ func (d *owm) setStatus() error {
return nil
}
func (d *owm) init(props properties, env environmentInfo) {
func (d *owm) init(props Properties, env environmentInfo) {
d.props = props
d.env = env
}

View file

@ -51,7 +51,7 @@ func TestOWMSegmentSingle(t *testing.T) {
for _, tc := range cases {
env := &MockedEnvironment{}
var props properties = map[Property]interface{}{
props := properties{
APIKey: "key",
Location: "AMSTERDAM,NL",
Units: "metric",
@ -187,7 +187,7 @@ func TestOWMSegmentIcons(t *testing.T) {
env.On("doGet", OWMAPIURL).Return([]byte(response), nil)
o := &owm{
props: map[Property]interface{}{
props: properties{
APIKey: "key",
Location: "AMSTERDAM,NL",
Units: "metric",
@ -210,7 +210,7 @@ func TestOWMSegmentIcons(t *testing.T) {
env.On("doGet", OWMAPIURL).Return([]byte(response), nil)
o := &owm{
props: map[Property]interface{}{
props: properties{
APIKey: "key",
Location: "AMSTERDAM,NL",
Units: "metric",
@ -232,7 +232,7 @@ func TestOWMSegmentFromCache(t *testing.T) {
env := &MockedEnvironment{}
cache := &MockedCache{}
o := &owm{
props: map[Property]interface{}{
props: properties{
APIKey: "key",
Location: "AMSTERDAM,NL",
Units: "metric",
@ -256,7 +256,7 @@ func TestOWMSegmentFromCacheWithHyperlink(t *testing.T) {
cache := &MockedCache{}
o := &owm{
props: map[Property]interface{}{
props: properties{
APIKey: "key",
Location: "AMSTERDAM,NL",
Units: "metric",

View file

@ -8,7 +8,7 @@ import (
)
type path struct {
props properties
props Properties
env environmentInfo
PWD string
@ -112,7 +112,7 @@ func (pt *path) formatWindowsDrive(pwd string) string {
return pwd + "\\"
}
func (pt *path) init(props properties, env environmentInfo) {
func (pt *path) init(props Properties, env environmentInfo) {
pt.props = props
pt.env = env
}

View file

@ -267,7 +267,7 @@ func TestRootLocationHome(t *testing.T) {
env.On("getRuntimeGOOS", nil).Return("")
path := &path{
env: env,
props: map[Property]interface{}{
props: properties{
HomeIcon: tc.HomeIcon,
WindowsRegistryIcon: tc.RegistryIcon,
},
@ -419,7 +419,7 @@ func TestAgnosterPathStyles(t *testing.T) {
env.On("getArgs", nil).Return(args)
path := &path{
env: env,
props: map[Property]interface{}{
props: properties{
FolderSeparatorIcon: tc.FolderSeparatorIcon,
Style: tc.Style,
MaxDepth: tc.MaxDepth,
@ -540,7 +540,7 @@ func TestGetFullPath(t *testing.T) {
if len(tc.Template) == 0 {
tc.Template = "{{ if gt .StackCount 0 }}{{ .StackCount }} {{ end }}{{ .Path }}"
}
var props properties = map[Property]interface{}{
props := properties{
Style: tc.Style,
SegmentTemplate: tc.Template,
}
@ -588,7 +588,7 @@ func TestGetFullPathCustomMappedLocations(t *testing.T) {
env.On("getArgs", nil).Return(args)
path := &path{
env: env,
props: map[Property]interface{}{
props: properties{
MappedLocationsEnabled: false,
MappedLocations: tc.MappedLocations,
},
@ -639,7 +639,7 @@ func TestGetFolderPathCustomMappedLocations(t *testing.T) {
env.On("getArgs", nil).Return(args)
path := &path{
env: env,
props: map[Property]interface{}{
props: properties{
MappedLocations: map[string]string{
"/a/b/c/d": "#",
},
@ -686,7 +686,7 @@ func TestAgnosterPath(t *testing.T) { // nolint:dupl
env.On("getArgs", nil).Return(args)
path := &path{
env: env,
props: map[Property]interface{}{
props: properties{
FolderSeparatorIcon: " > ",
FolderIcon: "f",
HomeIcon: "~",
@ -734,7 +734,7 @@ func TestAgnosterLeftPath(t *testing.T) { // nolint:dupl
env.On("getArgs", nil).Return(args)
path := &path{
env: env,
props: map[Property]interface{}{
props: properties{
FolderSeparatorIcon: " > ",
FolderIcon: "f",
HomeIcon: "~",
@ -782,7 +782,7 @@ func TestGetPwd(t *testing.T) {
env.On("getArgs", nil).Return(args)
path := &path{
env: env,
props: map[Property]interface{}{
props: properties{
MappedLocationsEnabled: tc.MappedLocationsEnabled,
MappedLocations: map[string]string{
"/a/b/c/d": "#",

View file

@ -8,7 +8,7 @@ func (n *php) string() string {
return n.language.string()
}
func (n *php) init(props properties, env environmentInfo) {
func (n *php) init(props Properties, env environmentInfo) {
n.language = language{
env: env,
props: props,

View file

@ -34,7 +34,7 @@ type plastic struct {
plasticWorkspaceFolder string // root folder of workspace
}
func (p *plastic) init(props properties, env environmentInfo) {
func (p *plastic) init(props Properties, env environmentInfo) {
p.props = props
p.env = env
}

View file

@ -13,7 +13,8 @@ func TestPlasticEnabledNotFound(t *testing.T) {
env.On("isWsl", nil).Return(false)
p := &plastic{
scm: scm{
env: env,
env: env,
props: properties{},
},
}
assert.False(t, p.enabled())
@ -32,7 +33,8 @@ func TestPlasticEnabledInWorkspaceDirectory(t *testing.T) {
env.On("hasParentFilePath", ".plastic").Return(fileInfo, nil)
p := &plastic{
scm: scm{
env: env,
env: env,
props: properties{},
},
}
assert.True(t, p.enabled())
@ -45,7 +47,8 @@ func setupCmStatusEnv(status, headStatus string) *plastic {
env.On("runCommand", "cm", []string{"status", "--head", "--machinereadable"}).Return(headStatus, nil)
p := &plastic{
scm: scm{
env: env,
env: env,
props: properties{},
},
}
return p
@ -321,7 +324,7 @@ func TestPlasticTemplateString(t *testing.T) {
}
for _, tc := range cases {
var props properties = map[Property]interface{}{
props := properties{
FetchStatus: true,
}
tc.Plastic.props = props

View file

@ -3,7 +3,7 @@ package main
import "strings"
type poshgit struct {
props properties
props Properties
env environmentInfo
gitStatus string
}
@ -22,7 +22,7 @@ func (p *poshgit) string() string {
return p.gitStatus
}
func (p *poshgit) init(props properties, env environmentInfo) {
func (p *poshgit) init(props Properties, env environmentInfo) {
p.props = props
p.env = env
}

View file

@ -19,7 +19,7 @@ func (p *python) string() string {
return p.language.renderTemplate(segmentTemplate, p)
}
func (p *python) init(props properties, env environmentInfo) {
func (p *python) init(props Properties, env environmentInfo) {
p.language = language{
env: env,
props: props,

View file

@ -52,7 +52,7 @@ func TestPythonTemplate(t *testing.T) {
env.On("getPathSeperator", nil).Return("")
env.On("getcwd", nil).Return("/usr/home/project")
env.On("homeDir", nil).Return("/usr/home")
var props properties = map[Property]interface{}{
props := properties{
FetchVersion: tc.FetchVersion,
SegmentTemplate: tc.Template,
DisplayMode: DisplayModeAlways,
@ -81,7 +81,7 @@ func TestPythonPythonInContext(t *testing.T) {
env.On("getenv", "CONDA_DEFAULT_ENV").Return("")
env.On("getenv", "PYENV_VERSION").Return("")
python := &python{}
python.init(nil, env)
python.init(properties{}, env)
python.loadContext()
assert.Equal(t, tc.Expected, python.inContext())
}

View file

@ -1,7 +1,7 @@
package main
type root struct {
props properties
props Properties
env environmentInfo
}
@ -18,7 +18,7 @@ func (rt *root) string() string {
return rt.props.getString(RootIcon, "\uF0E7")
}
func (rt *root) init(props properties, env environmentInfo) {
func (rt *root) init(props Properties, env environmentInfo) {
rt.props = props
rt.env = env
}

View file

@ -13,7 +13,7 @@ func (r *ruby) string() string {
return version
}
func (r *ruby) init(props properties, env environmentInfo) {
func (r *ruby) init(props Properties, env environmentInfo) {
r.language = language{
env: env,
props: props,

View file

@ -98,7 +98,7 @@ func TestRuby(t *testing.T) {
env.On("hasFiles", "Gemfile").Return(tc.HasGemFile)
env.On("getcwd", nil).Return("/usr/home/project")
env.On("homeDir", nil).Return("/usr/home")
var props properties = map[Property]interface{}{
props := properties{
FetchVersion: tc.FetchVersion,
}
ruby := &ruby{}

View file

@ -8,7 +8,7 @@ func (r *rust) string() string {
return r.language.string()
}
func (r *rust) init(props properties, env environmentInfo) {
func (r *rust) init(props Properties, env environmentInfo) {
r.language = language{
env: env,
props: props,

View file

@ -3,7 +3,7 @@ package main
import "strings"
type session struct {
props properties
props Properties
env environmentInfo
text string
@ -45,7 +45,7 @@ func (s *session) string() string {
return s.getFormattedText()
}
func (s *session) init(props properties, env environmentInfo) {
func (s *session) init(props Properties, env environmentInfo) {
s.props = props
s.env = env
}

View file

@ -109,7 +109,7 @@ func TestSessionSegmentTemplate(t *testing.T) {
env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserName)
session := &session{
env: env,
props: map[Property]interface{}{
props: properties{
SegmentTemplate: tc.Template,
},
}

View file

@ -3,7 +3,7 @@ package main
import "strings"
type shell struct {
props properties
props Properties
env environmentInfo
}
@ -28,7 +28,7 @@ func (s *shell) string() string {
return shellName
}
func (s *shell) init(props properties, env environmentInfo) {
func (s *shell) init(props Properties, env environmentInfo) {
s.props = props
s.env = env
}

View file

@ -11,7 +11,8 @@ func TestWriteCurrentShell(t *testing.T) {
env := new(MockedEnvironment)
env.On("getShellName", nil).Return(expected, nil)
s := &shell{
env: env,
env: env,
props: properties{},
}
assert.Equal(t, expected, s.string())
}
@ -30,7 +31,7 @@ func TestUseMappedShellNames(t *testing.T) {
env.On("getShellName", nil).Return(tc.Expected, nil)
s := &shell{
env: env,
props: map[Property]interface{}{
props: properties{
MappedShellNames: map[string]string{"pwsh": "PS"},
},
}

View file

@ -5,7 +5,7 @@ import (
)
type spotify struct {
props properties
props Properties
env environmentInfo
status string
artist string
@ -39,7 +39,7 @@ func (s *spotify) string() string {
return fmt.Sprintf("%s%s%s%s", icon, s.artist, separator, s.track)
}
func (s *spotify) init(props properties, env environmentInfo) {
func (s *spotify) init(props Properties, env environmentInfo) {
s.props = props
s.env = env
}

View file

@ -23,7 +23,8 @@ func bootStrapSpotifyDarwinTest(args *spotifyArgs) *spotify {
env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to artist of current track as string"}).Return(args.artist, nil)
env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to name of current track as string"}).Return(args.track, nil)
s := &spotify{
env: env,
env: env,
props: properties{},
}
return s
}

View file

@ -12,6 +12,7 @@ func TestSpotifyStringPlayingSong(t *testing.T) {
artist: "Candlemass",
track: "Spellbreaker",
status: "playing",
props: properties{},
}
assert.Equal(t, expected, s.string())
}
@ -22,6 +23,7 @@ func TestSpotifyStringPausedSong(t *testing.T) {
artist: "Candlemass",
track: "Spellbreaker",
status: "paused",
props: properties{},
}
assert.Equal(t, expected, s.string())
}
@ -32,6 +34,7 @@ func TestSpotifyStringStoppedSong(t *testing.T) {
artist: "Candlemass",
track: "Spellbreaker",
status: "stopped",
props: properties{},
}
assert.Equal(t, expected, s.string())
}

View file

@ -18,7 +18,8 @@ func bootStrapSpotifyWindowsTest(args *spotifyArgs) *spotify {
env := new(MockedEnvironment)
env.On("getWindowTitle", "spotify.exe").Return(args.title, args.runError)
s := &spotify{
env: env,
env: env,
props: properties{},
}
return s
}

View file

@ -55,7 +55,8 @@ func TestSpotifyWsl(t *testing.T) {
env.On("isWsl", nil).Return(true)
env.On("runCommand", "tasklist.exe", []string{"/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH"}).Return(tc.ExecOutput, nil)
s := &spotify{
env: env,
env: env,
props: properties{},
}
assert.Equal(t, tc.ExpectedEnabled, s.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
assert.Equal(t, tc.ExpectedString, s.string(), fmt.Sprintf("Failed in case: %s", tc.Case))

View file

@ -7,7 +7,7 @@ import (
)
type sysinfo struct {
props properties
props Properties
env environmentInfo
Precision int
// mem
@ -53,7 +53,7 @@ func (s *sysinfo) string() string {
return text
}
func (s *sysinfo) init(props properties, env environmentInfo) {
func (s *sysinfo) init(props Properties, env environmentInfo) {
s.props = props
s.env = env
s.Precision = s.props.getInt(Precision, 2)

View file

@ -35,11 +35,11 @@ func TestSysInfo(t *testing.T) {
for _, tc := range cases {
tc.SysInfo.env = new(MockedEnvironment)
tc.SysInfo.props = map[Property]interface{}{
tc.SysInfo.props = properties{
Precision: tc.Precision,
}
if tc.Template != "" {
tc.SysInfo.props[SegmentTemplate] = tc.Template
tc.SysInfo.props.set(SegmentTemplate, tc.Template)
}
if tc.ExpectDisabled {
assert.Equal(t, false, tc.SysInfo.enabled(), tc.Case)

View file

@ -1,7 +1,7 @@
package main
type terraform struct {
props properties
props Properties
env environmentInfo
WorkspaceName string
}
@ -20,7 +20,7 @@ func (tf *terraform) string() string {
return text
}
func (tf *terraform) init(props properties, env environmentInfo) {
func (tf *terraform) init(props Properties, env environmentInfo) {
tf.props = props
tf.env = env
}

View file

@ -19,7 +19,8 @@ func bootStrapTerraformTest(args *terraformArgs) *terraform {
env.On("getcwd", nil).Return("")
env.On("runCommand", "terraform", []string{"workspace", "show"}).Return(args.workspaceName, nil)
k := &terraform{
env: env,
env: env,
props: properties{},
}
return k
}

View file

@ -84,7 +84,7 @@ func TestShouldIncludeFolder(t *testing.T) {
env.On("homeDir", nil).Return("")
env.On("getcwd", nil).Return(cwd)
segment := &Segment{
Properties: map[Property]interface{}{
Properties: properties{
IncludeFolders: tc.IncludeFolders,
ExcludeFolders: tc.ExcludeFolders,
},
@ -101,7 +101,7 @@ func TestShouldIncludeFolderRegexInverted(t *testing.T) {
env.On("homeDir", nil).Return("")
env.On("getcwd", nil).Return(cwd)
segment := &Segment{
Properties: map[Property]interface{}{
Properties: properties{
ExcludeFolders: []string{"(?!Projects[\\/]).*"},
},
env: env,
@ -122,7 +122,7 @@ func TestShouldIncludeFolderRegexInvertedNonEscaped(t *testing.T) {
env.On("homeDir", nil).Return("")
env.On("getcwd", nil).Return(cwd)
segment := &Segment{
Properties: map[Property]interface{}{
Properties: properties{
ExcludeFolders: []string{"(?!Projects/).*"},
},
env: env,

View file

@ -1,7 +1,7 @@
package main
type text struct {
props properties
props Properties
env environmentInfo
content string
}
@ -26,7 +26,7 @@ func (t *text) string() string {
return t.content
}
func (t *text) init(props properties, env environmentInfo) {
func (t *text) init(props Properties, env environmentInfo) {
t.props = props
t.env = env
}

View file

@ -35,7 +35,7 @@ func TestTextSegment(t *testing.T) {
env.On("getHostName", nil).Return("MyHost", nil)
txt := &text{
env: env,
props: map[Property]interface{}{
props: properties{
TextProperty: tc.Text,
},
}

View file

@ -3,7 +3,7 @@ package main
import "time"
type tempus struct {
props properties
props Properties
env environmentInfo
templateText string
CurrentDate time.Time
@ -40,7 +40,7 @@ func (t *tempus) string() string {
return t.getFormattedText()
}
func (t *tempus) init(props properties, env environmentInfo) {
func (t *tempus) init(props Properties, env environmentInfo) {
t.props = props
t.env = env
}

View file

@ -41,7 +41,7 @@ func TestTimeSegmentTemplate(t *testing.T) {
env := new(MockedEnvironment)
tempus := &tempus{
env: env,
props: map[Property]interface{}{
props: properties{
SegmentTemplate: tc.Template,
},
CurrentDate: currentDate,

View file

@ -5,7 +5,7 @@ import (
)
type wakatime struct {
props properties
props Properties
env environmentInfo
wtData
@ -73,7 +73,7 @@ func (w *wakatime) setAPIData() error {
return nil
}
func (w *wakatime) init(props properties, env environmentInfo) {
func (w *wakatime) init(props Properties, env environmentInfo) {
w.props = props
w.env = env
}

View file

@ -79,7 +79,7 @@ func TestWTTrackedTime(t *testing.T) {
env.On("cache", nil).Return(cache)
w := &wakatime{
props: map[Property]interface{}{
props: properties{
APIKey: "key",
CacheTimeout: tc.CacheTimeout,
URL: FAKEAPIURL,

View file

@ -1,7 +1,7 @@
package main
type wifi struct {
props properties
props Properties
env environmentInfo
wifiInfo
@ -44,7 +44,7 @@ func (w *wifi) string() string {
return text
}
func (w *wifi) init(props properties, env environmentInfo) {
func (w *wifi) init(props Properties, env environmentInfo) {
w.props = props
w.env = env
}

View file

@ -48,7 +48,7 @@ func TestWiFiSegment(t *testing.T) {
w := &wifi{
env: env,
props: map[Property]interface{}{
props: properties{
DisplayError: tc.DisplayError,
SegmentTemplate: "{{ if .Error }}{{ .Error }}{{ else }}{{ .SSID }}{{ end }}",
},

View file

@ -6,7 +6,7 @@ import (
)
type winreg struct {
props properties
props Properties
env environmentInfo
Value string
@ -19,7 +19,7 @@ const (
Fallback Property = "fallback"
)
func (wr *winreg) init(props properties, env environmentInfo) {
func (wr *winreg) init(props Properties, env environmentInfo) {
wr.props = props
wr.env = env
}

View file

@ -75,7 +75,7 @@ func TestWinReg(t *testing.T) {
env.On("getWindowsRegistryKeyValue", tc.Path).Return(tc.getWRKVOutput, tc.Err)
r := &winreg{
env: env,
props: map[Property]interface{}{
props: properties{
RegistryPath: tc.Path,
Fallback: tc.Fallback,
},

View file

@ -6,7 +6,7 @@ import (
)
type ytm struct {
props properties
props Properties
env environmentInfo
status playStatus
artist string
@ -39,7 +39,7 @@ func (y *ytm) enabled() bool {
return err == nil
}
func (y *ytm) init(props properties, env environmentInfo) {
func (y *ytm) init(props Properties, env environmentInfo) {
y.props = props
y.env = env
}

View file

@ -13,6 +13,7 @@ func TestYTMStringPlayingSong(t *testing.T) {
artist: "Candlemass",
track: "Spellbreaker",
status: playing,
props: properties{},
}
assert.Equal(t, expected, y.string())
}
@ -23,6 +24,7 @@ func TestYTMStringPausedSong(t *testing.T) {
artist: "Candlemass",
track: "Spellbreaker",
status: paused,
props: properties{},
}
assert.Equal(t, expected, y.string())
}
@ -33,6 +35,7 @@ func TestYTMStringStoppedSong(t *testing.T) {
artist: "Candlemass",
track: "Spellbreaker",
status: stopped,
props: properties{},
}
assert.Equal(t, expected, y.string())
}
@ -43,7 +46,7 @@ func bootstrapYTMDATest(json string, err error) *ytm {
env.On("doGet", url+"/query").Return([]byte(json), err)
ytm := &ytm{
env: env,
props: map[Property]interface{}{
props: properties{
APIURL: url,
},
}