diff --git a/src/segments/language.go b/src/segments/language.go index 1cc89ce2..e2b7d24b 100644 --- a/src/segments/language.go +++ b/src/segments/language.go @@ -140,8 +140,13 @@ func (l *language) Enabled() bool { } if l.matchesVersionFile != nil { - l.version.Expected, l.Mismatch = l.matchesVersionFile() + expected, match := l.matchesVersionFile() + if !match { + l.Mismatch = true + l.Expected = expected + } } + return enabled } diff --git a/src/segments/language_test.go b/src/segments/language_test.go index e027d5d6..01ffd5ef 100644 --- a/src/segments/language_test.go +++ b/src/segments/language_test.go @@ -157,6 +157,31 @@ func TestLanguageEnabledOneExtensionFound(t *testing.T) { assert.Equal(t, "unicorn", lang.Executable, "unicorn was used") } +func TestLanguageEnabledMismatch(t *testing.T) { + expectedVersion := "1.2.009" + + args := &languageArgs{ + commands: []*cmd{ + { + executable: "unicorn", + args: []string{"--version"}, + regex: "(?P.*)", + }, + }, + extensions: []string{uni, corn}, + enabledExtensions: []string{uni}, + enabledCommands: []string{"unicorn"}, + version: universion, + matchesVersionFile: func() (string, bool) { + return expectedVersion, false + }, + } + lang := bootStrapLanguageTest(args) + assert.True(t, lang.Enabled()) + assert.Equal(t, expectedVersion, lang.Expected, "the expected unicorn version is 1.2.009") + assert.True(t, lang.Mismatch, "we require a different version of unicorn") +} + func TestLanguageDisabledInHome(t *testing.T) { args := &languageArgs{ commands: []*cmd{ diff --git a/website/docs/segments/node.mdx b/website/docs/segments/node.mdx index e8984784..e3b77423 100644 --- a/website/docs/segments/node.mdx +++ b/website/docs/segments/node.mdx @@ -10,16 +10,18 @@ Display the currently active [Node.js][node-js] version. ## Sample Configuration -import Config from '@site/src/components/Config.js'; +import Config from "@site/src/components/Config.js"; - + ## Properties @@ -55,7 +57,7 @@ import Config from '@site/src/components/Config.js'; | `.URL` | `string` | URL of the version info / release notes | | `.Error` | `string` | error encountered when fetching the version string | | `.PackageManagerIcon` | `string` | the Yarn or NPM icon when setting `fetch_package_manager` to `true` | -| `.Mismatch` | `boolean` | if the version in `.nvmrc` matches with `.Full` | +| `.Mismatch` | `boolean` | true if the version in `.nvmrc` is not equal to `.Full` | | `.Expected` | `string` | the expected version set in `.nvmrc` | [go-text-template]: https://golang.org/pkg/text/template/