mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
Hash maps now copy keys if keys are copyable.
This commit is contained in:
30
test/unit/stdlib/collections/copy_map.c3
Normal file
30
test/unit/stdlib/collections/copy_map.c3
Normal file
@@ -0,0 +1,30 @@
|
||||
module test;
|
||||
import std::io;
|
||||
import std::collections::map;
|
||||
|
||||
fn void! copy_map() @test
|
||||
{
|
||||
TrackingAllocator alloc;
|
||||
alloc.init(mem::heap());
|
||||
io::printfn("Heap mem: %d", alloc.allocated());
|
||||
mem::@scoped(&alloc)
|
||||
{
|
||||
HashMap(<String, int>) x;
|
||||
x.init();
|
||||
DString y;
|
||||
y.append("hello");
|
||||
x.set(y.as_str(), 123);
|
||||
y.append("bye");
|
||||
x.set(y.as_str(), 333);
|
||||
y.clear();
|
||||
y.append("bye");
|
||||
x.set(y.as_str(), 444);
|
||||
assert(x.get("hello")! == 123);
|
||||
assert(x.get("hellobye")! == 333);
|
||||
assert(x.get("bye")! == 444);
|
||||
assert(alloc.allocated() > 0);
|
||||
x.free();
|
||||
y.free();
|
||||
assert(alloc.allocated() == 0);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user