mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
fix: node segment enable_version_mismatch
This commit is contained in:
parent
2a44dca898
commit
c1bc4404e0
|
@ -61,5 +61,13 @@ func (n *node) matchesVersionFile() bool {
|
||||||
if len(fileVersion) == 0 {
|
if len(fileVersion) == 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return fileVersion == n.language.activeCommand.version.Full
|
|
||||||
|
regex := fmt.Sprintf(
|
||||||
|
`(?im)^v?%s(\.?%s)?(\.?%s)?$`,
|
||||||
|
n.language.activeCommand.version.Major,
|
||||||
|
n.language.activeCommand.version.Minor,
|
||||||
|
n.language.activeCommand.version.Patch,
|
||||||
|
)
|
||||||
|
|
||||||
|
return matchString(regex, fileVersion)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,25 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNodeMatchesVersionFile(t *testing.T) {
|
func TestNodeMatchesVersionFile(t *testing.T) {
|
||||||
|
nodeVersion := version{
|
||||||
|
Full: "1.2.3",
|
||||||
|
Major: "1",
|
||||||
|
Minor: "2",
|
||||||
|
Patch: "3",
|
||||||
|
}
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Case string
|
Case string
|
||||||
Expected bool
|
Expected bool
|
||||||
RCVersion string
|
RCVersion string
|
||||||
Version string
|
|
||||||
}{
|
}{
|
||||||
{Case: "no file context", Expected: true, RCVersion: "", Version: "durp"},
|
{Case: "no file context", Expected: true, RCVersion: ""},
|
||||||
{Case: "version match", Expected: true, RCVersion: "durp", Version: "durp"},
|
{Case: "version match", Expected: true, RCVersion: "1.2.3"},
|
||||||
{Case: "version mismatch", Expected: false, RCVersion: "werp", Version: "durp"},
|
{Case: "version mismatch", Expected: false, RCVersion: "3.2.1"},
|
||||||
|
{Case: "version match in other format", Expected: true, RCVersion: "v1.2.3"},
|
||||||
|
{Case: "version match without patch", Expected: true, RCVersion: "1.2"},
|
||||||
|
{Case: "version match without patch in other format", Expected: true, RCVersion: "v1.2"},
|
||||||
|
{Case: "version match without minor", Expected: true, RCVersion: "1"},
|
||||||
|
{Case: "version match without minor in other format", Expected: true, RCVersion: "v1"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
|
@ -25,9 +35,7 @@ func TestNodeMatchesVersionFile(t *testing.T) {
|
||||||
language: &language{
|
language: &language{
|
||||||
env: env,
|
env: env,
|
||||||
activeCommand: &cmd{
|
activeCommand: &cmd{
|
||||||
version: &version{
|
version: &nodeVersion,
|
||||||
Full: tc.Version,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue