Skip to content

Commit

Permalink
Merge pull request #17 from andyyu2004/builder-finish-fix
Browse files Browse the repository at this point in the history
Fix trailing_newline issue in Builder::build
  • Loading branch information
noib3 authored Apr 1, 2024
2 parents 8c10b81 + 2753b9b commit 468818b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/rope/rope_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ impl RopeBuilder {
#[inline]
pub fn build(mut self) -> Rope {
if self.buffer_len_left > 0 {
self.rope_has_trailing_newline =
self.buffer.has_trailing_newline();

self.buffer.left_summary =
ChunkSummary::from(self.buffer_left_chunk());

self.rope_has_trailing_newline =
self.buffer.has_trailing_newline();

self.tree_builder.append(self.buffer);
}

Expand Down
1 change: 0 additions & 1 deletion src/tree/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,6 @@ mod tests {
use core::ops::{Add, AddAssign, Sub, SubAssign};

use super::*;
use crate::tree::Summarize;

#[derive(Copy, Clone, Default, Debug, Eq, PartialEq)]
pub struct Count {
Expand Down
8 changes: 8 additions & 0 deletions tests/rope_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ mod common;
use common::LARGE;
use crop::{Rope, RopeBuilder};

#[test]
fn builder_line_len() {
let mut builder = RopeBuilder::new();
builder.append("\n");
let rope = builder.build();
assert_eq!(rope.line_len(), Rope::from("\n").line_len());
}

#[test]
fn builder_empty() {
let r = RopeBuilder::new().build();
Expand Down

0 comments on commit 468818b

Please sign in to comment.