add test for arena dupe

This commit is contained in:
Emil Lerch 2026-06-29 21:26:15 -07:00
parent 0f09c6d31a
commit fd5af31114
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -1622,3 +1622,23 @@ test "PortfolioData.revalue: returns false when the recompute yields no allocati
defer overlay.deinit();
try testing.expect(!pd.revalue(Date.fromYmd(2026, 5, 8), &overlay));
}
test "dupePricesArena: copies entries with arena-owned keys" {
var arena = std.heap.ArenaAllocator.init(testing.allocator);
defer arena.deinit();
const a = arena.allocator();
var src = std.StringHashMap(f64).init(testing.allocator);
defer src.deinit();
try src.put("AAPL", 1.5);
try src.put("SPY", 2.5);
// Copy lives in the arena (keys duped there), so it survives `src`
// being freed; reaped wholesale by arena.deinit (no out.deinit).
var out = dupePricesArena(a, &src);
src.clearAndFree(); // drop the source + its keys
try testing.expectEqual(@as(usize, 2), out.count());
try testing.expectApproxEqAbs(@as(f64, 1.5), out.get("AAPL").?, 0.0001);
try testing.expectApproxEqAbs(@as(f64, 2.5), out.get("SPY").?, 0.0001);
}