fix(node): invert .Mismatch logic

This commit is contained in:
Jan De Dobbeleer 2023-06-26 09:57:27 +02:00 committed by Jan De Dobbeleer
parent 32ee6fa7ab
commit 448bbd302f
3 changed files with 43 additions and 11 deletions

View file

@ -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
}

View file

@ -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<version>.*)",
},
},
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{

View file

@ -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";
<Config data={{
"type": "node",
"style": "powerline",
"powerline_symbol": "\uE0B0",
"foreground": "#ffffff",
"background": "#6CA35E",
"template": " \uE718 {{ .Full }} "
}}/>
<Config
data={{
type: "node",
style: "powerline",
powerline_symbol: "\uE0B0",
foreground: "#ffffff",
background: "#6CA35E",
template: " \uE718 {{ .Full }} ",
}}
/>
## 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/