From 78525cef45d0ec8b3cd30f0fa77f9c69f7ccd2ee Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 13 Apr 2025 22:21:19 +0100 Subject: [PATCH] Fix tests ignoring overflowing cursors --- backend/reconcile/tests/example_document.rs | 7 +++++++ backend/reconcile/tests/examples/deletes.yml | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/backend/reconcile/tests/example_document.rs b/backend/reconcile/tests/example_document.rs index 66a56f65..10790c8b 100644 --- a/backend/reconcile/tests/example_document.rs +++ b/backend/reconcile/tests/example_document.rs @@ -63,6 +63,13 @@ impl ExampleDocument { fn text_with_cursors_to_string(text: &TextWithCursors<'_>) -> String { let mut result = text.text.clone().into_owned(); for (i, cursor) in text.cursors.iter().enumerate() { + assert!( + cursor.char_index <= result.len(), // equals in case of insert at the end + "Cursor index out of bounds: {} > {}", + cursor.char_index, + result.len() + ); + result.insert( result .char_indices() diff --git a/backend/reconcile/tests/examples/deletes.yml b/backend/reconcile/tests/examples/deletes.yml index 59eb9337..c4c145b8 100644 --- a/backend/reconcile/tests/examples/deletes.yml +++ b/backend/reconcile/tests/examples/deletes.yml @@ -23,3 +23,9 @@ parent: long text with one big delete and many small left: long small right: long with big and small expected: long small + +--- +parent: long text where the cursor has to be clamped after delete +left: long text where the cursor has to be clamped after delete| +right: long text where the cursor +expected: long text where the cursor|