mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Upgrade of mingw in CI. Fix problems using reflection on interface types #1203. Improved debug information on defer. $foreach doesn't create an implicit syntactic scope. Error if `@if` depends on `@if`. Updated Linux stacktrace. Fix of default argument stacktrace. Allow linking libraries directly by file path. Improve inlining warning messages. Added `index_of_char_from`. Compiler crash using enum nameof from different module #1205. Removed unused fields in find_msvc. Use vswhere to find msvc. Update tests for LLVM 19
156 lines
3.4 KiB
C
156 lines
3.4 KiB
C
module list_test @test;
|
|
import std::collections::list;
|
|
|
|
def IntList = List(<int>);
|
|
def PtrList = List(<void*>);
|
|
|
|
struct Overalign
|
|
{
|
|
double[<33>] x;
|
|
}
|
|
|
|
fn void overaligned_type()
|
|
{
|
|
List(<Overalign>) l;
|
|
Overalign y;
|
|
for (int i = 0; i < 1000; i++) l.push(y);
|
|
assert((usz)l.get_ref(2) - (usz)l.get_ref(1) == Overalign.sizeof);
|
|
}
|
|
|
|
|
|
fn void! delete_contains_index()
|
|
{
|
|
IntList test;
|
|
test.add_array({ 1, 2 });
|
|
assert(test.contains(1));
|
|
assert(test.contains(2));
|
|
assert(!test.contains(0));
|
|
assert(!test.contains(3));
|
|
assert(test.array_view() == int[]{ 1, 2 });
|
|
test.push(3);
|
|
assert(test.array_view() == int[]{ 1, 2, 3 });
|
|
assert(test.contains(3));
|
|
test[0] = 10;
|
|
assert(test.contains(10));
|
|
test.remove_all_matches(10);
|
|
assert(test.array_view() == int[]{ 2, 3 });
|
|
assert(!test.contains(1));
|
|
assert(test.contains(2));
|
|
assert(test.len() == 2);
|
|
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);
|
|
test.remove_all_matches(0);
|
|
assert(test.len() == 2);
|
|
assert(test.array_view() == int[]{ 2, 3 });
|
|
}
|
|
|
|
fn void! compact()
|
|
{
|
|
PtrList test;
|
|
test.add_array({ null, &test });
|
|
assert(test.compact_count() == 1);
|
|
test.push(null);
|
|
assert(test.compact_count() == 1);
|
|
assert(test.len() == 3);
|
|
assert(test.compact() == 2);
|
|
assert(test.len() == 1);
|
|
assert(test.compact() == 0);
|
|
}
|
|
|
|
fn void! reverse()
|
|
{
|
|
IntList test;
|
|
test.reverse();
|
|
test.add_array({ 1, 2 });
|
|
test.push(3);
|
|
assert(test.array_view() == int[] { 1, 2, 3});
|
|
test.reverse();
|
|
assert(test.array_view() == int[] { 3, 2, 1 });
|
|
test.push(10);
|
|
assert(test.array_view() == int[] { 3, 2, 1, 10 });
|
|
test.reverse();
|
|
assert(test.array_view() == int[] { 10, 1, 2, 3 });
|
|
}
|
|
|
|
fn void! remove_if()
|
|
{
|
|
IntList test;
|
|
usz removed;
|
|
|
|
test.add_array({ 1, 11, 2, 10, 20 });
|
|
removed = test.remove_if(&filter);
|
|
assert(removed == 3);
|
|
assert(test.array_view() == int[]{1, 2});
|
|
|
|
test.clear();
|
|
test.add_array({ 1, 11, 2, 10, 20 });
|
|
removed = test.remove_if(&select);
|
|
assert(removed == 2);
|
|
assert(test.array_view() == int[]{11, 10, 20});
|
|
}
|
|
|
|
fn void! remove_using_test()
|
|
{
|
|
IntList test;
|
|
usz removed;
|
|
|
|
test.add_array({ 1, 11, 2, 10, 20 });
|
|
removed = test.remove_using_test(fn bool(i, ctx) => *i >= *(int*)ctx, &&10);
|
|
assert(removed == 3);
|
|
assert(test.array_view() == int[]{1, 2});
|
|
|
|
test.clear();
|
|
test.add_array({ 1, 11, 2, 10, 20 });
|
|
removed = test.remove_using_test(fn bool(i, ctx) => *i < *(int*)ctx, &&10);
|
|
assert(removed == 2);
|
|
assert(test.array_view() == int[]{11, 10, 20});
|
|
}
|
|
|
|
fn void! retain_if()
|
|
{
|
|
IntList test;
|
|
usz removed;
|
|
|
|
test.add_array({ 1, 11, 2, 10, 20 });
|
|
removed = test.retain_if(&select);
|
|
assert(removed == 3);
|
|
assert(test.array_view() == int[]{1, 2});
|
|
|
|
test.clear();
|
|
test.add_array({ 1, 11, 2, 10, 20 });
|
|
removed = test.retain_if(&filter);
|
|
assert(removed == 2);
|
|
assert(test.array_view() == int[]{11, 10, 20});
|
|
}
|
|
|
|
fn void! retain_using_test()
|
|
{
|
|
IntList test;
|
|
usz removed;
|
|
|
|
test.add_array({ 1, 11, 2, 10, 20 });
|
|
removed = test.remove_using_test(fn bool(i, ctx) => *i >= *(int*)ctx, &&10);
|
|
assert(removed == 3);
|
|
assert(test.array_view() == int[]{1, 2});
|
|
|
|
test.clear();
|
|
test.add_array({ 1, 11, 2, 10, 20 });
|
|
removed = test.remove_using_test(fn bool(i, ctx) => *i < *(int*)ctx, &&10);
|
|
assert(removed == 2);
|
|
assert(test.array_view() == int[]{11, 10, 20});
|
|
}
|
|
|
|
module list_test;
|
|
|
|
fn bool filter(int* i)
|
|
{
|
|
return *i >= 10;
|
|
}
|
|
|
|
fn bool select(int* i)
|
|
{
|
|
return *i < 10;
|
|
} |