1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-27 12:32:37 +02:00

Validate that Universal.JumpToBlock array has 5 elements

The code that uses this panics if it has fewer.
This commit is contained in:
Stefan Haller 2025-02-16 16:45:28 +01:00
parent f3791e6ab6
commit a5f78d3222
2 changed files with 24 additions and 1 deletions

View File

@ -68,5 +68,14 @@ func validateKeybindingsRecurse(path string, node any) error {
}
func validateKeybindings(keybindingConfig KeybindingConfig) error {
return validateKeybindingsRecurse("", keybindingConfig)
if err := validateKeybindingsRecurse("", keybindingConfig); err != nil {
return err
}
if len(keybindingConfig.Universal.JumpToBlock) != 5 {
return fmt.Errorf("keybinding.universal.jumpToBlock must have 5 elements; found %d.",
len(keybindingConfig.Universal.JumpToBlock))
}
return nil
}

View File

@ -1,6 +1,7 @@
package config
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -42,6 +43,19 @@ func TestUserConfigValidate_enums(t *testing.T) {
{value: "invalid_value", valid: false},
},
},
{
name: "JumpToBlock keybinding",
setup: func(config *UserConfig, value string) {
config.Keybinding.Universal.JumpToBlock = strings.Split(value, ",")
},
testCases: []testCase{
{value: "", valid: false},
{value: "1,2,3", valid: false},
{value: "1,2,3,4,5", valid: true},
{value: "1,2,3,4,invalid", valid: false},
{value: "1,2,3,4,5,6", valid: false},
},
},
}
for _, s := range scenarios {