Files
c3c/test/unit/stdlib/collections/anylist.c3
Book-reader 10241df23c Add generic InterfaceList type for storing values that implement a specific interface (#2433)
* Add generic InterfaceList type
---------

Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
2025-09-03 22:58:27 +02:00

29 lines
605 B
Plaintext

module anylist_test @test;
import std::collections::anylist;
fn void pop() => @pool()
{
AnyList l;
l.push(1.0);
l.push(1);
l.push("hello");
assert(l.pop(String)!! == "hello");
assert(l.pop(int)!! == 1);
assert(l.copy_pop(tmem)!!.type == double.typeid);
}
fn void predicates() => @pool()
{
AnyList l;
l.push(123u);
l.push(-1);
l.push("abc");
l.push(5.0);
l.remove_using_test(fn (x, p) => x.type == p.type, &&456u);
assert(l[0].type == int.typeid);
assert(l.get(0, int)!! == -1);
l.retain_if(fn (x) => x.type == double.typeid);
assert(l.len() == 1);
assert(l.get(0, double)!! == 5.0);
}