Files
sakurac/tests/core/allocators.sakura
T
2026-10-28 22:13:49 -05:00

17 lines
631 B
Plaintext

# Tests of the memory `core` gives: a block of the heap keeps what it holds
# through resizing. The allocators of std, an arena and a pool, are tested
# there.
import std::testing;
@test def uncleared_memory_keeps_what_it_holds_through_resizing(t: &mut tester): void {
val block := raw_allocate(64) as *mut u64;
for i in 0..8u { block[i] = i * 11; }
val grown := raw_resize(block as *mut u8, 8192) as *mut u64;
var same := true;
for i in 0..8u { same = same && grown[i] == i * 11; }
val shrunk := raw_resize(grown as *mut u8, 16) as *mut u64;
t.expects(same && shrunk[1] == 11);
raw_release(shrunk as *mut u8);
}