From 2065df12c0b758f0c1390e25a7c4a93d6ed9f95c Mon Sep 17 00:00:00 2001 From: Matthew Howard Date: Fri, 7 Feb 2025 16:50:21 +0000 Subject: [PATCH] add unit test for ghost pair limit --- src/allocator.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/allocator.rs b/src/allocator.rs index b6303e4a..aa46a89a 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -1041,6 +1041,19 @@ mod tests { } assert_eq!(a.new_pair(atom, atom).unwrap_err().1, "too many pairs"); + assert_eq!(a.add_ghost_pair(1).unwrap_err().1, "too many pairs"); + } + + #[test] + fn test_ghost_pair_limit() { + let mut a = Allocator::new(); + let atom = a.new_atom(b"foo").unwrap(); + // one pair is OK + let _pair1 = a.new_pair(atom, atom).unwrap(); + a.add_ghost_pair(MAX_NUM_PAIRS - 1).unwrap(); + + assert_eq!(a.new_pair(atom, atom).unwrap_err().1, "too many pairs"); + assert_eq!(a.add_ghost_pair(1).unwrap_err().1, "too many pairs"); } #[test]