Skip to content

Commit c185ec5

Browse files
committed
Expose tree constants for internal testing.
Fix for issue #92.
1 parent dfb0a78 commit c185ec5

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ pub use crate::rope::Rope;
185185
pub use crate::rope_builder::RopeBuilder;
186186
pub use crate::slice::RopeSlice;
187187

188+
/// NOT PART OF THE PUBLIC API (hidden from docs for a reason!)
189+
/// These are only exposed for tests that live in the `tests` directory.
190+
#[doc(hidden)]
191+
pub use crate::tree::{MAX_BYTES, MAX_CHILDREN, MIN_BYTES, MIN_CHILDREN};
192+
188193
//==============================================================
189194
// Error reporting types.
190195

src/tree/mod.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ mod constants {
4949
};
5050

5151
// Node maximums.
52-
pub(crate) const MAX_CHILDREN: usize = {
52+
#[doc(hidden)] // NOT PART OF THE PUBLIC API!
53+
pub const MAX_CHILDREN: usize = {
5354
let node_list_align = align_of::<Arc<u8>>();
5455
let info_list_align = align_of::<TextInfo>();
5556
let field_gap = if node_list_align >= info_list_align {
@@ -66,7 +67,8 @@ mod constants {
6667

6768
target_size / (size_of::<Arc<u8>>() + size_of::<TextInfo>())
6869
};
69-
pub(crate) const MAX_BYTES: usize = {
70+
#[doc(hidden)] // NOT PART OF THE PUBLIC API!
71+
pub const MAX_BYTES: usize = {
7072
let smallvec_overhead = size_of::<SmallVec<[u8; 16]>>() - 16;
7173
TARGET_TOTAL_SIZE - START_OFFSET - smallvec_overhead
7274
};
@@ -75,8 +77,10 @@ mod constants {
7577
// Note: MIN_BYTES is intentionally a little smaller than half
7678
// MAX_BYTES, to give a little wiggle room when on the edge of
7779
// merging/splitting.
78-
pub(crate) const MIN_CHILDREN: usize = MAX_CHILDREN / 2;
79-
pub(crate) const MIN_BYTES: usize = (MAX_BYTES / 2) - (MAX_BYTES / 32);
80+
#[doc(hidden)] // NOT PART OF THE PUBLIC API!
81+
pub const MIN_CHILDREN: usize = MAX_CHILDREN / 2;
82+
#[doc(hidden)] // NOT PART OF THE PUBLIC API!
83+
pub const MIN_BYTES: usize = (MAX_BYTES / 2) - (MAX_BYTES / 32);
8084

8185
// Compile-time assertion.
8286
const _: () = {
@@ -92,16 +96,20 @@ mod constants {
9296
// the tests.
9397
#[cfg(any(test, feature = "small_chunks"))]
9498
mod test_constants {
95-
pub(crate) const MAX_CHILDREN: usize = 5;
96-
pub(crate) const MIN_CHILDREN: usize = MAX_CHILDREN / 2;
99+
#[doc(hidden)] // NOT PART OF THE PUBLIC API!
100+
pub const MAX_CHILDREN: usize = 5;
101+
#[doc(hidden)] // NOT PART OF THE PUBLIC API!
102+
pub const MIN_CHILDREN: usize = MAX_CHILDREN / 2;
97103

98104
// MAX_BYTES must be >= 4 to allow for 4-byte utf8 characters.
99-
pub(crate) const MAX_BYTES: usize = 9; // Note: can't be 8, because 3-byte characters.
100-
pub(crate) const MIN_BYTES: usize = (MAX_BYTES / 2) - (MAX_BYTES / 32);
105+
#[doc(hidden)] // NOT PART OF THE PUBLIC API!
106+
pub const MAX_BYTES: usize = 9; // Note: can't be 8, because 3-byte characters.
107+
#[doc(hidden)] // NOT PART OF THE PUBLIC API!
108+
pub const MIN_BYTES: usize = (MAX_BYTES / 2) - (MAX_BYTES / 32);
101109
}
102110

103111
#[cfg(not(any(test, feature = "small_chunks")))]
104-
pub(crate) use self::constants::{MAX_BYTES, MAX_CHILDREN, MIN_BYTES, MIN_CHILDREN};
112+
pub use self::constants::{MAX_BYTES, MAX_CHILDREN, MIN_BYTES, MIN_CHILDREN};
105113

106114
#[cfg(any(test, feature = "small_chunks"))]
107-
pub(crate) use self::test_constants::{MAX_BYTES, MAX_CHILDREN, MIN_BYTES, MIN_CHILDREN};
115+
pub use self::test_constants::{MAX_BYTES, MAX_CHILDREN, MIN_BYTES, MIN_CHILDREN};

tests/proptest_tests.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use proptest::collection::vec;
88
use proptest::test_runner::Config;
99
use ropey::{
1010
str_utils::{byte_to_char_idx, byte_to_line_idx, char_to_byte_idx, char_to_line_idx},
11-
Rope,
11+
Rope, MAX_BYTES,
1212
};
1313

1414
fn string_insert(text: &mut String, char_idx: usize, text_ins: &str) {
@@ -130,8 +130,7 @@ proptest! {
130130
rope.assert_invariants();
131131
assert_eq!(rope, rope_clone);
132132

133-
let max_leaf_bytes = 1024 - 33;
134-
assert!((rope.capacity() - rope.len_bytes()) <= max_leaf_bytes);
133+
assert!((rope.capacity() - rope.len_bytes()) <= MAX_BYTES);
135134
assert!(rope.capacity() <= capacity_before);
136135
}
137136

@@ -153,8 +152,7 @@ proptest! {
153152
rope.assert_invariants();
154153
assert_eq!(rope, rope_clone);
155154

156-
let max_leaf_bytes = 1024 - 33;
157-
let max_diff = max_leaf_bytes + ((rope.len_bytes() / max_leaf_bytes) * ins_text.len());
155+
let max_diff = MAX_BYTES + ((rope.len_bytes() / MAX_BYTES) * ins_text.len());
158156

159157
assert!((rope.capacity() - rope.len_bytes()) <= max_diff);
160158
}

0 commit comments

Comments
 (0)