dymokomi/luce-prism
Source of release 0.6.1
0.6.1 / tests / names / sharing.lucb
## Internal regression: names are shared by their holders, found again through
## collisions after removals, and the table is freed with the last name.
import strings
test "names are shared by their holders and freed with the last name":
let before = live_names()
var first = try Name.of("subject")
var second = try Name.of("subject")
var third = try second.copy()
assert(first.shares(&second) and second.shares(&third))
assert(first.view() == "subject" and first.length() == 7)
var empty = try Name.of("")
assert(empty.is_empty() and empty.view() == "")
first.close()
second.close()
assert(third.view() == "subject" and live_names() == before + 1)
third.close()
empty.close()
assert(live_names() == before)
var held: Name[300]
for i in 0..<(usize)300:
var scratch: u8[16]
held[i] = try Name.of(try strings.format(scratch, f"n{i}"))
for i in 0..<(usize)300:
if i % 3 != 0:
held[i].close()
for i in 0..<(usize)300:
if i % 3 == 0:
var scratch: u8[16]
var again = try Name.of(try strings.format(scratch, f"n{i}"))
assert(again.shares(&held[i]))
again.close()
assert(live_names() == before + 100)
for i in 0..<(usize)300:
if i % 3 == 0:
held[i].close()
assert(live_names() == before)