don't crash in plaintext bracket match (mm) on empty file

pull/9341/head
Pascal Kuthe 11 months ago committed by Blaž Hrastnik
parent 3f88a3f4e6
commit 2fb7e50b54

@ -141,7 +141,7 @@ fn find_pair(
#[must_use] #[must_use]
pub fn find_matching_bracket_plaintext(doc: RopeSlice, cursor_pos: usize) -> Option<usize> { pub fn find_matching_bracket_plaintext(doc: RopeSlice, cursor_pos: usize) -> Option<usize> {
// Don't do anything when the cursor is not on top of a bracket. // Don't do anything when the cursor is not on top of a bracket.
let bracket = doc.char(cursor_pos); let bracket = doc.get_char(cursor_pos)?;
if !is_valid_bracket(bracket) { if !is_valid_bracket(bracket) {
return None; return None;
} }
@ -265,6 +265,12 @@ fn as_char(doc: RopeSlice, node: &Node) -> Option<(usize, char)> {
mod tests { mod tests {
use super::*; use super::*;
#[test]
fn find_matching_bracket_empty_file() {
let actual = find_matching_bracket_plaintext("".into(), 0);
assert_eq!(actual, None);
}
#[test] #[test]
fn test_find_matching_bracket_current_line_plaintext() { fn test_find_matching_bracket_current_line_plaintext() {
let assert = |input: &str, pos, expected| { let assert = |input: &str, pos, expected| {

Loading…
Cancel
Save