mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
refactor: add language tests
This commit is contained in:
parent
6e23cdd6af
commit
d96cb7989a
31
src/segment_crystal_test.go
Normal file
31
src/segment_crystal_test.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCrystal(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
ExpectedString string
|
||||||
|
Version string
|
||||||
|
}{
|
||||||
|
{Case: "Crystal 1.0.0", ExpectedString: "1.0.0", Version: "Crystal 1.0.0 (2021-03-22)"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
params := &mockedLanguageParams{
|
||||||
|
cmd: "crystal",
|
||||||
|
versionParam: "--version",
|
||||||
|
versionOutput: tc.Version,
|
||||||
|
extension: "*.cr",
|
||||||
|
}
|
||||||
|
env, props := getMockedLanguageEnv(params)
|
||||||
|
c := &crystal{}
|
||||||
|
c.init(props, env)
|
||||||
|
assert.True(t, c.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
assert.Equal(t, tc.ExpectedString, c.string(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,28 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type mockedLanguageParams struct {
|
||||||
|
cmd string
|
||||||
|
versionParam string
|
||||||
|
versionOutput string
|
||||||
|
extension string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMockedLanguageEnv(params *mockedLanguageParams) (*MockedEnvironment, *properties) {
|
||||||
|
env := new(MockedEnvironment)
|
||||||
|
env.On("hasCommand", params.cmd).Return(true)
|
||||||
|
env.On("runCommand", params.cmd, []string{params.versionParam}).Return(params.versionOutput, nil)
|
||||||
|
env.On("hasFiles", params.extension).Return(true)
|
||||||
|
env.On("getcwd", nil).Return("/usr/home/project")
|
||||||
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
|
props := &properties{
|
||||||
|
values: map[Property]interface{}{
|
||||||
|
DisplayVersion: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return env, props
|
||||||
|
}
|
||||||
|
|
||||||
func TestGolang(t *testing.T) {
|
func TestGolang(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Case string
|
Case string
|
||||||
|
@ -17,17 +39,13 @@ func TestGolang(t *testing.T) {
|
||||||
{Case: "Go 1.16", ExpectedString: "1.16", Version: "go version go1.16 darwin/amd64"},
|
{Case: "Go 1.16", ExpectedString: "1.16", Version: "go version go1.16 darwin/amd64"},
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := new(MockedEnvironment)
|
params := &mockedLanguageParams{
|
||||||
env.On("hasCommand", "go").Return(true)
|
cmd: "go",
|
||||||
env.On("runCommand", "go", []string{"version"}).Return(tc.Version, nil)
|
versionParam: "version",
|
||||||
env.On("hasFiles", "*.go").Return(true)
|
versionOutput: tc.Version,
|
||||||
env.On("getcwd", nil).Return("/usr/home/project")
|
extension: "*.go",
|
||||||
env.On("homeDir", nil).Return("/usr/home")
|
|
||||||
props := &properties{
|
|
||||||
values: map[Property]interface{}{
|
|
||||||
DisplayVersion: true,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
env, props := getMockedLanguageEnv(params)
|
||||||
g := &golang{}
|
g := &golang{}
|
||||||
g.init(props, env)
|
g.init(props, env)
|
||||||
assert.True(t, g.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
assert.True(t, g.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
|
32
src/segment_julia_test.go
Normal file
32
src/segment_julia_test.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestJulia(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
ExpectedString string
|
||||||
|
Version string
|
||||||
|
}{
|
||||||
|
{Case: "Julia 1.6.0", ExpectedString: "1.6.0", Version: "julia version 1.6.0"},
|
||||||
|
{Case: "Julia 1.6.1", ExpectedString: "1.6.1", Version: "julia version 1.6.1"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
params := &mockedLanguageParams{
|
||||||
|
cmd: "julia",
|
||||||
|
versionParam: "--version",
|
||||||
|
versionOutput: tc.Version,
|
||||||
|
extension: "*.jl",
|
||||||
|
}
|
||||||
|
env, props := getMockedLanguageEnv(params)
|
||||||
|
j := &julia{}
|
||||||
|
j.init(props, env)
|
||||||
|
assert.True(t, j.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
assert.Equal(t, tc.ExpectedString, j.string(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue