mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-13 20:27:28 -08:00
parent
c7db86ed4c
commit
de498044c9
|
@ -17,7 +17,7 @@ func (g *golang) init(props *properties, env environmentInfo) {
|
|||
{
|
||||
executable: "go",
|
||||
args: []string{"version"},
|
||||
regex: `(?:go(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
|
||||
regex: `(?:go(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+)(.(?P<patch>[0-9]+))?)))`,
|
||||
},
|
||||
},
|
||||
versionURLTemplate: "[%s](https://golang.org/doc/go%s.%s)",
|
||||
|
|
34
src/segment_golang_test.go
Executable file
34
src/segment_golang_test.go
Executable file
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGolang(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
ExpectedString string
|
||||
Version string
|
||||
}{
|
||||
{Case: "Go 1.15", ExpectedString: "1.15.8", Version: "go version go1.15.8 darwin/amd64"},
|
||||
{Case: "Go 1.16", ExpectedString: "1.16", Version: "go version go1.16 darwin/amd64"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
env := new(MockedEnvironment)
|
||||
env.On("hasCommand", "go").Return(true)
|
||||
env.On("runCommand", "go", []string{"version"}).Return(tc.Version, nil)
|
||||
env.On("hasFiles", "*.go").Return(true)
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
DisplayVersion: true,
|
||||
},
|
||||
}
|
||||
g := &golang{}
|
||||
g.init(props, env)
|
||||
assert.True(t, g.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
assert.Equal(t, tc.ExpectedString, g.string(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue