mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +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:
parent
f3791e6ab6
commit
a5f78d3222
2 changed files with 24 additions and 1 deletions
|
@ -68,5 +68,14 @@ func validateKeybindingsRecurse(path string, node any) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateKeybindings(keybindingConfig KeybindingConfig) 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
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -42,6 +43,19 @@ func TestUserConfigValidate_enums(t *testing.T) {
|
||||||
{value: "invalid_value", valid: false},
|
{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 {
|
for _, s := range scenarios {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue