fix(config): alleviate panic on blank config filee

Whenever the config parse was parsed an empty config,
a panic would result because of trying to process an
empty vector:

---- config::tests::test_blank_config stdout ----
thread 'config::tests::test_blank_config' panicked at 'index out of bounds: the len is 0 but the index is 0', src/config.rs:237:33

This commit alleviates that by simply returning an empty
Hotkey vector whenever an empty config is passed.
main
Angelo Fallaria 2 years ago
parent 036e7c12fe
commit e10d2ac005

@ -231,6 +231,11 @@ fn parse_contents(contents: String) -> Result<Vec<Hotkey>, Error> {
}
}
// Edge case: return a blank vector if no lines detected
if lines_with_types.len() == 0 {
return Ok(vec![]);
}
// Go through lines_with_types, and add the next line over and over until the current line no
// longer ends with backslash. (Only if the lines have the same type)
let mut actual_lines: Vec<(&str, u32, String)> = Vec::new();
@ -929,7 +934,29 @@ super + shift + b
],
)
}
#[test]
fn test_blank_config() -> std::io::Result<()> {
let contents = "";
eval_config_test(
contents,
vec![],
)
}
#[test]
fn test_blank_config_with_whitespace() -> std::io::Result<()> {
let contents = "
";
eval_config_test(
contents,
vec![],
)
}
#[test]
#[ignore]
fn test_numrow_special_keys() -> std::io::Result<()> {

Loading…
Cancel
Save