oh-my-posh/src/segments/perl_test.go

48 lines
1.3 KiB
Go
Raw Normal View History

2022-07-08 03:21:08 -07:00
package segments
import (
"fmt"
"testing"
2022-12-28 08:30:48 -08:00
"github.com/jandedobbeleer/oh-my-posh/mock"
"github.com/jandedobbeleer/oh-my-posh/properties"
2022-07-08 03:21:08 -07:00
"github.com/stretchr/testify/assert"
)
func TestPerl(t *testing.T) {
cases := []struct {
Case string
ExpectedString string
Version string
PerlHomeVersion string
PerlHomeEnabled bool
}{
{
Case: "v5.12+",
ExpectedString: "5.32.1",
Version: "This is perl 5, version 32, subversion 1 (v5.32.1) built for MSWin32-x64-multi-thread",
},
{
Case: "v5.6 - v5.10",
ExpectedString: "5.6.1",
Version: "This is perl, v5.6.1 built for MSWin32-x86-multi-thread",
},
}
for _, tc := range cases {
env := new(mock.MockedEnvironment)
env.On("HasCommand", "perl").Return(true)
env.On("RunCommand", "perl", []string{"-version"}).Return(tc.Version, nil)
env.On("HasFiles", ".perl-version").Return(true)
env.On("Pwd").Return("/usr/home/project")
env.On("Home").Return("/usr/home")
props := properties.Map{
properties.FetchVersion: true,
}
p := &Perl{}
p.Init(props, env)
assert.True(t, p.Enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
assert.Equal(t, tc.ExpectedString, renderTemplate(env, p.Template(), p), fmt.Sprintf("Failed in case: %s", tc.Case))
}
}