mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
Create a unit7 for all unit tests.
This commit is contained in:
32
test/unit7/stdlib/core/array.c3
Normal file
32
test/unit7/stdlib/core/array.c3
Normal file
@@ -0,0 +1,32 @@
|
||||
module arraytests @test;
|
||||
|
||||
fn void find()
|
||||
{
|
||||
int[3] a = { 1, 2, 3 };
|
||||
assert(array::index_of(a, 2)!! == 1);
|
||||
assert(array::index_of(a, 1)!! == 0);
|
||||
assert(array::index_of(a, 3)!! == 2);
|
||||
assert(@catch(array::index_of(a, 4)) == SearchResult.MISSING);
|
||||
}
|
||||
|
||||
fn void find_subarray()
|
||||
{
|
||||
int[] a = { 1, 2, 3 };
|
||||
assert(array::index_of(a, 2)!! == 1);
|
||||
assert(array::index_of(a, 1)!! == 0);
|
||||
assert(array::index_of(a, 3)!! == 2);
|
||||
assert(@catch(array::index_of(a, 4)) == SearchResult.MISSING);
|
||||
}
|
||||
|
||||
fn void concat()
|
||||
{
|
||||
int[3] a = { 1, 2, 3 };
|
||||
free(array::concat_new(a, a));
|
||||
free(array::concat_new(a[..], a[..]));
|
||||
free(array::concat_new(a[:0], a[:0]));
|
||||
free(array::concat_new((int[2]) { 1, 2 }, a[:0]));
|
||||
free(array::concat_new(a[:0], (int[2]) { 1, 2 }));
|
||||
int[] c = array::concat_new(a[1..2], a);
|
||||
defer free(c);
|
||||
assert (c == (int[]){ 2, 3, 1, 2, 3 });
|
||||
}
|
||||
Reference in New Issue
Block a user