1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/services/custom_commands/menu_generator_test.go

66 lines
1.7 KiB
Go
Raw Normal View History

package custom_commands
2021-10-22 11:18:40 +02:00
import (
"testing"
"github.com/jesseduffield/lazygit/pkg/utils"
2021-10-22 11:18:40 +02:00
"github.com/stretchr/testify/assert"
)
func TestMenuGenerator(t *testing.T) {
2021-10-22 11:18:40 +02:00
type scenario struct {
testName string
cmdOut string
filter string
valueFormat string
labelFormat string
test func([]*commandMenuEntry, error)
2021-10-22 11:18:40 +02:00
}
scenarios := []scenario{
{
"Extract remote branch name",
"upstream/pr-1",
"(?P<remote>[a-z_]+)/(?P<branch>.*)",
"{{ .branch }}",
"Remote: {{ .remote }}",
func(actualEntry []*commandMenuEntry, err error) {
2021-10-22 11:18:40 +02:00
assert.NoError(t, err)
assert.EqualValues(t, "pr-1", actualEntry[0].value)
assert.EqualValues(t, "Remote: upstream", actualEntry[0].label)
},
},
{
"Multiple named groups with empty labelFormat",
"upstream/pr-1",
"(?P<remote>[a-z]*)/(?P<branch>.*)",
"{{ .branch }}|{{ .remote }}",
"",
func(actualEntry []*commandMenuEntry, err error) {
2021-10-22 11:18:40 +02:00
assert.NoError(t, err)
assert.EqualValues(t, "pr-1|upstream", actualEntry[0].value)
assert.EqualValues(t, "pr-1|upstream", actualEntry[0].label)
},
},
{
"Multiple named groups with group ids",
"upstream/pr-1",
"(?P<remote>[a-z]*)/(?P<branch>.*)",
"{{ .group_2 }}|{{ .group_1 }}",
"Remote: {{ .group_1 }}",
func(actualEntry []*commandMenuEntry, err error) {
2021-10-22 11:18:40 +02:00
assert.NoError(t, err)
assert.EqualValues(t, "pr-1|upstream", actualEntry[0].value)
assert.EqualValues(t, "Remote: upstream", actualEntry[0].label)
},
},
}
for _, s := range scenarios {
2022-01-08 06:46:35 +02:00
s := s
2021-10-22 11:18:40 +02:00
t.Run(s.testName, func(t *testing.T) {
s.test(NewMenuGenerator(utils.NewDummyCommon()).call(s.cmdOut, s.filter, s.valueFormat, s.labelFormat))
2021-10-22 11:18:40 +02:00
})
}
}