Skip to content

Commit 9e0e715

Browse files
committed
fix: allow using empty string as the input
1 parent 738c04b commit 9e0e715

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "string_wizard"
3-
version = "0.0.8"
3+
version = "0.0.9"
44
edition = "2021"
55
license = "MIT"
66
description = "manipulate string like wizards"

src/chunk.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub struct Chunk<'str> {
3939

4040
impl<'s> Chunk<'s> {
4141
pub fn new(span: Span) -> Self {
42-
debug_assert!(span.0 < span.1);
4342
Self {
4443
span,
4544
..Default::default()

src/magic_string/mutation.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ impl<'text> MagicString<'text> {
6363
let start = start.assert_into_u32();
6464
let end = end.assert_into_u32();
6565
let to = to.assert_into_u32();
66+
if to >= start && to <= end {
67+
panic!("Cannot relocate a selection inside itself")
68+
}
6669

6770
self.split_at(start);
6871
self.split_at(end);

tests/magic_string.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,13 @@ mod misc {
287287
assert_eq!(s.remove(0, 3).to_string(), "3456");
288288
assert_eq!(s.remove(3, 7).to_string(), "");
289289
}
290+
291+
#[test]
292+
fn allow_empty_input() {
293+
let mut s = MagicString::new("");
294+
s.append("xyz");
295+
assert_eq!(s.to_string(), "xyz");
296+
s.prepend("xyz");
297+
assert_eq!(s.to_string(), "xyzxyz");
298+
}
290299
}

0 commit comments

Comments
 (0)