Deprecate old void! @benchmark and @test functions.

This commit is contained in:
Christoffer Lerno
2025-01-09 20:33:53 +01:00
parent c22b7d45c1
commit b941f93416
73 changed files with 988 additions and 860 deletions

View File

@@ -8,7 +8,7 @@ def List = List(<usz>);
def BitSet = BitSet(<2048>);
fn void! set_get()
fn void set_get()
{
BitSet bs;
assert(bs.cardinality() == 0);
@@ -47,7 +47,7 @@ fn void! set_get()
}
def GrowableBitSet = GrowableBitSet(<char>);
fn void! growable_set_get()
fn void growable_set_get()
{
GrowableBitSet bs;
bs.temp_init();

View File

@@ -3,7 +3,7 @@ import std::io;
import std::collections::map;
def IntMap = HashMap(<String, int>);
fn void! copy_map() @test
fn void copy_map() @test
{
TrackingAllocator alloc;
alloc.init(allocator::heap());
@@ -20,9 +20,9 @@ fn void! copy_map() @test
y.clear();
y.append("bye");
x.set(y.str_view(), 444);
assert(x.get("hello")! == 123);
assert(x.get("hellobye")! == 333);
assert(x.get("bye")! == 444);
assert(x.get("hello")!! == 123);
assert(x.get("hellobye")!! == 333);
assert(x.get("bye")!! == 444);
assert(alloc.allocated() > 0);
x.free();
y.free();
@@ -36,7 +36,7 @@ fn void! copy_map() @test
Otherwise when the map is freed, the copied-in keys will also be freed,
resulting in use-after-free.
*/
fn void! copy_keys() @test
fn void copy_keys() @test
{
String[] y;
@pool() {

View File

@@ -4,7 +4,7 @@ import std::collections::elastic_array;
def IntList = ElasticArray(<int, 10>);
def PtrList = ElasticArray(<void*, 10>);
fn void! delete_contains_index()
fn void delete_contains_index()
{
IntList test;
test.add_array({ 1, 2 });
@@ -26,14 +26,14 @@ fn void! delete_contains_index()
test.push(0);
test.insert_at(0, 0);
assert(test.array_view() == int[]{ 0, 2, 3, 0 });
assert(test.index_of(0)! == 0);
assert(test.rindex_of(0)! == 3);
assert(test.index_of(0)!! == 0);
assert(test.rindex_of(0)!! == 3);
test.remove_item(0);
assert(test.len() == 2);
assert(test.array_view() == int[]{ 2, 3 });
}
fn void! compact()
fn void compact()
{
PtrList test;
test.add_array({ null, &test });
@@ -46,7 +46,7 @@ fn void! compact()
assert(test.compact() == 0);
}
fn void! reverse()
fn void reverse()
{
IntList test;
test.reverse();
@@ -61,7 +61,7 @@ fn void! reverse()
assert(test.array_view() == int[] { 10, 1, 2, 3 });
}
fn void! remove_if()
fn void remove_if()
{
IntList test;
usz removed;
@@ -79,7 +79,7 @@ fn void! remove_if()
}
fn void! remove_using_test()
fn void remove_using_test()
{
IntList test;
usz removed;
@@ -96,7 +96,7 @@ fn void! remove_using_test()
assert(test.array_view() == int[]{11, 10, 20});
}
fn void! retain_if()
fn void retain_if()
{
IntList test;
usz removed;
@@ -113,7 +113,7 @@ fn void! retain_if()
assert(test.array_view() == int[]{11, 10, 20});
}
fn void! retain_using_test()
fn void retain_using_test()
{
IntList test;
usz removed;

View File

@@ -10,7 +10,7 @@ enum FooEnum
def FooEnumMap = EnumMap(<FooEnum, uint>);
fn void! enums()
fn void enums()
{
FooEnumMap nm;
nm.set(ONE, 1);

View File

@@ -3,33 +3,33 @@ import std::collections::linkedlist;
def IntList = LinkedList(<int>);
fn void! test_push_front()
fn void test_push_front()
{
IntList list;
list.push_front(23);
assert(list.len() == 1);
assert(list.first()! == 23);
assert(list.last()! == 23);
assert(list.first()!! == 23);
assert(list.last()!! == 23);
list.push_front(55);
assert(list.len() == 2);
assert(list.last()! == 23);
assert(list.first()! == 55);
assert(list.last()!! == 23);
assert(list.first()!! == 55);
}
fn void! test_push()
fn void test_push()
{
IntList list;
list.push(23);
assert(list.len() == 1);
assert(list.first()! == 23);
assert(list.last()! == 23);
assert(list.first()!! == 23);
assert(list.last()!! == 23);
list.push(55);
assert(list.len() == 2);
assert(list.last()! == 55);
assert(list.first()! == 23);
assert(list.last()!! == 55);
assert(list.first()!! == 23);
}
fn void! test_get()
fn void test_get()
{
IntList list;
list.push(23);
@@ -40,7 +40,7 @@ fn void! test_get()
assert(list.get(0) == 23);
}
fn void! test_insert()
fn void test_insert()
{
IntList list;
list.push(-3);
@@ -59,7 +59,7 @@ fn void! test_insert()
assert(list.get(6) == 1111);
}
fn void! test_set()
fn void test_set()
{
IntList list;
list.push(-3);
@@ -71,7 +71,7 @@ fn void! test_set()
assert(list.get(2) == 24);
}
fn void! test_remove_at()
fn void test_remove_at()
{
IntList list;
for (int i = 0; i < 10; i++) list.push(i);
@@ -85,7 +85,7 @@ fn void! test_remove_at()
assert(list.get(4) == 6);
}
fn void! test_remove()
fn void test_remove()
{
IntList list;
list.push(2);
@@ -95,79 +95,79 @@ fn void! test_remove()
assert(list.len() == 2);
}
fn void! test_remove_first_match()
fn void test_remove_first_match()
{
IntList list;
list.push(23);
list.push(55);
list.push(-3);
assert(list.remove_first_match(23));
assert(list.pop()! == -3);
assert(list.pop()! == 55);
assert(list.pop()!! == -3);
assert(list.pop()!! == 55);
assert(!list.len());
list.push(23);
list.push(55);
list.push(-3);
assert(list.remove_first_match(55));
assert(list.pop()! == -3);
assert(list.pop()! == 23);
assert(list.pop()!! == -3);
assert(list.pop()!! == 23);
assert(!list.len());
list.push(23);
list.push(55);
list.push(-3);
assert(list.remove_first_match(-3));
assert(list.pop()! == 55);
assert(list.pop()! == 23);
assert(list.pop()!! == 55);
assert(list.pop()!! == 23);
assert(!list.len());
}
fn void! test_remove_last_match()
fn void test_remove_last_match()
{
IntList list;
list.push(23);
list.push(55);
list.push(-3);
assert(list.remove_last_match(23));
assert(list.pop()! == -3);
assert(list.pop()! == 55);
assert(list.pop()!! == -3);
assert(list.pop()!! == 55);
assert(!list.len());
list.push(23);
list.push(55);
list.push(-3);
assert(list.remove_last_match(55));
assert(list.pop()! == -3);
assert(list.pop()! == 23);
assert(list.pop()!! == -3);
assert(list.pop()!! == 23);
assert(!list.len());
list.push(23);
list.push(55);
list.push(-3);
assert(list.remove_last_match(-3));
assert(list.pop()! == 55);
assert(list.pop()! == 23);
assert(list.pop()!! == 55);
assert(list.pop()!! == 23);
assert(!list.len());
}
fn void! test_pop()
fn void test_pop()
{
IntList list;
list.push(23);
list.push(55);
list.push(-3);
assert(list.len() == 3);
assert(list.first()! == 23);
assert(list.last()! == -3);
assert(list.pop()! == -3);
assert(list.first()!! == 23);
assert(list.last()!! == -3);
assert(list.pop()!! == -3);
assert(list.len() == 2);
assert(list.first()! == 23);
assert(list.last()! == 55);
assert(list.pop()! == 55);
assert(list.first()! == 23);
assert(list.last()! == 23);
assert(list.pop()! == 23);
assert(list.first()!! == 23);
assert(list.last()!! == 55);
assert(list.pop()!! == 55);
assert(list.first()!! == 23);
assert(list.last()!! == 23);
assert(list.pop()!! == 23);
assert(list.len() == 0);
assert(@catch(list.pop()));
assert(list.len() == 0);
@@ -175,22 +175,22 @@ fn void! test_pop()
assert(list.len() == 1);
}
fn void! test_remove_last()
fn void test_remove_last()
{
IntList list;
list.push(23);
list.push(55);
list.push(-3);
assert(list.len() == 3);
assert(list.first()! == 23);
assert(list.last()! == -3);
assert(list.first()!! == 23);
assert(list.last()!! == -3);
assert(@ok(list.remove_last()));
assert(list.len() == 2);
assert(list.first()! == 23);
assert(list.last()! == 55);
assert(list.first()!! == 23);
assert(list.last()!! == 55);
assert(@ok(list.remove_last()));
assert(list.first()! == 23);
assert(list.last()! == 23);
assert(list.first()!! == 23);
assert(list.last()!! == 23);
assert(@ok(list.remove_last()));
assert(list.len() == 0);
assert(@catch(list.pop()));
@@ -199,22 +199,22 @@ fn void! test_remove_last()
assert(list.len() == 1);
}
fn void! test_remove_first()
fn void test_remove_first()
{
IntList list;
list.push(23);
list.push(55);
list.push(-3);
assert(list.len() == 3);
assert(list.first()! == 23);
assert(list.last()! == -3);
assert(list.first()!! == 23);
assert(list.last()!! == -3);
assert(@ok(list.remove_first()));
assert(list.len() == 2);
assert(list.last()! == -3);
assert(list.first()! == 55);
assert(list.last()!! == -3);
assert(list.first()!! == 55);
assert(@ok(list.remove_first()));
assert(list.last()! == -3);
assert(list.first()! == -3);
assert(list.last()!! == -3);
assert(list.first()!! == -3);
assert(@ok(list.remove_first()));
assert(list.len() == 0);
assert(@catch(list.remove_first()));

View File

@@ -19,7 +19,7 @@ fn void overaligned_type()
}
fn void! delete_contains_index()
fn void delete_contains_index()
{
IntList test;
test.add_array({ 1, 2 });
@@ -41,14 +41,14 @@ fn void! delete_contains_index()
test.push(0);
test.insert_at(0, 0);
assert(test.array_view() == int[]{ 0, 2, 3, 0 });
assert(test.index_of(0)! == 0);
assert(test.rindex_of(0)! == 3);
assert(test.index_of(0)!! == 0);
assert(test.rindex_of(0)!! == 3);
test.remove_item(0);
assert(test.len() == 2);
assert(test.array_view() == int[]{ 2, 3 });
}
fn void! compact()
fn void compact()
{
PtrList test;
test.add_array({ null, &test });
@@ -61,7 +61,7 @@ fn void! compact()
assert(test.compact() == 0);
}
fn void! reverse()
fn void reverse()
{
IntList test;
test.reverse();
@@ -76,7 +76,7 @@ fn void! reverse()
assert(test.array_view() == int[] { 10, 1, 2, 3 });
}
fn void! remove_if()
fn void remove_if()
{
IntList test;
usz removed;
@@ -93,7 +93,7 @@ fn void! remove_if()
assert(test.array_view() == int[]{11, 10, 20});
}
fn void! init_with_array()
fn void init_with_array()
{
IntList foo;
foo.new_init_with_array({ 1, 2, 3});
@@ -101,7 +101,7 @@ fn void! init_with_array()
assert(foo[2] == 3);
}
fn void! init_with_temp_array()
fn void init_with_temp_array()
{
IntList foo;
foo.temp_init_with_array({ 1, 2, 3});
@@ -109,7 +109,7 @@ fn void! init_with_temp_array()
assert(foo[2] == 3);
}
fn void! remove_using_test()
fn void remove_using_test()
{
IntList test;
usz removed;
@@ -126,7 +126,7 @@ fn void! remove_using_test()
assert(test.array_view() == int[]{11, 10, 20});
}
fn void! retain_if()
fn void retain_if()
{
IntList test;
usz removed;
@@ -143,7 +143,7 @@ fn void! retain_if()
assert(test.array_view() == int[]{11, 10, 20});
}
fn void! retain_using_test()
fn void retain_using_test()
{
IntList test;
usz removed;

View File

@@ -6,17 +6,17 @@ fn void test_general()
Object* root = object::new_obj(allocator::heap());
root.set("foo", 1);
root.set("bar", "baz");
assert(root.get_int("foo")! == 1);
assert(root.get_string("bar")! == "baz");
assert(root.get_int("foo")!! == 1);
assert(root.get_string("bar")!! == "baz");
Object* goo = root.set("goo", object::new_obj(allocator::heap()));
goo.push("hello");
goo.push(132);
assert(root.get("goo").get_int_at(1)! == 132);
assert(root.get("goo").get_string_at(0)! == "hello");
assert(root.get("goo").get_int_at(1)!! == 132);
assert(root.get("goo").get_string_at(0)!! == "hello");
Object* abc = root.get_or_create_obj("abc80");
abc.set("cool", 1.3);
assert(root.get("abc80").get_int("cool")! == 1);
assert(root.get("abc80").get_float("cool")! == 1.3);
assert(root.get("abc80").get_int("cool")!! == 1);
assert(root.get("abc80").get_float("cool")!! == 1.3);
assert((root.get_int("yyy") ?? -1) == -1);
root.set("yyy", true);
assert(root.get_bool("yyy") ?? false);

View File

@@ -4,7 +4,7 @@ import std::collections::priorityqueue;
def Queue = PriorityQueue(<int>);
fn void! priorityqueue()
fn void priorityqueue()
{
Queue q;
assert(q.is_empty());
@@ -14,25 +14,25 @@ fn void! priorityqueue()
assert(q.len() == 2);
int x;
x = q.pop()!;
x = q.pop()!!;
assert(x == 1, "got %d; want %d", x, 1);
x = q.pop()!;
x = q.pop()!!;
assert(x == 2, "got %d; want %d", x, 2);
q.push(3);
q.push(2);
q.push(1);
x = q.pop()!;
x = q.pop()!!;
assert(x == 1, "got %d; want %d", x, 1);
x = q.pop()!;
x = q.pop()!!;
assert(x == 2, "got %d; want %d", x, 2);
x = q.pop()!;
x = q.pop()!!;
assert(x == 3, "got %d; want %d", x, 3);
}
def QueueMax = PriorityQueueMax(<int>);
fn void! priorityqueue_max()
fn void priorityqueue_max()
{
QueueMax q;
assert(q.is_empty());
@@ -42,18 +42,18 @@ fn void! priorityqueue_max()
assert(q.len() == 2);
int x;
x = q.pop()!;
x = q.pop()!!;
assert(x == 2, "got %d; want %d", x, 2);
x = q.pop()!;
x = q.pop()!!;
assert(x == 1, "got %d; want %d", x, 1);
q.push(3);
q.push(2);
q.push(1);
x = q.pop()!;
x = q.pop()!!;
assert(x == 3, "got %d; want %d", x, 3);
x = q.pop()!;
x = q.pop()!!;
assert(x == 2, "got %d; want %d", x, 2);
x = q.pop()!;
x = q.pop()!!;
assert(x == 1, "got %d; want %d", x, 1);
}

View File

@@ -4,7 +4,7 @@ import std::collections::range;
def IntRange = Range(<int>);
def IntExRange = ExclusiveRange(<int>);
fn void! test_range()
fn void test_range()
{
IntRange range = { -4, 2 };
int sum = 0;
@@ -19,7 +19,7 @@ fn void! test_range()
assert(!range.contains(3));
}
fn void! test_exrange()
fn void test_exrange()
{
IntExRange range = { -4, 2 };
int sum = 0;

View File

@@ -4,7 +4,7 @@ import std::io;
def Buffer = RingBuffer(<char, 4>);
fn void! push_get()
fn void push_get()
{
Buffer rb;
rb.init();
@@ -24,6 +24,6 @@ fn void! push_get()
assert(rb.get(2) == 4);
assert(rb.get(3) == 5);
char c = rb.pop()!;
char c = rb.pop()!!;
assert(c == 5);
}