about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMoritz Vetter <mv@3yourmind.com>2022-02-26 15:46:14 +0100
committerMoritz Vetter <mv@3yourmind.com>2022-02-26 15:46:14 +0100
commitc541f3396cd8dc1c2c87434d1e07d6862a2e8584 (patch)
tree55a682e51f55cfe3349d20d359ea7ac177a0ec83
parenta2cc1d6b7b499d6b03436db7fc8053aea72f75ac (diff)
downloadrust-c541f3396cd8dc1c2c87434d1e07d6862a2e8584.tar.gz
rust-c541f3396cd8dc1c2c87434d1e07d6862a2e8584.zip
test: add unit test for TextEdit::apply()
-rw-r--r--crates/text_edit/src/lib.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/text_edit/src/lib.rs b/crates/text_edit/src/lib.rs
index 21c622d3d6b..f478e4dcf57 100644
--- a/crates/text_edit/src/lib.rs
+++ b/crates/text_edit/src/lib.rs
@@ -203,3 +203,17 @@ fn check_disjoint_and_sort(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bo
         l.delete.end() <= r.delete.start() || l == r
     })
 }
+
+#[test]
+fn test_apply() {
+    let mut text = "_11h1_2222_xx3333_4444_6666".to_string();
+    let mut builder = TextEditBuilder::default();
+    builder.replace(TextRange::new(3.into(), 4.into()), "1".to_string());
+    builder.delete(TextRange::new(11.into(), 13.into()));
+    builder.insert(22.into(), "_5555".to_string());
+
+    let text_edit = builder.finish();
+    text_edit.apply(&mut text);
+
+    assert_eq!(text, "_1111_2222_3333_4444_5555_6666")
+}
\ No newline at end of file