From 5717aa8e35b12120de067f86dbc620a6dfac91ed Mon Sep 17 00:00:00 2001 From: rhogenson <05huvhec@duck.com> Date: Sat, 21 Sep 2024 07:05:17 -0700 Subject: [PATCH] Fix Rope.starts_with. (#11739) Co-authored-by: Rose Hogenson --- helix-stdx/src/rope.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/helix-stdx/src/rope.rs b/helix-stdx/src/rope.rs index 2695555e..f7e31924 100644 --- a/helix-stdx/src/rope.rs +++ b/helix-stdx/src/rope.rs @@ -51,7 +51,7 @@ impl<'a> RopeSliceExt<'a> for RopeSlice<'a> { if len < text.len() { return false; } - self.get_byte_slice(..len - text.len()) + self.get_byte_slice(..text.len()) .map_or(false, |start| start == text) } @@ -137,4 +137,14 @@ mod tests { } } } + + #[test] + fn starts_with() { + assert!(RopeSlice::from("asdf").starts_with("a")); + } + + #[test] + fn ends_with() { + assert!(RopeSlice::from("asdf").ends_with("f")); + } }