mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
perf: correctly align struct fields
This commit is contained in:
parent
0853a527a7
commit
d4b86e63e4
25
src/cache/template.go
vendored
25
src/cache/template.go
vendored
|
@ -7,28 +7,27 @@ import (
|
|||
)
|
||||
|
||||
type Template struct {
|
||||
Root bool
|
||||
PWD string
|
||||
Env map[string]string
|
||||
SegmentsCache maps.Simple
|
||||
Segments *maps.Concurrent
|
||||
Var maps.Simple
|
||||
ShellVersion string
|
||||
AbsolutePWD string
|
||||
PSWD string
|
||||
Folder string
|
||||
Shell string
|
||||
ShellVersion string
|
||||
UserName string
|
||||
HostName string
|
||||
Code int
|
||||
Env map[string]string
|
||||
Var maps.Simple
|
||||
PWD string
|
||||
Shell string
|
||||
Folder string
|
||||
OS string
|
||||
WSL bool
|
||||
Code int
|
||||
PromptCount int
|
||||
SHLVL int
|
||||
Jobs int
|
||||
Segments *maps.Concurrent
|
||||
SegmentsCache maps.Simple
|
||||
|
||||
Initialized bool
|
||||
sync.RWMutex
|
||||
WSL bool
|
||||
Root bool
|
||||
Initialized bool
|
||||
}
|
||||
|
||||
func (t *Template) AddSegmentData(key string, value any) {
|
||||
|
|
|
@ -62,8 +62,8 @@ func isPaletteKey(colorName Ansi) (Ansi, bool) {
|
|||
|
||||
// PaletteKeyError records the missing Palette key.
|
||||
type PaletteKeyError struct {
|
||||
Key Ansi
|
||||
palette Palette
|
||||
Key Ansi
|
||||
}
|
||||
|
||||
func (p *PaletteKeyError) Error() string {
|
||||
|
|
|
@ -19,8 +19,8 @@ var (
|
|||
type TestPaletteRequest struct {
|
||||
Case string
|
||||
Request Ansi
|
||||
ExpectedError bool
|
||||
Expected Ansi
|
||||
ExpectedError bool
|
||||
}
|
||||
|
||||
func TestPaletteShouldResolveColorFromTestPalette(t *testing.T) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package color
|
||||
|
||||
type Palettes struct {
|
||||
Template string `json:"template,omitempty" toml:"template,omitempty"`
|
||||
List map[string]Palette `json:"list,omitempty" toml:"list,omitempty"`
|
||||
Template string `json:"template,omitempty" toml:"template,omitempty"`
|
||||
}
|
||||
|
|
|
@ -34,24 +34,19 @@ const (
|
|||
|
||||
// Block defines a part of the prompt with optional segments
|
||||
type Block struct {
|
||||
Type BlockType `json:"type,omitempty" toml:"type,omitempty"`
|
||||
Alignment BlockAlignment `json:"alignment,omitempty" toml:"alignment,omitempty"`
|
||||
Segments []*Segment `json:"segments,omitempty" toml:"segments,omitempty"`
|
||||
Newline bool `json:"newline,omitempty" toml:"newline,omitempty"`
|
||||
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
|
||||
Overflow Overflow `json:"overflow,omitempty" toml:"overflow,omitempty"`
|
||||
|
||||
LeadingDiamond string `json:"leading_diamond,omitempty" toml:"leading_diamond,omitempty"`
|
||||
TrailingDiamond string `json:"trailing_diamond,omitempty" toml:"trailing_diamond,omitempty"`
|
||||
|
||||
// Deprecated: keep the logic for legacy purposes
|
||||
HorizontalOffset int `json:"horizontal_offset,omitempty" toml:"horizontal_offset,omitempty"`
|
||||
VerticalOffset int `json:"vertical_offset,omitempty" toml:"vertical_offset,omitempty"`
|
||||
|
||||
MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
|
||||
MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"`
|
||||
|
||||
env runtime.Environment
|
||||
env runtime.Environment
|
||||
Type BlockType `json:"type,omitempty" toml:"type,omitempty"`
|
||||
Alignment BlockAlignment `json:"alignment,omitempty" toml:"alignment,omitempty"`
|
||||
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
|
||||
Overflow Overflow `json:"overflow,omitempty" toml:"overflow,omitempty"`
|
||||
LeadingDiamond string `json:"leading_diamond,omitempty" toml:"leading_diamond,omitempty"`
|
||||
TrailingDiamond string `json:"trailing_diamond,omitempty" toml:"trailing_diamond,omitempty"`
|
||||
Segments []*Segment `json:"segments,omitempty" toml:"segments,omitempty"`
|
||||
VerticalOffset int `json:"vertical_offset,omitempty" toml:"vertical_offset,omitempty"`
|
||||
HorizontalOffset int `json:"horizontal_offset,omitempty" toml:"horizontal_offset,omitempty"`
|
||||
MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
|
||||
MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"`
|
||||
Newline bool `json:"newline,omitempty" toml:"newline,omitempty"`
|
||||
}
|
||||
|
||||
func (b *Block) Init(env runtime.Environment) {
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
func TestBlockEnabled(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected bool
|
||||
Segments []*Segment
|
||||
Type BlockType
|
||||
Segments []*Segment
|
||||
Expected bool
|
||||
}{
|
||||
{Case: "line break block", Expected: true, Type: LineBreak},
|
||||
{Case: "prompt enabled", Expected: true, Type: Prompt, Segments: []*Segment{{Enabled: true}}},
|
||||
|
|
|
@ -21,41 +21,36 @@ const (
|
|||
|
||||
// Config holds all the theme for rendering the prompt
|
||||
type Config struct {
|
||||
Version int `json:"version" toml:"version"`
|
||||
FinalSpace bool `json:"final_space,omitempty" toml:"final_space,omitempty"`
|
||||
ConsoleTitleTemplate string `json:"console_title_template,omitempty" toml:"console_title_template,omitempty"`
|
||||
TerminalBackground color.Ansi `json:"terminal_background,omitempty" toml:"terminal_background,omitempty"`
|
||||
env runtime.Environment
|
||||
Palette color.Palette `json:"palette,omitempty" toml:"palette,omitempty"`
|
||||
DebugPrompt *Segment `json:"debug_prompt,omitempty" toml:"debug_prompt,omitempty"`
|
||||
Var map[string]any `json:"var,omitempty" toml:"var,omitempty"`
|
||||
Palettes *color.Palettes `json:"palettes,omitempty" toml:"palettes,omitempty"`
|
||||
ValidLine *Segment `json:"valid_line,omitempty" toml:"valid_line,omitempty"`
|
||||
SecondaryPrompt *Segment `json:"secondary_prompt,omitempty" toml:"secondary_prompt,omitempty"`
|
||||
TransientPrompt *Segment `json:"transient_prompt,omitempty" toml:"transient_prompt,omitempty"`
|
||||
ErrorLine *Segment `json:"error_line,omitempty" toml:"error_line,omitempty"`
|
||||
ConsoleTitleTemplate string `json:"console_title_template,omitempty" toml:"console_title_template,omitempty"`
|
||||
Format string `json:"-" toml:"-"`
|
||||
origin string
|
||||
PWD string `json:"pwd,omitempty" toml:"pwd,omitempty"`
|
||||
AccentColor color.Ansi `json:"accent_color,omitempty" toml:"accent_color,omitempty"`
|
||||
Output string `json:"-" toml:"-"`
|
||||
TerminalBackground color.Ansi `json:"terminal_background,omitempty" toml:"terminal_background,omitempty"`
|
||||
Cycle color.Cycle `json:"cycle,omitempty" toml:"cycle,omitempty"`
|
||||
ITermFeatures terminal.ITermFeatures `json:"iterm_features,omitempty" toml:"iterm_features,omitempty"`
|
||||
Blocks []*Block `json:"blocks,omitempty" toml:"blocks,omitempty"`
|
||||
Tooltips []*Segment `json:"tooltips,omitempty" toml:"tooltips,omitempty"`
|
||||
TransientPrompt *Segment `json:"transient_prompt,omitempty" toml:"transient_prompt,omitempty"`
|
||||
ValidLine *Segment `json:"valid_line,omitempty" toml:"valid_line,omitempty"`
|
||||
ErrorLine *Segment `json:"error_line,omitempty" toml:"error_line,omitempty"`
|
||||
SecondaryPrompt *Segment `json:"secondary_prompt,omitempty" toml:"secondary_prompt,omitempty"`
|
||||
DebugPrompt *Segment `json:"debug_prompt,omitempty" toml:"debug_prompt,omitempty"`
|
||||
Palette color.Palette `json:"palette,omitempty" toml:"palette,omitempty"`
|
||||
Palettes *color.Palettes `json:"palettes,omitempty" toml:"palettes,omitempty"`
|
||||
Cycle color.Cycle `json:"cycle,omitempty" toml:"cycle,omitempty"`
|
||||
ShellIntegration bool `json:"shell_integration,omitempty" toml:"shell_integration,omitempty"`
|
||||
PWD string `json:"pwd,omitempty" toml:"pwd,omitempty"`
|
||||
Var map[string]any `json:"var,omitempty" toml:"var,omitempty"`
|
||||
EnableCursorPositioning bool `json:"enable_cursor_positioning,omitempty" toml:"enable_cursor_positioning,omitempty"`
|
||||
PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty" toml:"patch_pwsh_bleed,omitempty"`
|
||||
Version int `json:"version" toml:"version"`
|
||||
DisableNotice bool `json:"disable_notice,omitempty" toml:"disable_notice,omitempty"`
|
||||
AutoUpgrade bool `json:"auto_upgrade,omitempty" toml:"auto_upgrade,omitempty"`
|
||||
ITermFeatures terminal.ITermFeatures `json:"iterm_features,omitempty" toml:"iterm_features,omitempty"`
|
||||
|
||||
// Deprecated
|
||||
OSC99 bool `json:"osc99,omitempty" toml:"osc99,omitempty"`
|
||||
|
||||
Output string `json:"-" toml:"-"`
|
||||
MigrateGlyphs bool `json:"-" toml:"-"`
|
||||
Format string `json:"-" toml:"-"`
|
||||
|
||||
origin string
|
||||
// eval bool
|
||||
updated bool
|
||||
env runtime.Environment
|
||||
OSC99 bool `json:"osc99,omitempty" toml:"osc99,omitempty"`
|
||||
ShellIntegration bool `json:"shell_integration,omitempty" toml:"shell_integration,omitempty"`
|
||||
MigrateGlyphs bool `json:"-" toml:"-"`
|
||||
PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty" toml:"patch_pwsh_bleed,omitempty"`
|
||||
EnableCursorPositioning bool `json:"enable_cursor_positioning,omitempty" toml:"enable_cursor_positioning,omitempty"`
|
||||
updated bool
|
||||
FinalSpace bool `json:"final_space,omitempty" toml:"final_space,omitempty"`
|
||||
}
|
||||
|
||||
func (cfg *Config) MakeColors() color.String {
|
||||
|
|
|
@ -19,10 +19,10 @@ func TestGetPalette(t *testing.T) {
|
|||
}
|
||||
|
||||
cases := []struct {
|
||||
Case string
|
||||
Palettes *color.Palettes
|
||||
Palette color.Palette
|
||||
ExpectedPalette color.Palette
|
||||
Case string
|
||||
}{
|
||||
{
|
||||
Case: "match",
|
||||
|
|
|
@ -20,10 +20,10 @@ const (
|
|||
|
||||
func TestHasProperty(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected bool
|
||||
Property properties.Property
|
||||
Props properties.Map
|
||||
Case string
|
||||
Property properties.Property
|
||||
Expected bool
|
||||
}{
|
||||
{Case: "Match", Expected: true, Property: Foo, Props: properties.Map{Foo: "bar"}},
|
||||
{Case: "No Match", Expected: false, Property: Foo, Props: properties.Map{Bar: "foo"}},
|
||||
|
@ -40,10 +40,10 @@ func TestHasProperty(t *testing.T) {
|
|||
|
||||
func TestMigratePropertyValue(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected any
|
||||
Property properties.Property
|
||||
Props properties.Map
|
||||
Case string
|
||||
Property properties.Property
|
||||
}{
|
||||
{Case: "Match", Expected: "foo", Property: Foo, Props: properties.Map{Foo: "bar"}},
|
||||
{Case: "No Match", Expected: nil, Property: Foo, Props: properties.Map{Bar: "foo"}},
|
||||
|
@ -59,11 +59,11 @@ func TestMigratePropertyValue(t *testing.T) {
|
|||
|
||||
func TestMigratePropertyKey(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected any
|
||||
Props properties.Map
|
||||
Case string
|
||||
OldProperty properties.Property
|
||||
NewProperty properties.Property
|
||||
Props properties.Map
|
||||
}{
|
||||
{Case: "Match", Expected: "bar", OldProperty: Foo, NewProperty: Bar, Props: properties.Map{Foo: "bar"}},
|
||||
{Case: "No match", Expected: nil, OldProperty: Foo, NewProperty: Bar, Props: properties.Map{FooBar: "bar"}},
|
||||
|
@ -95,10 +95,10 @@ func (m *MockedWriter) Init(_ properties.Properties, _ runtime.Environment) {}
|
|||
|
||||
func TestIconOverride(t *testing.T) {
|
||||
cases := []struct {
|
||||
Props properties.Map
|
||||
Case string
|
||||
Expected string
|
||||
Property properties.Property
|
||||
Props properties.Map
|
||||
}{
|
||||
{
|
||||
Case: "Match",
|
||||
|
@ -133,13 +133,13 @@ func TestIconOverride(t *testing.T) {
|
|||
|
||||
func TestColorMigration(t *testing.T) {
|
||||
cases := []struct {
|
||||
Props properties.Map
|
||||
Case string
|
||||
Expected string
|
||||
Property properties.Property
|
||||
Template string
|
||||
Background bool
|
||||
NoOverride bool
|
||||
Props properties.Map
|
||||
}{
|
||||
{
|
||||
Case: "Foreground override",
|
||||
|
@ -191,10 +191,10 @@ func TestColorMigration(t *testing.T) {
|
|||
|
||||
func TestSegmentTemplateMigration(t *testing.T) {
|
||||
cases := []struct {
|
||||
Props properties.Map
|
||||
Case string
|
||||
Expected string
|
||||
Type SegmentType
|
||||
Props properties.Map
|
||||
}{
|
||||
{
|
||||
Case: "GIT",
|
||||
|
@ -336,10 +336,10 @@ func TestSegmentTemplateMigration(t *testing.T) {
|
|||
|
||||
func TestInlineColorOverride(t *testing.T) {
|
||||
cases := []struct {
|
||||
Props properties.Map
|
||||
Case string
|
||||
Expected string
|
||||
Property properties.Property
|
||||
Props properties.Map
|
||||
}{
|
||||
{
|
||||
Case: "Match",
|
||||
|
@ -374,9 +374,9 @@ func TestInlineColorOverride(t *testing.T) {
|
|||
|
||||
func TestMigratePreAndPostfix(t *testing.T) {
|
||||
cases := []struct {
|
||||
Props properties.Map
|
||||
Case string
|
||||
Expected string
|
||||
Props properties.Map
|
||||
}{
|
||||
{
|
||||
Case: "Pre and Postfix",
|
||||
|
|
|
@ -10,11 +10,11 @@ import (
|
|||
|
||||
func TestShouldHideForWidth(t *testing.T) {
|
||||
cases := []struct {
|
||||
Error error
|
||||
Case string
|
||||
MinWidth int
|
||||
MaxWidth int
|
||||
Width int
|
||||
Error error
|
||||
Expected bool
|
||||
}{
|
||||
{Case: "No settings"},
|
||||
|
|
|
@ -35,41 +35,37 @@ func (s *SegmentStyle) resolve(env runtime.Environment, context any) SegmentStyl
|
|||
}
|
||||
|
||||
type Segment struct {
|
||||
Type SegmentType `json:"type,omitempty" toml:"type,omitempty"`
|
||||
Tips []string `json:"tips,omitempty" toml:"tips,omitempty"`
|
||||
Style SegmentStyle `json:"style,omitempty" toml:"style,omitempty"`
|
||||
PowerlineSymbol string `json:"powerline_symbol,omitempty" toml:"powerline_symbol,omitempty"`
|
||||
writer SegmentWriter
|
||||
env runtime.Environment
|
||||
Properties properties.Map `json:"properties,omitempty" toml:"properties,omitempty"`
|
||||
LeadingPowerlineSymbol string `json:"leading_powerline_symbol,omitempty" toml:"leading_powerline_symbol,omitempty"`
|
||||
InvertPowerline bool `json:"invert_powerline,omitempty" toml:"invert_powerline,omitempty"`
|
||||
ForegroundTemplates template.List `json:"foreground_templates,omitempty" toml:"foreground_templates,omitempty"`
|
||||
BackgroundTemplates template.List `json:"background_templates,omitempty" toml:"background_templates,omitempty"`
|
||||
Background color.Ansi `json:"background" toml:"background"`
|
||||
Style SegmentStyle `json:"style,omitempty" toml:"style,omitempty"`
|
||||
Text string `json:"-" toml:"-"`
|
||||
name string
|
||||
LeadingDiamond string `json:"leading_diamond,omitempty" toml:"leading_diamond,omitempty"`
|
||||
TrailingDiamond string `json:"trailing_diamond,omitempty" toml:"trailing_diamond,omitempty"`
|
||||
Template string `json:"template,omitempty" toml:"template,omitempty"`
|
||||
Templates template.List `json:"templates,omitempty" toml:"templates,omitempty"`
|
||||
Foreground color.Ansi `json:"foreground" toml:"foreground"`
|
||||
TemplatesLogic template.Logic `json:"templates_logic,omitempty" toml:"templates_logic,omitempty"`
|
||||
Properties properties.Map `json:"properties,omitempty" toml:"properties,omitempty"`
|
||||
Interactive bool `json:"interactive,omitempty" toml:"interactive,omitempty"`
|
||||
Alias string `json:"alias,omitempty" toml:"alias,omitempty"`
|
||||
MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
|
||||
MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"`
|
||||
PowerlineSymbol string `json:"powerline_symbol,omitempty" toml:"powerline_symbol,omitempty"`
|
||||
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
|
||||
Background color.Ansi `json:"background,omitempty" toml:"background,omitempty"`
|
||||
Foreground color.Ansi `json:"foreground,omitempty" toml:"foreground,omitempty"`
|
||||
Newline bool `json:"newline,omitempty" toml:"newline,omitempty"`
|
||||
Alias string `json:"alias,omitempty" toml:"alias,omitempty"`
|
||||
Type SegmentType `json:"type,omitempty" toml:"type,omitempty"`
|
||||
styleCache SegmentStyle
|
||||
CacheDuration cache.Duration `json:"cache_duration,omitempty" toml:"cache_duration,omitempty"`
|
||||
|
||||
Enabled bool `json:"-" toml:"-"`
|
||||
Text string `json:"-" toml:"-"`
|
||||
|
||||
env runtime.Environment
|
||||
writer SegmentWriter
|
||||
styleCache SegmentStyle
|
||||
name string
|
||||
|
||||
// debug info
|
||||
Duration time.Duration `json:"-" toml:"-"`
|
||||
NameLength int `json:"-" toml:"-"`
|
||||
BackgroundTemplates template.List `json:"background_templates,omitempty" toml:"background_templates,omitempty"`
|
||||
ForegroundTemplates template.List `json:"foreground_templates,omitempty" toml:"foreground_templates,omitempty"`
|
||||
Tips []string `json:"tips,omitempty" toml:"tips,omitempty"`
|
||||
Templates template.List `json:"templates,omitempty" toml:"templates,omitempty"`
|
||||
MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"`
|
||||
MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
|
||||
Duration time.Duration `json:"-" toml:"-"`
|
||||
NameLength int `json:"-" toml:"-"`
|
||||
Interactive bool `json:"interactive,omitempty" toml:"interactive,omitempty"`
|
||||
Enabled bool `json:"-" toml:"-"`
|
||||
Newline bool `json:"newline,omitempty" toml:"newline,omitempty"`
|
||||
InvertPowerline bool `json:"invert_powerline,omitempty" toml:"invert_powerline,omitempty"`
|
||||
}
|
||||
|
||||
func (segment *Segment) Name() string {
|
||||
|
|
|
@ -94,12 +94,12 @@ func TestShouldIncludeFolder(t *testing.T) {
|
|||
func TestGetColors(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Background bool
|
||||
Expected color.Ansi
|
||||
Templates []string
|
||||
Default color.Ansi
|
||||
Region string
|
||||
Profile string
|
||||
Templates []string
|
||||
Background bool
|
||||
}{
|
||||
{Case: "No template - foreground", Expected: "color", Background: false, Default: "color"},
|
||||
{Case: "No template - background", Expected: "color", Background: true, Default: "color"},
|
||||
|
|
|
@ -72,13 +72,13 @@ const (
|
|||
)
|
||||
|
||||
type main struct {
|
||||
spinner spinner.Model
|
||||
list *list.Model
|
||||
system bool
|
||||
font string
|
||||
state state
|
||||
err error
|
||||
list *list.Model
|
||||
font string
|
||||
families []string
|
||||
spinner spinner.Model
|
||||
state state
|
||||
system bool
|
||||
}
|
||||
|
||||
func (m *main) buildFontList(nerdFonts []*Asset) {
|
||||
|
|
|
@ -109,42 +109,32 @@ func NewRGBColor(ansiColor string) *RGB {
|
|||
}
|
||||
|
||||
type Renderer struct {
|
||||
AnsiString string
|
||||
Author string
|
||||
CursorPadding int
|
||||
RPromptOffset int
|
||||
BgColor string
|
||||
|
||||
env runtime.Environment
|
||||
|
||||
Path string
|
||||
|
||||
factor float64
|
||||
|
||||
columns int
|
||||
rows int
|
||||
|
||||
italic font.Face
|
||||
env runtime.Environment
|
||||
bold font.Face
|
||||
regular font.Face
|
||||
defaultForegroundColor *RGB
|
||||
ansiSequenceRegexMap map[string]string
|
||||
foregroundColor *RGB
|
||||
backgroundColor *RGB
|
||||
defaultBackgroundColor *RGB
|
||||
|
||||
shadowBaseColor string
|
||||
shadowRadius uint8
|
||||
shadowOffsetX float64
|
||||
shadowOffsetY float64
|
||||
|
||||
padding float64
|
||||
margin float64
|
||||
|
||||
regular font.Face
|
||||
bold font.Face
|
||||
italic font.Face
|
||||
lineSpacing float64
|
||||
|
||||
// canvas switches
|
||||
style string
|
||||
backgroundColor *RGB
|
||||
foregroundColor *RGB
|
||||
ansiSequenceRegexMap map[string]string
|
||||
Path string
|
||||
AnsiString string
|
||||
Author string
|
||||
shadowBaseColor string
|
||||
style string
|
||||
BgColor string
|
||||
shadowOffsetX float64
|
||||
padding float64
|
||||
margin float64
|
||||
factor float64
|
||||
shadowOffsetY float64
|
||||
rows int
|
||||
lineSpacing float64
|
||||
RPromptOffset int
|
||||
CursorPadding int
|
||||
columns int
|
||||
shadowRadius uint8
|
||||
}
|
||||
|
||||
func (ir *Renderer) Init(env runtime.Environment) error {
|
||||
|
|
|
@ -15,17 +15,15 @@ import (
|
|||
var cycle *color.Cycle = &color.Cycle{}
|
||||
|
||||
type Engine struct {
|
||||
Config *config.Config
|
||||
Env runtime.Environment
|
||||
Plain bool
|
||||
|
||||
prompt strings.Builder
|
||||
currentLineLength int
|
||||
rprompt string
|
||||
rpromptLength int
|
||||
|
||||
Env runtime.Environment
|
||||
Config *config.Config
|
||||
activeSegment *config.Segment
|
||||
previousActiveSegment *config.Segment
|
||||
rprompt string
|
||||
prompt strings.Builder
|
||||
currentLineLength int
|
||||
rpromptLength int
|
||||
Plain bool
|
||||
}
|
||||
|
||||
func (e *Engine) write(text string) {
|
||||
|
|
|
@ -17,12 +17,12 @@ import (
|
|||
|
||||
func TestCanWriteRPrompt(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected bool
|
||||
TerminalWidth int
|
||||
TerminalWidthError error
|
||||
Case string
|
||||
TerminalWidth int
|
||||
PromptLength int
|
||||
RPromptLength int
|
||||
Expected bool
|
||||
}{
|
||||
{Case: "Width Error", Expected: false, TerminalWidthError: errors.New("burp")},
|
||||
{Case: "Terminal > Prompt enabled", Expected: true, TerminalWidth: 200, PromptLength: 100, RPromptLength: 10},
|
||||
|
@ -150,12 +150,12 @@ func BenchmarkEngineRenderPalette(b *testing.B) {
|
|||
func TestGetTitle(t *testing.T) {
|
||||
cases := []struct {
|
||||
Template string
|
||||
Root bool
|
||||
User string
|
||||
Cwd string
|
||||
PathSeparator string
|
||||
ShellName string
|
||||
Expected string
|
||||
Root bool
|
||||
}{
|
||||
{
|
||||
Template: "{{.Env.USERDOMAIN}} :: {{.PWD}}{{if .Root}} :: Admin{{end}} :: {{.Shell}}",
|
||||
|
@ -220,12 +220,12 @@ func TestGetTitle(t *testing.T) {
|
|||
func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) {
|
||||
cases := []struct {
|
||||
Template string
|
||||
Root bool
|
||||
User string
|
||||
Cwd string
|
||||
PathSeparator string
|
||||
ShellName string
|
||||
Expected string
|
||||
Root bool
|
||||
}{
|
||||
{
|
||||
Template: "Not using Host only {{.UserName}} and {{.Shell}}",
|
||||
|
|
|
@ -88,9 +88,9 @@ func TestGetBoolInvalidProperty(t *testing.T) {
|
|||
|
||||
func TestGetFloat64(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input any
|
||||
Case string
|
||||
Expected float64
|
||||
Input any
|
||||
}{
|
||||
{Case: "int", Expected: 1337, Input: 1337},
|
||||
{Case: "float64", Expected: 1337, Input: float64(1337)},
|
||||
|
@ -115,11 +115,11 @@ func TestGetFloat64PropertyNotInMap(t *testing.T) {
|
|||
|
||||
func TestOneOf(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Map Map
|
||||
Properties []Property
|
||||
DefaultValue string
|
||||
Expected any
|
||||
Map Map
|
||||
Case string
|
||||
DefaultValue string
|
||||
Properties []Property
|
||||
}{
|
||||
{
|
||||
Case: "one element",
|
||||
|
|
|
@ -28,14 +28,14 @@ import (
|
|||
|
||||
func TestErrors(t *testing.T) {
|
||||
cases := []struct {
|
||||
in Errors
|
||||
str string
|
||||
in Errors
|
||||
}{
|
||||
{Errors{nil}, ""},
|
||||
{Errors{errors.New("")}, ""},
|
||||
{Errors{errors.New("t1")}, "t1"},
|
||||
{Errors{errors.New("t2"), errors.New("t3")}, "t2, t3"},
|
||||
{Errors{errors.New("t4"), errors.New("t5")}, "t4, t5"},
|
||||
{"", Errors{nil}},
|
||||
{"", Errors{errors.New("")}},
|
||||
{"t1", Errors{errors.New("t1")}},
|
||||
{"t2, t3", Errors{errors.New("t2"), errors.New("t3")}},
|
||||
{"t4, t5", Errors{errors.New("t4"), errors.New("t5")}},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
|
|
|
@ -77,30 +77,31 @@ type Environment interface {
|
|||
}
|
||||
|
||||
type Flags struct {
|
||||
ErrorCode int
|
||||
PSWD string
|
||||
PipeStatus string
|
||||
Config string
|
||||
Shell string
|
||||
ShellVersion string
|
||||
PWD string
|
||||
PSWD string
|
||||
PromptCount int
|
||||
ExecutionTime float64
|
||||
Eval bool
|
||||
JobCount int
|
||||
StackCount int
|
||||
Migrate bool
|
||||
Column int
|
||||
TerminalWidth int
|
||||
Strict bool
|
||||
Debug bool
|
||||
ErrorCode int
|
||||
Plain bool
|
||||
Manual bool
|
||||
Debug bool
|
||||
Primary bool
|
||||
HasTransient bool
|
||||
PromptCount int
|
||||
Strict bool
|
||||
Cleared bool
|
||||
NoExitCode bool
|
||||
Column int
|
||||
JobCount int
|
||||
SaveCache bool
|
||||
Init bool
|
||||
Migrate bool
|
||||
Eval bool
|
||||
}
|
||||
|
||||
type CommandError struct {
|
||||
|
@ -129,9 +130,9 @@ const (
|
|||
|
||||
type WindowsRegistryValue struct {
|
||||
ValueType WindowsRegistryValueType
|
||||
String string
|
||||
DWord uint64
|
||||
QWord uint64
|
||||
String string
|
||||
}
|
||||
|
||||
type NotImplemented struct{}
|
||||
|
@ -152,9 +153,9 @@ const (
|
|||
type Connection struct {
|
||||
Name string
|
||||
Type ConnectionType
|
||||
SSID string
|
||||
TransmitRate uint64
|
||||
ReceiveRate uint64
|
||||
SSID string // Wi-Fi only
|
||||
}
|
||||
|
||||
type Memory struct {
|
||||
|
@ -168,12 +169,9 @@ type Memory struct {
|
|||
}
|
||||
|
||||
type SystemInfo struct {
|
||||
// mem
|
||||
Disks map[string]disk.IOCountersStat
|
||||
Memory
|
||||
// load
|
||||
Load1 float64
|
||||
Load5 float64
|
||||
Load15 float64
|
||||
// disk
|
||||
Disks map[string]disk.IOCountersStat
|
||||
}
|
||||
|
|
|
@ -31,14 +31,12 @@ func (a *OAuthError) Error() string {
|
|||
}
|
||||
|
||||
type OAuthRequest struct {
|
||||
Request
|
||||
|
||||
AccessTokenKey string
|
||||
RefreshTokenKey string
|
||||
SegmentName string
|
||||
|
||||
RefreshToken string
|
||||
AccessToken string
|
||||
RefreshToken string
|
||||
AccessToken string
|
||||
Request
|
||||
}
|
||||
|
||||
func (o *OAuthRequest) getAccessToken() (string, error) {
|
||||
|
|
|
@ -21,21 +21,19 @@ func TestOauthResult(t *testing.T) {
|
|||
successData := &data{Hello: "world"}
|
||||
|
||||
cases := []struct {
|
||||
Case string
|
||||
// tokens
|
||||
AccessToken string
|
||||
RefreshToken string
|
||||
TokenResponse string
|
||||
// API response
|
||||
JSONResponse string
|
||||
// Cache
|
||||
RefreshTokenFromCache bool
|
||||
Error error
|
||||
ExpectedData *data
|
||||
AccessToken string
|
||||
RefreshToken string
|
||||
TokenResponse string
|
||||
JSONResponse string
|
||||
CacheJSONResponse string
|
||||
Case string
|
||||
ExpectedErrorMessage string
|
||||
CacheTimeout int
|
||||
ResponseCacheMiss bool
|
||||
AccessTokenFromCache bool
|
||||
// Errors
|
||||
Error error
|
||||
// Validations
|
||||
ExpectedErrorMessage string
|
||||
ExpectedData *data
|
||||
RefreshTokenFromCache bool
|
||||
}{
|
||||
{
|
||||
Case: "No initial tokens",
|
||||
|
|
|
@ -31,14 +31,14 @@ func TestRequestResult(t *testing.T) {
|
|||
url := "https://google.com?q=hello"
|
||||
|
||||
cases := []struct {
|
||||
Case string
|
||||
// API response
|
||||
JSONResponse string
|
||||
// Errors
|
||||
Error error
|
||||
// Validations
|
||||
ExpectedErrorMessage string
|
||||
Error error
|
||||
ExpectedData *data
|
||||
Case string
|
||||
JSONResponse string
|
||||
CacheJSONResponse string
|
||||
ExpectedErrorMessage string
|
||||
CacheTimeout int
|
||||
ResponseCacheMiss bool
|
||||
}{
|
||||
{
|
||||
Case: "No cache",
|
||||
|
|
|
@ -31,22 +31,17 @@ import (
|
|||
)
|
||||
|
||||
type Terminal struct {
|
||||
CmdFlags *Flags
|
||||
Var maps.Simple
|
||||
|
||||
cwd string
|
||||
host string
|
||||
cmdCache *cache.Command
|
||||
|
||||
CmdFlags *Flags
|
||||
Var maps.Simple
|
||||
cmdCache *cache.Command
|
||||
deviceCache *cache.File
|
||||
sessionCache *cache.File
|
||||
|
||||
tmplCache *cache.Template
|
||||
networks []*Connection
|
||||
|
||||
tmplCache *cache.Template
|
||||
lsDirMap maps.Concurrent
|
||||
cwd string
|
||||
host string
|
||||
networks []*Connection
|
||||
sync.RWMutex
|
||||
|
||||
lsDirMap maps.Concurrent
|
||||
}
|
||||
|
||||
func (term *Terminal) Init() {
|
||||
|
|
|
@ -28,8 +28,8 @@ type ArgocdContext struct {
|
|||
}
|
||||
|
||||
type ArgocdConfig struct {
|
||||
Contexts []*ArgocdContext `yaml:"contexts"`
|
||||
CurrentContext string `yaml:"current-context"`
|
||||
Contexts []*ArgocdContext `yaml:"contexts"`
|
||||
}
|
||||
|
||||
type Argocd struct {
|
||||
|
|
|
@ -73,11 +73,11 @@ func TestArgocdGetConfigPath(t *testing.T) {
|
|||
func TestArgocdParseConfig(t *testing.T) {
|
||||
configFile := "/Users/posh/.config/argocd/config"
|
||||
cases := []struct {
|
||||
ExpectedContext ArgocdContext
|
||||
Case string
|
||||
Config string
|
||||
Expected bool
|
||||
ExpectedError string
|
||||
ExpectedContext ArgocdContext
|
||||
Expected bool
|
||||
}{
|
||||
{Case: "missing or empty yaml", Config: "", ExpectedError: argocdInvalidYaml},
|
||||
{
|
||||
|
@ -177,14 +177,14 @@ users:
|
|||
func TestArgocdSegment(t *testing.T) {
|
||||
configFile := path.Join(poshHome, ".config", "argocd", "config")
|
||||
cases := []struct {
|
||||
ExpectedContext ArgocdContext
|
||||
Case string
|
||||
Opts string
|
||||
Config string
|
||||
Template string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
ExpectedError string
|
||||
ExpectedContext ArgocdContext
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "default template",
|
||||
|
|
|
@ -14,7 +14,6 @@ func TestAWSSegment(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
Profile string
|
||||
DefaultProfile string
|
||||
Vault string
|
||||
|
@ -22,6 +21,7 @@ func TestAWSSegment(t *testing.T) {
|
|||
DefaultRegion string
|
||||
ConfigFile string
|
||||
Template string
|
||||
ExpectedEnabled bool
|
||||
DisplayDefault bool
|
||||
}{
|
||||
{Case: "enabled with default user", ExpectedString: "default@eu-west", Region: "eu-west", ExpectedEnabled: true, DisplayDefault: true},
|
||||
|
|
|
@ -11,11 +11,10 @@ import (
|
|||
)
|
||||
|
||||
type Az struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
|
||||
AzureSubscription
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
Origin string
|
||||
AzureSubscription
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -28,21 +27,21 @@ const (
|
|||
)
|
||||
|
||||
type AzureConfig struct {
|
||||
Subscriptions []*AzureSubscription `json:"subscriptions"`
|
||||
InstallationID string `json:"installationId"`
|
||||
Subscriptions []*AzureSubscription `json:"subscriptions"`
|
||||
}
|
||||
|
||||
type AzureSubscription struct {
|
||||
User *AzureUser `json:"user"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
User *AzureUser `json:"user"`
|
||||
IsDefault bool `json:"isDefault"`
|
||||
TenantID string `json:"tenantId"`
|
||||
TenantDisplayName string `json:"tenantDisplayName"`
|
||||
EnvironmentName string `json:"environmentName"`
|
||||
HomeTenantID string `json:"homeTenantId"`
|
||||
ManagedByTenants []any `json:"managedByTenants"`
|
||||
IsDefault bool `json:"isDefault"`
|
||||
}
|
||||
|
||||
type AzureUser struct {
|
||||
|
|
|
@ -15,12 +15,12 @@ import (
|
|||
func TestAzSegment(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
ExpectedEnabled bool
|
||||
ExpectedString string
|
||||
HasCLI bool
|
||||
HasPowerShell bool
|
||||
Template string
|
||||
Source string
|
||||
ExpectedEnabled bool
|
||||
HasCLI bool
|
||||
HasPowerShell bool
|
||||
}{
|
||||
{
|
||||
Case: "no config files found",
|
||||
|
|
|
@ -17,8 +17,8 @@ type Azd struct {
|
|||
}
|
||||
|
||||
type azdConfig struct {
|
||||
Version int `json:"version"`
|
||||
DefaultEnvironment string `json:"defaultEnvironment"`
|
||||
Version int `json:"version"`
|
||||
}
|
||||
|
||||
func (t *Azd) Template() string {
|
||||
|
|
|
@ -16,9 +16,9 @@ import (
|
|||
func TestAzdSegment(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
ExpectedEnabled bool
|
||||
ExpectedString string
|
||||
Template string
|
||||
ExpectedEnabled bool
|
||||
IsInited bool
|
||||
}{
|
||||
{
|
||||
|
|
|
@ -6,9 +6,8 @@ import (
|
|||
)
|
||||
|
||||
type Bazel struct {
|
||||
language
|
||||
|
||||
Icon string
|
||||
language
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -16,20 +16,17 @@ import (
|
|||
|
||||
// segment struct, makes templating easier
|
||||
type Brewfather struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
DaysBottledOrFermented *uint
|
||||
TemperatureTrendIcon string
|
||||
StatusIcon string
|
||||
DayIcon string
|
||||
URL string
|
||||
Batch
|
||||
TemperatureTrendIcon string
|
||||
StatusIcon string
|
||||
DayIcon string // populated from day_icon for use in template
|
||||
|
||||
ReadingAge int // age in hours of the most recent reading included in the batch, -1 if none
|
||||
DaysFermenting uint
|
||||
DaysBottled uint
|
||||
DaysBottledOrFermented *uint // help avoid chronic template logic - code will point this to one of above or be nil depending on status
|
||||
|
||||
URL string // URL of batch page to open if hyperlink enabled on the segment and URL formatting used in template: «text»(link)
|
||||
ReadingAge int
|
||||
DaysFermenting uint
|
||||
DaysBottled uint
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -64,34 +61,28 @@ const (
|
|||
// Returned from https://api.brewfather.app/v1/batches/batch_id/readings
|
||||
type BatchReading struct {
|
||||
Comment string `json:"comment"`
|
||||
Gravity float64 `json:"sg"`
|
||||
DeviceType string `json:"type"`
|
||||
DeviceID string `json:"id"`
|
||||
Temperature float64 `json:"temp"` // celsius - need to add F conversion
|
||||
Timepoint int64 `json:"timepoint"` // << check what these are...
|
||||
Time int64 `json:"time"` // <<
|
||||
Gravity float64 `json:"sg"`
|
||||
Temperature float64 `json:"temp"`
|
||||
Timepoint int64 `json:"timepoint"`
|
||||
Time int64 `json:"time"`
|
||||
}
|
||||
type Batch struct {
|
||||
// Json tagged values returned from https://api.brewfather.app/v1/batches/batch_id
|
||||
Status string `json:"status"`
|
||||
BatchName string `json:"name"`
|
||||
BatchNumber int `json:"batchNo"`
|
||||
Recipe struct {
|
||||
Reading *BatchReading
|
||||
Status string `json:"status"`
|
||||
BatchName string `json:"name"`
|
||||
Recipe struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"recipe"`
|
||||
BrewDate int64 `json:"brewDate"`
|
||||
FermentStartDate int64 `json:"fermentationStartDate"`
|
||||
BottlingDate int64 `json:"bottlingDate"`
|
||||
|
||||
MeasuredOg float64 `json:"measuredOg"`
|
||||
MeasuredFg float64 `json:"measuredFg"`
|
||||
MeasuredAbv float64 `json:"measuredAbv"`
|
||||
|
||||
// copy of the latest BatchReading in here.
|
||||
Reading *BatchReading
|
||||
|
||||
// Calculated values we need to cache because they require the rest query to reproduce
|
||||
TemperatureTrend float64 // diff between this and last, short term trend
|
||||
BatchNumber int `json:"batchNo"`
|
||||
BrewDate int64 `json:"brewDate"`
|
||||
FermentStartDate int64 `json:"fermentationStartDate"`
|
||||
BottlingDate int64 `json:"bottlingDate"`
|
||||
MeasuredOg float64 `json:"measuredOg"`
|
||||
MeasuredFg float64 `json:"measuredFg"`
|
||||
MeasuredAbv float64 `json:"measuredAbv"`
|
||||
TemperatureTrend float64
|
||||
}
|
||||
|
||||
func (bf *Brewfather) Template() string {
|
||||
|
|
|
@ -52,13 +52,15 @@ func TestBrewfatherSegment(t *testing.T) {
|
|||
batchReadingJSON3 := `,"type":"manual"}, {"id":"manual","temp":15,"comment":"","sg":1.050,"time":`
|
||||
|
||||
cases := []struct {
|
||||
Error error
|
||||
Case string
|
||||
BatchJSONResponse string
|
||||
BatchReadingsJSONResponse string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
Template string
|
||||
Error error
|
||||
CacheTimeout int
|
||||
ExpectedEnabled bool
|
||||
CacheFoundFail bool
|
||||
}{
|
||||
{
|
||||
Case: "Planning Status",
|
||||
|
|
|
@ -22,15 +22,15 @@ type CarbonIntensityResponse struct {
|
|||
}
|
||||
|
||||
type CarbonIntensityPeriod struct {
|
||||
Intensity *CarbonIntensityData `json:"intensity"`
|
||||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
Intensity *CarbonIntensityData `json:"intensity"`
|
||||
}
|
||||
|
||||
type CarbonIntensityData struct {
|
||||
Index Index `json:"index"`
|
||||
Forecast Number `json:"forecast"`
|
||||
Actual Number `json:"actual"`
|
||||
Index Index `json:"index"`
|
||||
}
|
||||
|
||||
type Number int
|
||||
|
|
|
@ -20,14 +20,14 @@ const (
|
|||
func TestCarbonIntensitySegmentSingle(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
HasError bool
|
||||
HasData bool
|
||||
Actual int
|
||||
Forecast int
|
||||
Index string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
Template string
|
||||
Actual int
|
||||
Forecast int
|
||||
HasError bool
|
||||
HasData bool
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "Very Low, Going Down",
|
||||
|
|
|
@ -15,13 +15,13 @@ import (
|
|||
|
||||
func TestCFTargetSegment(t *testing.T) {
|
||||
cases := []struct {
|
||||
CommandError error
|
||||
FileInfo *runtime.FileInfo
|
||||
Case string
|
||||
Template string
|
||||
ExpectedString string
|
||||
DisplayMode string
|
||||
FileInfo *runtime.FileInfo
|
||||
TargetOutput string
|
||||
CommandError error
|
||||
}{
|
||||
{
|
||||
Case: "not logged in to CF account",
|
||||
|
|
|
@ -157,8 +157,8 @@ func TestExecuteScript(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
Output string
|
||||
HasScript bool
|
||||
ExpectedString string
|
||||
HasScript bool
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
|
|
|
@ -19,9 +19,9 @@ func TestConnection(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
ConnectionType string
|
||||
Connections []*connectionResponse
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "WiFi only, enabled",
|
||||
|
|
|
@ -15,12 +15,12 @@ func TestDockerSegment(t *testing.T) {
|
|||
value string
|
||||
}
|
||||
cases := []struct {
|
||||
EnvVar envVar
|
||||
Case string
|
||||
Expected string
|
||||
ExpectedEnabled bool
|
||||
EnvVar envVar
|
||||
HasFiles bool
|
||||
ConfigFile string
|
||||
ExpectedEnabled bool
|
||||
HasFiles bool
|
||||
}{
|
||||
{Case: "DOCKER_MACHINE_NAME", Expected: "alpine", ExpectedEnabled: true, EnvVar: envVar{name: "DOCKER_MACHINE_NAME", value: "alpine"}},
|
||||
{Case: "DOCKER_HOST", Expected: "alpine 2", ExpectedEnabled: true, EnvVar: envVar{name: "DOCKER_HOST", value: "alpine 2"}},
|
||||
|
|
|
@ -13,8 +13,8 @@ func TestDotnetSegment(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
Expected string
|
||||
ExitCode int
|
||||
Version string
|
||||
ExitCode int
|
||||
}{
|
||||
{Case: "Unsupported version", Expected: "\uf071", ExitCode: constants.DotnetExitCode, Version: "3.1.402"},
|
||||
{Case: "Regular version", Expected: "3.1.402", Version: "3.1.402"},
|
||||
|
|
|
@ -19,8 +19,8 @@ func TestFirebaseSegment(t *testing.T) {
|
|||
Case string
|
||||
ActiveConfig string
|
||||
ActivePath string
|
||||
ExpectedEnabled bool
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "happy path",
|
||||
|
|
|
@ -27,10 +27,9 @@ const (
|
|||
)
|
||||
|
||||
type Fossil struct {
|
||||
scm
|
||||
|
||||
Status *FossilStatus
|
||||
Branch string
|
||||
scm
|
||||
}
|
||||
|
||||
func (f *Fossil) Template() string {
|
||||
|
|
|
@ -13,12 +13,12 @@ import (
|
|||
|
||||
func TestFossilStatus(t *testing.T) {
|
||||
cases := []struct {
|
||||
OutputError error
|
||||
Case string
|
||||
Output string
|
||||
OutputError error
|
||||
HasCommand bool
|
||||
ExpectedStatus string
|
||||
ExpectedBranch string
|
||||
HasCommand bool
|
||||
ExpectedDisabled bool
|
||||
}{
|
||||
{
|
||||
|
|
|
@ -16,8 +16,8 @@ func TestGcpSegment(t *testing.T) {
|
|||
Case string
|
||||
CfgData string
|
||||
ActiveConfig string
|
||||
ExpectedEnabled bool
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "happy path",
|
||||
|
|
|
@ -16,13 +16,12 @@ import (
|
|||
)
|
||||
|
||||
type Commit struct {
|
||||
// git log -1 --pretty="format:%an%n%ae%n%cn%n%ce%n%at%n%s"
|
||||
Timestamp time.Time
|
||||
Author *User
|
||||
Committer *User
|
||||
Subject string
|
||||
Timestamp time.Time
|
||||
Sha string
|
||||
Refs *Refs
|
||||
Subject string
|
||||
Sha string
|
||||
}
|
||||
|
||||
type Refs struct {
|
||||
|
@ -129,37 +128,33 @@ const (
|
|||
)
|
||||
|
||||
type Git struct {
|
||||
scm
|
||||
|
||||
User *User
|
||||
Working *GitStatus
|
||||
Staging *GitStatus
|
||||
Ahead int
|
||||
Behind int
|
||||
HEAD string
|
||||
commit *Commit
|
||||
UpstreamURL string
|
||||
UpstreamIcon string
|
||||
Ref string
|
||||
Hash string
|
||||
ShortHash string
|
||||
BranchStatus string
|
||||
Upstream string
|
||||
UpstreamIcon string
|
||||
UpstreamURL string
|
||||
HEAD string
|
||||
RawUpstreamURL string
|
||||
UpstreamGone bool
|
||||
IsWorkTree bool
|
||||
IsBare bool
|
||||
User *User
|
||||
Detached bool
|
||||
Merge bool
|
||||
Rebase bool
|
||||
CherryPick bool
|
||||
Revert bool
|
||||
|
||||
// needed for posh-git support
|
||||
poshgit bool
|
||||
scm
|
||||
Ahead int
|
||||
stashCount int
|
||||
worktreeCount int
|
||||
|
||||
commit *Commit
|
||||
Behind int
|
||||
IsWorkTree bool
|
||||
Merge bool
|
||||
Rebase bool
|
||||
CherryPick bool
|
||||
Revert bool
|
||||
poshgit bool
|
||||
Detached bool
|
||||
IsBare bool
|
||||
UpstreamGone bool
|
||||
}
|
||||
|
||||
func (g *Git) Template() string {
|
||||
|
|
|
@ -74,13 +74,13 @@ func TestResolveEmptyGitPath(t *testing.T) {
|
|||
func TestEnabledInWorktree(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
ExpectedEnabled bool
|
||||
WorkingFolder string
|
||||
WorkingFolderAddon string
|
||||
WorkingFolderContent string
|
||||
ExpectedRealFolder string
|
||||
ExpectedWorkingFolder string
|
||||
ExpectedRootFolder string
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "worktree",
|
||||
|
@ -156,12 +156,12 @@ func TestEnabledInBareRepo(t *testing.T) {
|
|||
Case string
|
||||
HEAD string
|
||||
IsBare string
|
||||
FetchRemote bool
|
||||
Remote string
|
||||
RemoteURL string
|
||||
ExpectedEnabled bool
|
||||
ExpectedHEAD string
|
||||
ExpectedRemote string
|
||||
FetchRemote bool
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "Bare repo on main",
|
||||
|
@ -234,19 +234,19 @@ func TestGetGitOutputForCommand(t *testing.T) {
|
|||
|
||||
func TestSetGitHEADContextClean(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Ours string
|
||||
Expected string
|
||||
Ref string
|
||||
RebaseMerge bool
|
||||
RebaseApply bool
|
||||
Merge bool
|
||||
CherryPick bool
|
||||
Revert bool
|
||||
Sequencer bool
|
||||
Ours string
|
||||
Theirs string
|
||||
Step string
|
||||
Case string
|
||||
Total string
|
||||
Step string
|
||||
Theirs string
|
||||
RebaseMerge bool
|
||||
Sequencer bool
|
||||
Revert bool
|
||||
CherryPick bool
|
||||
Merge bool
|
||||
RebaseApply bool
|
||||
}{
|
||||
{Case: "detached on commit", Ref: DETACHED, Expected: "branch detached at commit 1234567"},
|
||||
{Case: "not detached, clean", Ref: "main", Expected: "branch main"},
|
||||
|
@ -428,16 +428,16 @@ func TestSetPrettyHEADName(t *testing.T) {
|
|||
|
||||
func TestSetGitStatus(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Output string
|
||||
ExpectedWorking *GitStatus
|
||||
ExpectedStaging *GitStatus
|
||||
Case string
|
||||
Output string
|
||||
ExpectedHash string
|
||||
ExpectedRef string
|
||||
ExpectedUpstream string
|
||||
ExpectedUpstreamGone bool
|
||||
ExpectedAhead int
|
||||
ExpectedBehind int
|
||||
ExpectedUpstreamGone bool
|
||||
Rebase bool
|
||||
Merge bool
|
||||
}{
|
||||
|
@ -610,8 +610,8 @@ func TestSetGitStatus(t *testing.T) {
|
|||
|
||||
func TestGetStashContextZeroEntries(t *testing.T) {
|
||||
cases := []struct {
|
||||
Expected int
|
||||
StashContent string
|
||||
Expected int
|
||||
}{
|
||||
{Expected: 0, StashContent: ""},
|
||||
{Expected: 2, StashContent: "1\n2\n"},
|
||||
|
@ -714,9 +714,9 @@ func TestGetBranchStatus(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
Expected string
|
||||
Upstream string
|
||||
Ahead int
|
||||
Behind int
|
||||
Upstream string
|
||||
UpstreamGone bool
|
||||
}{
|
||||
{Case: "Equal with remote", Expected: "equal", Upstream: branchName},
|
||||
|
@ -751,10 +751,10 @@ func TestGetBranchStatus(t *testing.T) {
|
|||
|
||||
func TestGitTemplateString(t *testing.T) {
|
||||
cases := []struct {
|
||||
Git *Git
|
||||
Case string
|
||||
Expected string
|
||||
Template string
|
||||
Git *Git
|
||||
}{
|
||||
{
|
||||
Case: "Only HEAD name",
|
||||
|
@ -886,9 +886,9 @@ func TestGitTemplateString(t *testing.T) {
|
|||
|
||||
func TestGitUntrackedMode(t *testing.T) {
|
||||
cases := []struct {
|
||||
UntrackedModes map[string]string
|
||||
Case string
|
||||
Expected string
|
||||
UntrackedModes map[string]string
|
||||
}{
|
||||
{
|
||||
Case: "Default mode - no map",
|
||||
|
@ -934,9 +934,9 @@ func TestGitUntrackedMode(t *testing.T) {
|
|||
|
||||
func TestGitIgnoreSubmodules(t *testing.T) {
|
||||
cases := []struct {
|
||||
IgnoreSubmodules map[string]string
|
||||
Case string
|
||||
Expected string
|
||||
IgnoreSubmodules map[string]string
|
||||
}{
|
||||
{
|
||||
Case: "Overide",
|
||||
|
@ -1107,8 +1107,8 @@ func TestGitCommit(t *testing.T) {
|
|||
func TestGitRemotes(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected int
|
||||
Config string
|
||||
Expected int
|
||||
}{
|
||||
{
|
||||
Case: "Empty config file",
|
||||
|
|
|
@ -8,39 +8,39 @@ import (
|
|||
)
|
||||
|
||||
type gitVersion struct {
|
||||
Major int `json:"Major"`
|
||||
Minor int `json:"Minor"`
|
||||
Patch int `json:"Patch"`
|
||||
PreReleaseTag string `json:"PreReleaseTag"`
|
||||
NuGetVersionV2 string `json:"NuGetVersionV2"`
|
||||
FullSemVer string `json:"FullSemVer"`
|
||||
CommitDate string `json:"CommitDate"`
|
||||
AssemblySemVer string `json:"AssemblySemVer"`
|
||||
PreReleaseTagWithDash string `json:"PreReleaseTagWithDash"`
|
||||
PreReleaseLabel string `json:"PreReleaseLabel"`
|
||||
PreReleaseLabelWithDash string `json:"PreReleaseLabelWithDash"`
|
||||
PreReleaseNumber int `json:"PreReleaseNumber"`
|
||||
WeightedPreReleaseNumber int `json:"WeightedPreReleaseNumber"`
|
||||
BuildMetaData int `json:"BuildMetaData"`
|
||||
AssemblySemFileVer string `json:"AssemblySemFileVer"`
|
||||
CommitsSinceVersionSourcePadded string `json:"CommitsSinceVersionSourcePadded"`
|
||||
VersionSourceSha string `json:"VersionSourceSha"`
|
||||
BuildMetaDataPadded string `json:"BuildMetaDataPadded"`
|
||||
FullBuildMetaData string `json:"FullBuildMetaData"`
|
||||
MajorMinorPatch string `json:"MajorMinorPatch"`
|
||||
SemVer string `json:"SemVer"`
|
||||
NuGetVersion string `json:"NuGetVersion"`
|
||||
LegacySemVer string `json:"LegacySemVer"`
|
||||
LegacySemVerPadded string `json:"LegacySemVerPadded"`
|
||||
AssemblySemVer string `json:"AssemblySemVer"`
|
||||
AssemblySemFileVer string `json:"AssemblySemFileVer"`
|
||||
FullSemVer string `json:"FullSemVer"`
|
||||
PreReleaseTag string `json:"PreReleaseTag"`
|
||||
NuGetPreReleaseTag string `json:"NuGetPreReleaseTag"`
|
||||
SemVer string `json:"SemVer"`
|
||||
InformationalVersion string `json:"InformationalVersion"`
|
||||
BranchName string `json:"BranchName"`
|
||||
EscapedBranchName string `json:"EscapedBranchName"`
|
||||
Sha string `json:"Sha"`
|
||||
ShortSha string `json:"ShortSha"`
|
||||
NuGetVersionV2 string `json:"NuGetVersionV2"`
|
||||
NuGetVersion string `json:"NuGetVersion"`
|
||||
NuGetPreReleaseTagV2 string `json:"NuGetPreReleaseTagV2"`
|
||||
NuGetPreReleaseTag string `json:"NuGetPreReleaseTag"`
|
||||
VersionSourceSha string `json:"VersionSourceSha"`
|
||||
BuildMetaData int `json:"BuildMetaData"`
|
||||
Major int `json:"Major"`
|
||||
PreReleaseNumber int `json:"PreReleaseNumber"`
|
||||
Minor int `json:"Minor"`
|
||||
CommitsSinceVersionSource int `json:"CommitsSinceVersionSource"`
|
||||
CommitsSinceVersionSourcePadded string `json:"CommitsSinceVersionSourcePadded"`
|
||||
WeightedPreReleaseNumber int `json:"WeightedPreReleaseNumber"`
|
||||
UncommittedChanges int `json:"UncommittedChanges"`
|
||||
CommitDate string `json:"CommitDate"`
|
||||
Patch int `json:"Patch"`
|
||||
}
|
||||
|
||||
type GitVersion struct {
|
||||
|
|
|
@ -12,13 +12,16 @@ import (
|
|||
|
||||
func TestGitversion(t *testing.T) {
|
||||
cases := []struct {
|
||||
CacheError error
|
||||
CommandError error
|
||||
Case string
|
||||
ExpectedEnabled bool
|
||||
ExpectedString string
|
||||
Response string
|
||||
HasGitversion bool
|
||||
CacheResponse string
|
||||
Template string
|
||||
CommandError error
|
||||
CacheTimeout int
|
||||
ExpectedEnabled bool
|
||||
HasGitversion bool
|
||||
}{
|
||||
{Case: "GitVersion not installed"},
|
||||
{Case: "GitVersion installed, no GitVersion.yml file", HasGitversion: true, Response: "Cannot find the .git directory"},
|
||||
|
|
|
@ -15,12 +15,12 @@ import (
|
|||
func TestHelmSegment(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
HelmExists bool
|
||||
ExpectedEnabled bool
|
||||
ExpectedString string
|
||||
Template string
|
||||
DisplayMode string
|
||||
ChartFile string
|
||||
HelmExists bool
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "Helm not installed",
|
||||
|
|
|
@ -26,9 +26,8 @@ func (i *ipAPI) Get() (*ipData, error) {
|
|||
}
|
||||
|
||||
type IPify struct {
|
||||
IP string
|
||||
|
||||
api IPAPI
|
||||
IP string
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -19,12 +19,9 @@ const (
|
|||
type Kubectl struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
|
||||
dirty bool
|
||||
|
||||
Context string
|
||||
|
||||
KubeContext
|
||||
Context string
|
||||
dirty bool
|
||||
}
|
||||
|
||||
type KubeConfig struct {
|
||||
|
|
|
@ -23,21 +23,21 @@ func TestKubectlSegment(t *testing.T) {
|
|||
lsep := string(filepath.ListSeparator)
|
||||
|
||||
cases := []struct {
|
||||
Case string
|
||||
Template string
|
||||
DisplayError bool
|
||||
KubectlExists bool
|
||||
Files map[string]string
|
||||
ContextAliases map[string]string
|
||||
Cluster string
|
||||
Kubeconfig string
|
||||
ParseKubeConfig bool
|
||||
Context string
|
||||
Namespace string
|
||||
UserName string
|
||||
Cluster string
|
||||
Case string
|
||||
ExpectedString string
|
||||
Template string
|
||||
KubectlExists bool
|
||||
ParseKubeConfig bool
|
||||
KubectlErr bool
|
||||
ExpectedEnabled bool
|
||||
ExpectedString string
|
||||
Files map[string]string
|
||||
ContextAliases map[string]string
|
||||
DisplayError bool
|
||||
}{
|
||||
{
|
||||
Case: "kubeconfig incomplete",
|
||||
|
|
|
@ -35,11 +35,11 @@ type version struct {
|
|||
}
|
||||
|
||||
type cmd struct {
|
||||
executable string
|
||||
args []string
|
||||
regex string
|
||||
getVersion getVersion
|
||||
executable string
|
||||
regex string
|
||||
versionURLTemplate string
|
||||
args []string
|
||||
}
|
||||
|
||||
func (c *cmd) parse(versionInfo string) (*version, error) {
|
||||
|
@ -60,25 +60,23 @@ func (c *cmd) parse(versionInfo string) (*version, error) {
|
|||
}
|
||||
|
||||
type language struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
extensions []string
|
||||
folders []string
|
||||
commands []*cmd
|
||||
versionURLTemplate string
|
||||
exitCode int
|
||||
props properties.Properties
|
||||
projectRoot *runtime.FileInfo
|
||||
loadContext loadContext
|
||||
inContext inContext
|
||||
matchesVersionFile matchesVersionFile
|
||||
homeEnabled bool
|
||||
displayMode string
|
||||
// root is the root folder of the project
|
||||
projectFiles []string
|
||||
projectRoot *runtime.FileInfo
|
||||
|
||||
version
|
||||
Error string
|
||||
Mismatch bool
|
||||
displayMode string
|
||||
Error string
|
||||
versionURLTemplate string
|
||||
commands []*cmd
|
||||
projectFiles []string
|
||||
folders []string
|
||||
extensions []string
|
||||
exitCode int
|
||||
homeEnabled bool
|
||||
Mismatch bool
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -19,15 +19,15 @@ const (
|
|||
)
|
||||
|
||||
type languageArgs struct {
|
||||
expectedError error
|
||||
properties properties.Properties
|
||||
matchesVersionFile matchesVersionFile
|
||||
version string
|
||||
versionURLTemplate string
|
||||
extensions []string
|
||||
enabledExtensions []string
|
||||
commands []*cmd
|
||||
enabledCommands []string
|
||||
versionURLTemplate string
|
||||
expectedError error
|
||||
properties properties.Properties
|
||||
matchesVersionFile matchesVersionFile
|
||||
inHome bool
|
||||
}
|
||||
|
||||
|
|
|
@ -17,12 +17,12 @@ const (
|
|||
|
||||
func TestLFMSegmentSingle(t *testing.T) {
|
||||
cases := []struct {
|
||||
Error error
|
||||
Case string
|
||||
APIJSONResponse string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
Template string
|
||||
Error error
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "All Defaults",
|
||||
|
|
|
@ -13,10 +13,10 @@ func TestLua(t *testing.T) {
|
|||
Case string
|
||||
ExpectedString string
|
||||
Version string
|
||||
HasLua bool
|
||||
HasLuaJit bool
|
||||
Prefer string
|
||||
ExpectedURL string
|
||||
HasLua bool
|
||||
HasLuaJit bool
|
||||
}{
|
||||
{
|
||||
Case: "Lua 5.4.4 - Prefer Lua",
|
||||
|
|
|
@ -30,16 +30,15 @@ func (s *MercurialStatus) add(code string) {
|
|||
}
|
||||
|
||||
type Mercurial struct {
|
||||
scm
|
||||
|
||||
Working *MercurialStatus
|
||||
IsTip bool
|
||||
LocalCommitNumber string
|
||||
ChangeSetID string
|
||||
ChangeSetIDShort string
|
||||
Branch string
|
||||
Bookmarks []string
|
||||
Tags []string
|
||||
scm
|
||||
Bookmarks []string
|
||||
Tags []string
|
||||
IsTip bool
|
||||
}
|
||||
|
||||
func (hg *Mercurial) Template() string {
|
||||
|
|
|
@ -56,17 +56,17 @@ func TestMercurialEnabledInWorkingDirectory(t *testing.T) {
|
|||
|
||||
func TestMercurialGetIdInfo(t *testing.T) {
|
||||
cases := []struct {
|
||||
ExpectedWorking *MercurialStatus
|
||||
Case string
|
||||
LogOutput string
|
||||
StatusOutput string
|
||||
ExpectedWorking *MercurialStatus
|
||||
ExpectedBranch string
|
||||
ExpectedChangeSetID string
|
||||
ExpectedShortID string
|
||||
ExpectedLocalCommitNumber string
|
||||
ExpectedIsTip bool
|
||||
ExpectedBookmarks []string
|
||||
ExpectedTags []string
|
||||
ExpectedIsTip bool
|
||||
}{
|
||||
{
|
||||
Case: "nochanges_tip",
|
||||
|
|
|
@ -15,8 +15,8 @@ func TestMvn(t *testing.T) {
|
|||
Case string
|
||||
ExpectedString string
|
||||
MvnVersion string
|
||||
HasMvnw bool
|
||||
MvnwVersion string
|
||||
HasMvnw bool
|
||||
}{
|
||||
{
|
||||
Case: "Maven version",
|
||||
|
|
|
@ -107,11 +107,11 @@ type Scoreboard struct {
|
|||
}
|
||||
|
||||
type Game struct {
|
||||
GameStatus int `json:"gameStatus"`
|
||||
GameStatusText string `json:"gameStatusText"`
|
||||
GameTimeUTC string `json:"gameTimeUTC"`
|
||||
HomeTeam Team `json:"homeTeam"`
|
||||
AwayTeam Team `json:"awayTeam"`
|
||||
GameStatus int `json:"gameStatus"`
|
||||
}
|
||||
|
||||
type Team struct {
|
||||
|
|
|
@ -24,13 +24,15 @@ func TestNBASegment(t *testing.T) {
|
|||
jsonScoreData := getTestData("nba/score.json")
|
||||
|
||||
cases := []struct {
|
||||
Error error
|
||||
Case string
|
||||
JSONResponse string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
TeamName string
|
||||
CacheTimeout int
|
||||
DaysOffset int
|
||||
Error error
|
||||
ExpectedEnabled bool
|
||||
CacheFoundFail bool
|
||||
}{
|
||||
{
|
||||
Case: "Team (Home Team) Scheduled Game",
|
||||
|
|
|
@ -15,7 +15,6 @@ type Nbgv struct {
|
|||
}
|
||||
|
||||
type VersionInfo struct {
|
||||
VersionFileFound bool `json:"VersionFileFound"`
|
||||
Version string `json:"Version"`
|
||||
AssemblyVersion string `json:"AssemblyVersion"`
|
||||
AssemblyInformationalVersion string `json:"AssemblyInformationalVersion"`
|
||||
|
@ -23,6 +22,7 @@ type VersionInfo struct {
|
|||
ChocolateyPackageVersion string `json:"ChocolateyPackageVersion"`
|
||||
NpmPackageVersion string `json:"NpmPackageVersion"`
|
||||
SimpleVersion string `json:"SimpleVersion"`
|
||||
VersionFileFound bool `json:"VersionFileFound"`
|
||||
}
|
||||
|
||||
func (n *Nbgv) Template() string {
|
||||
|
|
|
@ -12,13 +12,13 @@ import (
|
|||
|
||||
func TestNbgv(t *testing.T) {
|
||||
cases := []struct {
|
||||
Error error
|
||||
Case string
|
||||
ExpectedEnabled bool
|
||||
ExpectedString string
|
||||
Response string
|
||||
HasNbgv bool
|
||||
Template string
|
||||
Error error
|
||||
ExpectedEnabled bool
|
||||
HasNbgv bool
|
||||
}{
|
||||
{Case: "nbgv not installed"},
|
||||
{Case: "nbgv installed, no version file", HasNbgv: true, Response: "{ \"VersionFileFound\": false }"},
|
||||
|
|
|
@ -12,11 +12,10 @@ import (
|
|||
|
||||
// segment struct, makes templating easier
|
||||
type Nightscout struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
|
||||
NightscoutData
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
TrendIcon string
|
||||
NightscoutData
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -35,16 +34,16 @@ const (
|
|||
|
||||
// NightscoutData struct contains the API data
|
||||
type NightscoutData struct {
|
||||
ID string `json:"_id"`
|
||||
Sgv int `json:"sgv"`
|
||||
Date int64 `json:"date"`
|
||||
DateString time.Time `json:"dateString"`
|
||||
Trend int `json:"trend"`
|
||||
SysTime time.Time `json:"sysTime"`
|
||||
ID string `json:"_id"`
|
||||
Direction string `json:"direction"`
|
||||
Device string `json:"device"`
|
||||
Type string `json:"type"`
|
||||
Sgv int `json:"sgv"`
|
||||
Date int64 `json:"date"`
|
||||
Trend int `json:"trend"`
|
||||
UtcOffset int `json:"utcOffset"`
|
||||
SysTime time.Time `json:"sysTime"`
|
||||
Mills int64 `json:"mills"`
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,14 @@ const (
|
|||
|
||||
func TestNSSegment(t *testing.T) {
|
||||
cases := []struct {
|
||||
Error error
|
||||
Case string
|
||||
JSONResponse string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
Template string
|
||||
Error error
|
||||
CacheTimeout int
|
||||
ExpectedEnabled bool
|
||||
CacheFoundFail bool
|
||||
}{
|
||||
{
|
||||
Case: "Flat 150",
|
||||
|
|
|
@ -10,9 +10,8 @@ import (
|
|||
)
|
||||
|
||||
type Node struct {
|
||||
language
|
||||
|
||||
PackageManagerIcon string
|
||||
language
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -18,9 +18,9 @@ func TestNodeMatchesVersionFile(t *testing.T) {
|
|||
}
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected bool
|
||||
ExpectedVersion string
|
||||
RCVersion string
|
||||
Expected bool
|
||||
}{
|
||||
{Case: "no file context", Expected: true, RCVersion: ""},
|
||||
{Case: "version match", Expected: true, ExpectedVersion: "20.14.0", RCVersion: "20.14.0"},
|
||||
|
@ -55,12 +55,12 @@ func TestNodeMatchesVersionFile(t *testing.T) {
|
|||
func TestNodeInContext(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
hasPNPM bool
|
||||
hasYarn bool
|
||||
hasNPM bool
|
||||
hasDefault bool
|
||||
PkgMgrEnabled bool
|
||||
ExpectedString string
|
||||
}{
|
||||
{Case: "no package manager file", ExpectedString: "", PkgMgrEnabled: true},
|
||||
{Case: "pnpm", hasPNPM: true, ExpectedString: "pnpm", PkgMgrEnabled: true},
|
||||
|
|
|
@ -15,10 +15,10 @@ func TestOSInfo(t *testing.T) {
|
|||
Case string
|
||||
ExpectedString string
|
||||
GOOS string
|
||||
IsWSL bool
|
||||
Platform string
|
||||
DisplayDistroName bool
|
||||
Icon string
|
||||
IsWSL bool
|
||||
DisplayDistroName bool
|
||||
}{
|
||||
{
|
||||
Case: "WSL debian - icon",
|
||||
|
|
|
@ -12,14 +12,13 @@ import (
|
|||
)
|
||||
|
||||
type Owm struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
|
||||
Temperature int
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
Weather string
|
||||
URL string
|
||||
units string
|
||||
UnitIcon string
|
||||
Temperature int
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -19,13 +19,13 @@ const (
|
|||
|
||||
func TestOWMSegmentSingle(t *testing.T) {
|
||||
cases := []struct {
|
||||
Error error
|
||||
Case string
|
||||
Location string
|
||||
WeatherJSONResponse string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
Template string
|
||||
Error error
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "Sunny Display",
|
||||
|
|
|
@ -15,8 +15,8 @@ import (
|
|||
|
||||
type Folder struct {
|
||||
Name string
|
||||
Display bool
|
||||
Path string
|
||||
Display bool
|
||||
}
|
||||
|
||||
type Folders []*Folder
|
||||
|
@ -32,25 +32,21 @@ func (f Folders) List() []string {
|
|||
}
|
||||
|
||||
type Path struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
|
||||
pwd string
|
||||
root string
|
||||
relative string
|
||||
folders Folders
|
||||
// After `setPaths` is called, the above 4 fields should remain unchanged to preserve the original path info.
|
||||
|
||||
cygPath bool
|
||||
windowsPath bool
|
||||
pathSeparator string
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
mappedLocations map[string]string
|
||||
|
||||
Path string
|
||||
StackCount int
|
||||
Location string
|
||||
Writable bool
|
||||
RootDir bool
|
||||
root string
|
||||
relative string
|
||||
pwd string
|
||||
Location string
|
||||
pathSeparator string
|
||||
Path string
|
||||
Folders Folders
|
||||
StackCount int
|
||||
windowsPath bool
|
||||
Writable bool
|
||||
RootDir bool
|
||||
cygPath bool
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -142,7 +138,7 @@ func (pt *Path) Enabled() bool {
|
|||
|
||||
func (pt *Path) setPaths() {
|
||||
defer func() {
|
||||
pt.folders = pt.splitPath()
|
||||
pt.Folders = pt.splitPath()
|
||||
}()
|
||||
|
||||
displayCygpath := func() bool {
|
||||
|
@ -177,7 +173,7 @@ func (pt *Path) Parent() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
folders := pt.folders.List()
|
||||
folders := pt.Folders.List()
|
||||
if len(folders) == 0 {
|
||||
// No parent.
|
||||
return ""
|
||||
|
@ -300,7 +296,7 @@ func (pt *Path) getFolderSeparator() string {
|
|||
|
||||
func (pt *Path) getMixedPath() string {
|
||||
root := pt.root
|
||||
folders := pt.folders
|
||||
folders := pt.Folders
|
||||
threshold := int(pt.props.GetFloat64(MixedThreshold, 4))
|
||||
folderIcon := pt.props.GetString(FolderIcon, "..")
|
||||
|
||||
|
@ -326,7 +322,7 @@ func (pt *Path) getMixedPath() string {
|
|||
|
||||
func (pt *Path) getAgnosterPath() string {
|
||||
root := pt.root
|
||||
folders := pt.folders
|
||||
folders := pt.Folders
|
||||
folderIcon := pt.props.GetString(FolderIcon, "..")
|
||||
|
||||
if pt.isRootFS(root) {
|
||||
|
@ -350,7 +346,7 @@ func (pt *Path) getAgnosterPath() string {
|
|||
|
||||
func (pt *Path) getAgnosterLeftPath() string {
|
||||
root := pt.root
|
||||
folders := pt.folders
|
||||
folders := pt.Folders
|
||||
folderIcon := pt.props.GetString(FolderIcon, "..")
|
||||
|
||||
if pt.isRootFS(root) {
|
||||
|
@ -391,7 +387,7 @@ func (pt *Path) getRelevantLetter(folder *Folder) string {
|
|||
|
||||
func (pt *Path) getLetterPath() string {
|
||||
root := pt.root
|
||||
folders := pt.folders
|
||||
folders := pt.Folders
|
||||
|
||||
if pt.isRootFS(root) {
|
||||
root = folders[0].Name
|
||||
|
@ -416,7 +412,7 @@ func (pt *Path) getLetterPath() string {
|
|||
|
||||
func (pt *Path) getUniqueLettersPath(maxWidth int) string {
|
||||
root := pt.root
|
||||
folders := pt.folders
|
||||
folders := pt.Folders
|
||||
separator := pt.getFolderSeparator()
|
||||
|
||||
if pt.isRootFS(root) {
|
||||
|
@ -484,7 +480,7 @@ func (pt *Path) getUniqueLettersPath(maxWidth int) string {
|
|||
|
||||
func (pt *Path) getAgnosterFullPath() string {
|
||||
root := pt.root
|
||||
folders := pt.folders
|
||||
folders := pt.Folders
|
||||
|
||||
if pt.isRootFS(root) {
|
||||
root = folders[0].Name
|
||||
|
@ -496,7 +492,7 @@ func (pt *Path) getAgnosterFullPath() string {
|
|||
|
||||
func (pt *Path) getAgnosterShortPath() string {
|
||||
root := pt.root
|
||||
folders := pt.folders
|
||||
folders := pt.Folders
|
||||
|
||||
if pt.isRootFS(root) {
|
||||
root = folders[0].Name
|
||||
|
@ -531,11 +527,11 @@ func (pt *Path) getAgnosterShortPath() string {
|
|||
}
|
||||
|
||||
func (pt *Path) getFullPath() string {
|
||||
return pt.colorizePath(pt.root, pt.folders.List())
|
||||
return pt.colorizePath(pt.root, pt.Folders.List())
|
||||
}
|
||||
|
||||
func (pt *Path) getFolderPath() string {
|
||||
folderName := pt.folders[len(pt.folders)-1].Name
|
||||
folderName := pt.Folders[len(pt.Folders)-1].Name
|
||||
return pt.colorizePath(folderName, nil)
|
||||
}
|
||||
|
||||
|
|
|
@ -165,18 +165,18 @@ func TestParent(t *testing.T) {
|
|||
|
||||
func TestAgnosterPathStyles(t *testing.T) {
|
||||
cases := []struct {
|
||||
Style string
|
||||
Expected string
|
||||
HomePath string
|
||||
CygpathError error
|
||||
GOOS string
|
||||
Shell string
|
||||
Pswd string
|
||||
Pwd string
|
||||
PathSeparator string
|
||||
HomeIcon string
|
||||
HomePath string
|
||||
Style string
|
||||
FolderSeparatorIcon string
|
||||
GOOS string
|
||||
Shell string
|
||||
Cygpath string
|
||||
CygpathError error
|
||||
Expected string
|
||||
MaxDepth int
|
||||
MaxWidth int
|
||||
HideRootLocation bool
|
||||
|
@ -816,11 +816,11 @@ func TestFullAndFolderPath(t *testing.T) {
|
|||
Pwd string
|
||||
Pswd string
|
||||
Expected string
|
||||
DisableMappedLocations bool
|
||||
GOOS string
|
||||
PathSeparator string
|
||||
StackCount int
|
||||
Template string
|
||||
StackCount int
|
||||
DisableMappedLocations bool
|
||||
}{
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", Expected: "/"},
|
||||
{Style: Full, Pwd: "/", Expected: "/"},
|
||||
|
@ -1368,10 +1368,10 @@ func TestAgnosterLeftPath(t *testing.T) {
|
|||
|
||||
func TestGetPwd(t *testing.T) {
|
||||
cases := []struct {
|
||||
MappedLocationsEnabled bool
|
||||
Pwd string
|
||||
Pswd string
|
||||
Expected string
|
||||
MappedLocationsEnabled bool
|
||||
}{
|
||||
{MappedLocationsEnabled: true, Pwd: homeDir, Expected: "~"},
|
||||
{MappedLocationsEnabled: true, Pwd: homeDir + "-test", Expected: homeDir + "-test"},
|
||||
|
@ -1604,8 +1604,8 @@ func TestReplaceMappedLocations(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
Pwd string
|
||||
MappedLocationsEnabled bool
|
||||
Expected string
|
||||
MappedLocationsEnabled bool
|
||||
}{
|
||||
{Pwd: "/c/l/k/f", Expected: "f"},
|
||||
{Pwd: "/f/g/h", Expected: "/f/g/h"},
|
||||
|
@ -1721,8 +1721,8 @@ func TestSplitPath(t *testing.T) {
|
|||
|
||||
func TestGetMaxWidth(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
MaxWidth any
|
||||
Case string
|
||||
Expected int
|
||||
}{
|
||||
{
|
||||
|
|
|
@ -28,14 +28,12 @@ func (s *PlasticStatus) add(code string) {
|
|||
}
|
||||
|
||||
type Plastic struct {
|
||||
Status *PlasticStatus
|
||||
Selector string
|
||||
plasticWorkspaceFolder string
|
||||
scm
|
||||
|
||||
Status *PlasticStatus
|
||||
Behind bool
|
||||
Selector string
|
||||
MergePending bool
|
||||
|
||||
plasticWorkspaceFolder string // root folder of workspace
|
||||
}
|
||||
|
||||
func (p *Plastic) Init(props properties.Properties, env runtime.Environment) {
|
||||
|
|
|
@ -69,9 +69,9 @@ func TestPlasticGetCmOutputForCommand(t *testing.T) {
|
|||
func TestPlasticStatusBehind(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected bool
|
||||
Status string
|
||||
Head string
|
||||
Expected bool
|
||||
}{
|
||||
{
|
||||
Case: "Not behind",
|
||||
|
@ -97,8 +97,8 @@ func TestPlasticStatusBehind(t *testing.T) {
|
|||
func TestPlasticStatusChanged(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected bool
|
||||
Status string
|
||||
Expected bool
|
||||
}{
|
||||
{
|
||||
Case: "No changes",
|
||||
|
@ -164,8 +164,8 @@ func TestPlasticStatusCounts(t *testing.T) {
|
|||
func TestPlasticMergePending(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected bool
|
||||
Status string
|
||||
Expected bool
|
||||
}{
|
||||
{
|
||||
Case: "No pending merge",
|
||||
|
@ -188,10 +188,10 @@ func TestPlasticMergePending(t *testing.T) {
|
|||
func TestPlasticParseIntPattern(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected int
|
||||
Text string
|
||||
Pattern string
|
||||
Name string
|
||||
Expected int
|
||||
Default int
|
||||
}{
|
||||
{
|
||||
|
@ -287,10 +287,10 @@ func TestPlasticStatus(t *testing.T) {
|
|||
|
||||
func TestPlasticTemplateString(t *testing.T) {
|
||||
cases := []struct {
|
||||
Plastic *Plastic
|
||||
Case string
|
||||
Expected string
|
||||
Template string
|
||||
Plastic *Plastic
|
||||
}{
|
||||
{
|
||||
Case: "Default template",
|
||||
|
|
|
@ -11,18 +11,18 @@ const (
|
|||
)
|
||||
|
||||
type poshGit struct {
|
||||
Index *poshGitStatus `json:"Index"`
|
||||
Working *poshGitStatus `json:"Working"`
|
||||
RepoName string `json:"RepoName"`
|
||||
Branch string `json:"Branch"`
|
||||
GitDir string `json:"GitDir"`
|
||||
Upstream string `json:"Upstream"`
|
||||
StashCount int `json:"StashCount"`
|
||||
AheadBy int `json:"AheadBy"`
|
||||
Index *poshGitStatus `json:"Index"`
|
||||
RepoName string `json:"RepoName"`
|
||||
HasWorking bool `json:"HasWorking"`
|
||||
Branch string `json:"Branch"`
|
||||
HasIndex bool `json:"HasIndex"`
|
||||
GitDir string `json:"GitDir"`
|
||||
BehindBy int `json:"BehindBy"`
|
||||
HasWorking bool `json:"HasWorking"`
|
||||
HasIndex bool `json:"HasIndex"`
|
||||
HasUntracked bool `json:"HasUntracked"`
|
||||
Working *poshGitStatus `json:"Working"`
|
||||
Upstream string `json:"Upstream"`
|
||||
}
|
||||
|
||||
type poshGitStatus struct {
|
||||
|
|
|
@ -15,9 +15,9 @@ func TestPoshGitSegment(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
PoshGitJSON string
|
||||
FetchUpstreamIcon bool
|
||||
Template string
|
||||
ExpectedString string
|
||||
FetchUpstreamIcon bool
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
|
|
|
@ -16,9 +16,9 @@ import (
|
|||
)
|
||||
|
||||
type ProjectItem struct {
|
||||
Fetcher func(item ProjectItem) *ProjectData
|
||||
Name string
|
||||
Files []string
|
||||
Fetcher func(item ProjectItem) *ProjectData
|
||||
}
|
||||
|
||||
type ProjectData struct {
|
||||
|
@ -54,11 +54,9 @@ type NuSpec struct {
|
|||
type Project struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
|
||||
projects []*ProjectItem
|
||||
Error string
|
||||
|
||||
ProjectData
|
||||
Error string
|
||||
projects []*ProjectItem
|
||||
}
|
||||
|
||||
func (n *Project) Enabled() bool {
|
||||
|
|
|
@ -19,11 +19,11 @@ const (
|
|||
)
|
||||
|
||||
type MockDirEntry struct {
|
||||
name string
|
||||
isDir bool
|
||||
fileMode fs.FileMode
|
||||
fileInfo fs.FileInfo
|
||||
err error
|
||||
name string
|
||||
fileMode fs.FileMode
|
||||
isDir bool
|
||||
}
|
||||
|
||||
func (m *MockDirEntry) Name() string {
|
||||
|
@ -276,9 +276,9 @@ func TestPackage(t *testing.T) {
|
|||
func TestNuspecPackage(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
HasFiles bool
|
||||
FileName string
|
||||
ExpectedString string
|
||||
HasFiles bool
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
|
@ -342,9 +342,9 @@ func TestDotnetProject(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
FileName string
|
||||
HasFiles bool
|
||||
ProjectContents string
|
||||
ExpectedString string
|
||||
HasFiles bool
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
|
@ -415,8 +415,8 @@ func TestDotnetProject(t *testing.T) {
|
|||
func TestPowerShellModuleProject(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
HasFiles bool
|
||||
ExpectedString string
|
||||
HasFiles bool
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
|
|
|
@ -13,26 +13,21 @@ import (
|
|||
|
||||
func TestPulumi(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
YAMLConfig string
|
||||
JSONConfig string
|
||||
|
||||
HasCommand bool
|
||||
|
||||
FetchStack bool
|
||||
Stack string
|
||||
StackError error
|
||||
|
||||
HasWorkspaceFolder bool
|
||||
StackError error
|
||||
AboutError error
|
||||
About string
|
||||
YAMLConfig string
|
||||
JSONConfig string
|
||||
Case string
|
||||
ExpectedString string
|
||||
Stack string
|
||||
AboutCache string
|
||||
WorkSpaceFile string
|
||||
|
||||
FetchAbout bool
|
||||
About string
|
||||
AboutError error
|
||||
AboutCache string
|
||||
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
HasCommand bool
|
||||
FetchAbout bool
|
||||
HasWorkspaceFolder bool
|
||||
FetchStack bool
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "no pulumi command",
|
||||
|
|
|
@ -12,9 +12,8 @@ import (
|
|||
)
|
||||
|
||||
type Python struct {
|
||||
language
|
||||
|
||||
Venv string
|
||||
language
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -15,19 +15,19 @@ import (
|
|||
|
||||
func TestPythonTemplate(t *testing.T) {
|
||||
type ResolveSymlink struct {
|
||||
Path string
|
||||
Err error
|
||||
Path string
|
||||
}
|
||||
cases := []struct {
|
||||
ResolveSymlink ResolveSymlink
|
||||
Case string
|
||||
Expected string
|
||||
ExpectedDisabled bool
|
||||
Template string
|
||||
VirtualEnvName string
|
||||
FetchVersion bool
|
||||
PythonPath string
|
||||
ResolveSymlink ResolveSymlink
|
||||
PyvenvCfg string
|
||||
ExpectedDisabled bool
|
||||
FetchVersion bool
|
||||
}{
|
||||
{Case: "No virtual env present", FetchVersion: true, Expected: "3.8.4", Template: "{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}"},
|
||||
{Case: "Virtual env present", FetchVersion: true, Expected: "VENV 3.8.4", VirtualEnvName: "VENV", Template: "{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}"},
|
||||
|
@ -123,8 +123,8 @@ func TestPythonTemplate(t *testing.T) {
|
|||
|
||||
func TestPythonPythonInContext(t *testing.T) {
|
||||
cases := []struct {
|
||||
Expected bool
|
||||
VirtualEnvName string
|
||||
Expected bool
|
||||
}{
|
||||
{Expected: true, VirtualEnvName: "VENV"},
|
||||
{Expected: false, VirtualEnvName: ""},
|
||||
|
@ -151,8 +151,8 @@ func TestPythonPythonInContext(t *testing.T) {
|
|||
func TestPythonVirtualEnvIgnoreDefaultVenvNames(t *testing.T) {
|
||||
cases := []struct {
|
||||
Expected string
|
||||
FolderNameFallback bool
|
||||
VirtualEnvName string
|
||||
FolderNameFallback bool
|
||||
}{
|
||||
{
|
||||
Expected: "folder",
|
||||
|
@ -202,9 +202,9 @@ func TestPythonVirtualEnvIgnoreDefaultVenvNames(t *testing.T) {
|
|||
func TestPythonVirtualEnvIgnoreCustomVenvNames(t *testing.T) {
|
||||
cases := []struct {
|
||||
Expected string
|
||||
FolderNameFallback bool
|
||||
DefaultVenvNames []string
|
||||
VirtualEnvName string
|
||||
DefaultVenvNames []string
|
||||
FolderNameFallback bool
|
||||
}{
|
||||
{
|
||||
Expected: "folder",
|
||||
|
|
|
@ -18,11 +18,10 @@ type Package struct {
|
|||
}
|
||||
|
||||
type Quasar struct {
|
||||
language
|
||||
|
||||
HasVite bool
|
||||
Vite *Package
|
||||
AppVite *Package
|
||||
language
|
||||
HasVite bool
|
||||
}
|
||||
|
||||
func (q *Quasar) Enabled() bool {
|
||||
|
|
|
@ -11,10 +11,10 @@ func TestR(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
Version string
|
||||
HasRscript bool
|
||||
HasR bool
|
||||
HasRexe bool
|
||||
Version string
|
||||
}{
|
||||
{Case: "Rscript 4.2.0", ExpectedString: "4.2.0", HasRscript: true, Version: "Rscript (R) version 4.2.0 (2022-04-22)"},
|
||||
{Case: "Rscript 4.1.3", ExpectedString: "4.1.3", HasRscript: true, Version: "R scripting front-end version 4.1.3 (2022-03-10)"},
|
||||
|
|
|
@ -13,12 +13,12 @@ func TestRuby(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
Version string
|
||||
HasRbenv bool
|
||||
HasRvmprompt bool
|
||||
HasChruby bool
|
||||
HasAsdf bool
|
||||
HasRuby bool
|
||||
Version string
|
||||
HasRubyFiles bool
|
||||
HasRakeFile bool
|
||||
HasGemFile bool
|
||||
|
|
|
@ -44,17 +44,15 @@ const (
|
|||
)
|
||||
|
||||
type Sapling struct {
|
||||
scm
|
||||
|
||||
Working *SaplingStatus
|
||||
ShortHash string
|
||||
Hash string
|
||||
When string
|
||||
Author string
|
||||
Bookmark string
|
||||
Description string
|
||||
New bool
|
||||
|
||||
Working *SaplingStatus
|
||||
scm
|
||||
New bool
|
||||
}
|
||||
|
||||
func (sl *Sapling) Template() string {
|
||||
|
|
|
@ -184,9 +184,9 @@ func TestShouldDisplay(t *testing.T) {
|
|||
func TestSetHeadContext(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
FetchStatus bool
|
||||
Output string
|
||||
Expected string
|
||||
FetchStatus bool
|
||||
}{
|
||||
{
|
||||
Case: "Do not fetch status",
|
||||
|
|
|
@ -18,6 +18,7 @@ const (
|
|||
|
||||
// ScmStatus represents part of the status of a repository
|
||||
type ScmStatus struct {
|
||||
Formats map[string]string
|
||||
Unmerged int
|
||||
Deleted int
|
||||
Added int
|
||||
|
@ -28,8 +29,6 @@ type ScmStatus struct {
|
|||
Clean int
|
||||
Missing int
|
||||
Ignored int
|
||||
|
||||
Formats map[string]string
|
||||
}
|
||||
|
||||
func (s *ScmStatus) Changed() bool {
|
||||
|
@ -81,19 +80,17 @@ func (s *ScmStatus) String() string {
|
|||
}
|
||||
|
||||
type scm struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
Dir string
|
||||
RepoName string
|
||||
workingDir string
|
||||
rootDir string
|
||||
realDir string
|
||||
command string
|
||||
IsWslSharedPath bool
|
||||
CommandMissing bool
|
||||
Dir string // actual repo root directory
|
||||
RepoName string
|
||||
|
||||
workingDir string
|
||||
rootDir string
|
||||
realDir string // real directory (can be different from current path when in worktrees)
|
||||
command string
|
||||
nativeFallback bool
|
||||
nativeFallback bool
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
func TestScmStatusChanged(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Expected bool
|
||||
Status ScmStatus
|
||||
Expected bool
|
||||
}{
|
||||
{
|
||||
Case: "No changes",
|
||||
|
@ -143,12 +143,12 @@ func TestHasCommand(t *testing.T) {
|
|||
|
||||
func TestFormatBranch(t *testing.T) {
|
||||
cases := []struct {
|
||||
MappedBranches map[string]string
|
||||
Case string
|
||||
Expected string
|
||||
Input string
|
||||
MappedBranches map[string]string
|
||||
BranchMaxLength int
|
||||
TruncateSymbol string
|
||||
BranchMaxLength int
|
||||
NoFullBranchPath bool
|
||||
}{
|
||||
{
|
||||
|
|
|
@ -7,14 +7,10 @@ import (
|
|||
)
|
||||
|
||||
type Session struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
// text string
|
||||
|
||||
SSHSession bool
|
||||
|
||||
// Deprecated
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
DefaultUserName string
|
||||
SSHSession bool
|
||||
}
|
||||
|
||||
func (s *Session) Enabled() bool {
|
||||
|
|
|
@ -19,11 +19,11 @@ func TestSessionSegmentTemplate(t *testing.T) {
|
|||
UserName string
|
||||
DefaultUserName string
|
||||
ComputerName string
|
||||
SSHSession bool
|
||||
Root bool
|
||||
Template string
|
||||
WhoAmI string
|
||||
Platform string
|
||||
SSHSession bool
|
||||
Root bool
|
||||
}{
|
||||
{
|
||||
Case: "user and computer",
|
||||
|
|
|
@ -28,8 +28,8 @@ type EndpointConfig struct {
|
|||
}
|
||||
|
||||
type UserConfig struct {
|
||||
DefaultEndpoint string `json:"defaultEndpoint"`
|
||||
Endpoints map[string]EndpointConfig `json:"endpoints"`
|
||||
DefaultEndpoint string `json:"defaultEndpoint"`
|
||||
}
|
||||
|
||||
func (s *Sitecore) Enabled() bool {
|
||||
|
|
|
@ -15,10 +15,10 @@ func TestSitecoreSegment(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
UserFileContent string
|
||||
ExpectedEnabled bool
|
||||
SitecoreFileExists bool
|
||||
UserFileExists bool
|
||||
UserFileContent string
|
||||
DisplayDefault bool
|
||||
}{
|
||||
{Case: "Disabled, no sitecore.json file and user.json file", ExpectedString: "", ExpectedEnabled: false, SitecoreFileExists: false, UserFileExists: false},
|
||||
|
|
|
@ -14,12 +14,12 @@ import (
|
|||
|
||||
func TestSpotifyDarwinEnabledAndSpotifyPlaying(t *testing.T) {
|
||||
cases := []struct {
|
||||
Error error
|
||||
Running string
|
||||
Expected string
|
||||
Status string
|
||||
Artist string
|
||||
Track string
|
||||
Error error
|
||||
}{
|
||||
{Running: "false", Expected: ""},
|
||||
{Running: "false", Expected: "", Error: errors.New("oops")},
|
||||
|
@ -32,10 +32,12 @@ func TestSpotifyDarwinEnabledAndSpotifyPlaying(t *testing.T) {
|
|||
env.On("RunCommand", "osascript", []string{"-e", "tell application \"Spotify\" to player state as string"}).Return(tc.Status, nil)
|
||||
env.On("RunCommand", "osascript", []string{"-e", "tell application \"Spotify\" to artist of current track as string"}).Return(tc.Artist, nil)
|
||||
env.On("RunCommand", "osascript", []string{"-e", "tell application \"Spotify\" to name of current track as string"}).Return(tc.Track, nil)
|
||||
|
||||
s := &Spotify{
|
||||
env: env,
|
||||
props: properties.Map{},
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.Running == "true", s.Enabled())
|
||||
assert.Equal(t, tc.Expected, renderTemplate(env, s.Template(), s))
|
||||
}
|
||||
|
|
|
@ -14,11 +14,11 @@ import (
|
|||
|
||||
func TestSpotifyWindowsNative(t *testing.T) {
|
||||
cases := []struct {
|
||||
Error error
|
||||
Case string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
Title string
|
||||
Error error
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "Playing",
|
||||
|
@ -55,11 +55,11 @@ func TestSpotifyWindowsNative(t *testing.T) {
|
|||
|
||||
func TestSpotifyWindowsPWA(t *testing.T) {
|
||||
cases := []struct {
|
||||
Error error
|
||||
Case string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
Title string
|
||||
Error error
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "Playing",
|
||||
|
|
|
@ -16,8 +16,8 @@ func TestSpotifyWsl(t *testing.T) {
|
|||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
ExecOutput string
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "Spotify not running",
|
||||
|
|
|
@ -15,17 +15,13 @@ const (
|
|||
)
|
||||
|
||||
type Status struct {
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
|
||||
String string
|
||||
Error bool
|
||||
Code int
|
||||
|
||||
props properties.Properties
|
||||
env runtime.Environment
|
||||
template *template.Text
|
||||
|
||||
// Deprecated: Use {{ reason .Code }} instead
|
||||
Meaning string
|
||||
String string
|
||||
Meaning string
|
||||
Code int
|
||||
Error bool
|
||||
}
|
||||
|
||||
func (s *Status) Template() string {
|
||||
|
|
|
@ -14,9 +14,9 @@ import (
|
|||
|
||||
func TestStatusWriterEnabled(t *testing.T) {
|
||||
cases := []struct {
|
||||
Template string
|
||||
Status int
|
||||
Expected bool
|
||||
Template string
|
||||
}{
|
||||
{Status: 102, Expected: true},
|
||||
{Status: 0, Expected: false},
|
||||
|
@ -49,11 +49,11 @@ func TestStatusWriterEnabled(t *testing.T) {
|
|||
func TestFormatStatus(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
Status int
|
||||
PipeStatus string
|
||||
Template string
|
||||
Separator string
|
||||
Expected string
|
||||
Status int
|
||||
}{
|
||||
{
|
||||
Case: "No PipeStatus",
|
||||
|
|
|
@ -27,16 +27,14 @@ func (s *stravaAPI) GetActivities() ([]*StravaData, error) {
|
|||
// segment struct, makes templating easier
|
||||
type Strava struct {
|
||||
props properties.Properties
|
||||
|
||||
api StravaAPI
|
||||
Icon string
|
||||
Ago string
|
||||
Error string
|
||||
URL string
|
||||
StravaData
|
||||
Icon string
|
||||
Ago string
|
||||
Hours int
|
||||
Authenticate bool
|
||||
Error string
|
||||
URL string
|
||||
|
||||
api StravaAPI
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -54,18 +52,18 @@ const (
|
|||
|
||||
// StravaData struct contains the API data
|
||||
type StravaData struct {
|
||||
ID int `json:"id"`
|
||||
Type string `json:"type"`
|
||||
StartDate time.Time `json:"start_date"`
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
ID int `json:"id"`
|
||||
Distance float64 `json:"distance"`
|
||||
Duration float64 `json:"moving_time"`
|
||||
DeviceWatts bool `json:"device_watts"`
|
||||
AverageWatts float64 `json:"average_watts"`
|
||||
WeightedAverageWatts float64 `json:"weighted_average_watts"`
|
||||
AverageHeartRate float64 `json:"average_heartrate"`
|
||||
MaxHeartRate float64 `json:"max_heartrate"`
|
||||
KudosCount int `json:"kudos_count"`
|
||||
DeviceWatts bool `json:"device_watts"`
|
||||
}
|
||||
|
||||
func (s *Strava) Template() string {
|
||||
|
|
|
@ -28,12 +28,12 @@ func TestStravaSegment(t *testing.T) {
|
|||
fourDaysAgo := time.Now().Add(-h)
|
||||
|
||||
cases := []struct {
|
||||
APIError error
|
||||
Case string
|
||||
ExpectedString string
|
||||
ExpectedEnabled bool
|
||||
Template string
|
||||
APIError error
|
||||
StravaData []*StravaData
|
||||
ExpectedEnabled bool
|
||||
}{
|
||||
{
|
||||
Case: "Ride 6",
|
||||
|
|
|
@ -39,11 +39,10 @@ const (
|
|||
)
|
||||
|
||||
type Svn struct {
|
||||
scm
|
||||
|
||||
Working *SvnStatus
|
||||
BaseRev int
|
||||
Branch string
|
||||
scm
|
||||
BaseRev int
|
||||
}
|
||||
|
||||
func (s *Svn) Template() string {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue