diff --git a/crates/loro-internal/src/container/richtext/richtext_state.rs b/crates/loro-internal/src/container/richtext/richtext_state.rs index b03c3941b..7360d5200 100644 --- a/crates/loro-internal/src/container/richtext/richtext_state.rs +++ b/crates/loro-internal/src/container/richtext/richtext_state.rs @@ -233,7 +233,7 @@ mod text_chunk { } fn check(&self) { - if cfg!(debug_assertions) { + if cfg!(any(debug_assertions, test)) { assert_eq!(self.unicode_len, self.as_str().chars().count() as i32); assert_eq!( self.utf16_len, @@ -1904,6 +1904,10 @@ impl RichtextState { #[allow(unused)] pub(crate) fn check(&self) { + if !cfg!(any(debug_assertions, test)) { + return; + } + self.tree.check(); self.check_consistency_between_content_and_style_ranges(); self.check_style_anchors_appear_in_pairs(); @@ -2116,7 +2120,7 @@ impl RichtextState { /// Allow StyleAnchors to appear in pairs, so that there won't be unmatched single StyleAnchors. pub(crate) fn check_style_anchors_appear_in_pairs(&self) { - if !cfg!(debug_assertions) { + if !cfg!(any(debug_assertions, test)) { return; } diff --git a/crates/loro-internal/src/container/richtext/tracker.rs b/crates/loro-internal/src/container/richtext/tracker.rs index 1dd640170..09dd8b97c 100644 --- a/crates/loro-internal/src/container/richtext/tracker.rs +++ b/crates/loro-internal/src/container/richtext/tracker.rs @@ -507,6 +507,10 @@ impl Tracker { } fn check_vv_correctness(&self) { + if !cfg!(debug_assertions) { + return; + } + for span in self.rope.tree().iter() { if span.id.peer == UNKNOWN_PEER_ID { continue; @@ -525,6 +529,10 @@ impl Tracker { // It can only check the correctness of insertions in id_to_cursor. // The deletions are not checked. fn check_id_to_cursor_insertions_correctness(&self) { + if !cfg!(debug_assertions) { + return; + } + for rope_elem in self.rope.tree().iter() { let id_span = rope_elem.id_span(); let leaf_from_start = self.id_to_cursor.get_insert(id_span.id_start()).unwrap(); diff --git a/crates/loro-internal/src/state/movable_list_state.rs b/crates/loro-internal/src/state/movable_list_state.rs index 1940f1a69..17343cf07 100644 --- a/crates/loro-internal/src/state/movable_list_state.rs +++ b/crates/loro-internal/src/state/movable_list_state.rs @@ -347,6 +347,10 @@ mod inner { #[allow(dead_code)] pub fn check_consistency(&self) { + if !cfg!(debug_assertions) { + return; + } + let mut failed = false; if self.check_list_item_consistency().is_err() { error!("list item consistency check failed, self={:#?}", self); diff --git a/crates/loro-internal/src/state/richtext_state.rs b/crates/loro-internal/src/state/richtext_state.rs index 602c007b6..c0617dace 100644 --- a/crates/loro-internal/src/state/richtext_state.rs +++ b/crates/loro-internal/src/state/richtext_state.rs @@ -686,6 +686,10 @@ impl RichtextState { /// Panic if inconsistent. #[allow(unused)] pub(crate) fn check_consistency_between_content_and_style_ranges(&mut self) { + if !cfg!(debug_assertions) { + return; + } + self.state .get_mut() .check_consistency_between_content_and_style_ranges();