diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-14 11:37:23 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-14 11:37:23 +0200 |
commit | b553df1b1504e07187c0e1d4b5dd01ae65a5fcc1 (patch) | |
tree | 3f3b120fbab3206c0809212094a8e7847199e2bb /src | |
parent | 246063fb7cd21a83beae5934f95b2795fb85df51 (diff) | |
download | markdown-rs-b553df1b1504e07187c0e1d4b5dd01ae65a5fcc1.tar.gz markdown-rs-b553df1b1504e07187c0e1d4b5dd01ae65a5fcc1.tar.bz2 markdown-rs-b553df1b1504e07187c0e1d4b5dd01ae65a5fcc1.zip |
Refactor some code to improve coverage
Diffstat (limited to '')
-rw-r--r-- | src/util/slice.rs | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/util/slice.rs b/src/util/slice.rs index 4c942b9..869ecca 100644 --- a/src/util/slice.rs +++ b/src/util/slice.rs @@ -29,18 +29,14 @@ impl<'a> Position<'a> { debug_assert_eq!(exit.kind, Kind::Exit, "expected `exit` event"); let mut enter_index = index - 1; - loop { - let enter = &events[enter_index]; - if enter.kind == Kind::Enter && enter.name == exit.name { - let position = Position { - start: &enter.point, - end: &exit.point, - }; - return position; - } - + while events[enter_index].kind != Kind::Enter || events[enter_index].name != exit.name { enter_index -= 1; } + + Position { + start: &events[enter_index].point, + end: &exit.point, + } } /// Turn a position into indices. @@ -122,6 +118,10 @@ impl<'a> Slice<'a> { /// /// Supports virtual spaces. pub fn serialize(&self) -> String { + debug_assert_eq!(self.after, 0, "expected no trailing vs"); + // If the above ever starts erroring, handle the same as `self.before` + // above but with `self.after`. + // It’d currently be unused code. let mut string = String::with_capacity(self.len()); let mut index = self.before; while index > 0 { @@ -129,10 +129,6 @@ impl<'a> Slice<'a> { index -= 1; } string.push_str(self.as_str()); - debug_assert_eq!(self.after, 0, "expected no trailing vs"); - // If the above ever starts erroring, handle the same as `self.before` - // above but with `self.after`. - // It’d currently be unused code. string } } |