From c98c1b54253dfe635ef41deaf13bb53f2940fa4a Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sat, 17 Apr 2021 13:28:06 +0200 Subject: [PATCH] feat(language): enable in home dir when always_enabled resolves #649 --- src/segment_language.go | 7 +++++-- src/segment_language_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/segment_language.go b/src/segment_language.go index 9ea0f9b7..7e0648f1 100644 --- a/src/segment_language.go +++ b/src/segment_language.go @@ -116,11 +116,14 @@ func (l *language) string() string { } func (l *language) enabled() bool { - if l.env.getcwd() == l.env.homeDir() { + inHomeDir := func() bool { + return l.env.getcwd() == l.env.homeDir() + } + displayMode := l.props.getString(DisplayMode, DisplayModeFiles) + if inHomeDir() && displayMode != DisplayModeAlways { return false } l.loadLanguageContext() - displayMode := l.props.getString(DisplayMode, DisplayModeFiles) switch displayMode { case DisplayModeAlways: return true diff --git a/src/segment_language_test.go b/src/segment_language_test.go index 14c5d9f7..afbb7ae8 100644 --- a/src/segment_language_test.go +++ b/src/segment_language_test.go @@ -438,6 +438,39 @@ func TestLanguageHyperlinkEnabledLessParamInTemplate(t *testing.T) { assert.Equal(t, "[1.3.307](https://unicor.org/doc/1)", lang.string()) } +func TestLanguageEnabledInHome(t *testing.T) { + cases := []struct { + Case string + DisplayMode string + ExpectedEnabled bool + }{ + {Case: "Always enabled", DisplayMode: DisplayModeAlways, ExpectedEnabled: true}, + {Case: "Context disabled", DisplayMode: DisplayModeContext, ExpectedEnabled: false}, + } + for _, tc := range cases { + props := map[Property]interface{}{ + DisplayMode: tc.DisplayMode, + } + args := &languageArgs{ + commands: []*cmd{ + { + executable: "uni", + args: []string{"--version"}, + regex: `(?P((?P[0-9]+).(?P[0-9]+).(?P[0-9]+)))`, + }, + }, + extensions: []string{uni, corn}, + enabledExtensions: []string{corn}, + enabledCommands: []string{"corn"}, + version: universion, + properties: props, + inHome: true, + } + lang := bootStrapLanguageTest(args) + assert.Equal(t, tc.ExpectedEnabled, lang.enabled(), tc.Case) + } +} + func TestLanguageHyperlinkEnabledMoreParamInTemplate(t *testing.T) { props := map[Property]interface{}{ EnableHyperlink: true,