mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Update tests to (Foo) { ... } syntax.
This commit is contained in:
@@ -37,7 +37,7 @@ fn void set_get()
|
||||
assert(!x);
|
||||
}
|
||||
}
|
||||
assert(found.array_view() == usz[]{0, 2000});
|
||||
assert(found.array_view() == (usz[]){0, 2000});
|
||||
|
||||
bs.unset(0);
|
||||
assert(!bs.get(0));
|
||||
@@ -81,7 +81,7 @@ fn void growable_set_get()
|
||||
assert(!x, "Should not get here");
|
||||
}
|
||||
}
|
||||
assert(found.array_view() == usz[]{0, 2000}, "Array view should hold 2");
|
||||
assert(found.array_view() == (usz[]){0, 2000}, "Array view should hold 2");
|
||||
|
||||
bs.unset(0);
|
||||
assert(!bs.get(0), "Get should be false");
|
||||
|
||||
@@ -12,25 +12,25 @@ fn void delete_contains_index()
|
||||
assert(test.contains(2));
|
||||
assert(!test.contains(0));
|
||||
assert(!test.contains(3));
|
||||
assert(test.array_view() == int[]{ 1, 2 });
|
||||
assert(test.array_view() == (int[]){ 1, 2 });
|
||||
test.push(3);
|
||||
assert(test.array_view() == int[]{ 1, 2, 3 });
|
||||
assert(test.array_view() == (int[]){ 1, 2, 3 });
|
||||
assert(test.contains(3));
|
||||
test[0] = 10;
|
||||
assert(test.contains(10));
|
||||
test.remove_item(10);
|
||||
assert(test.array_view() == int[]{ 2, 3 });
|
||||
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.array_view() == (int[]){ 0, 2, 3, 0 });
|
||||
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 });
|
||||
assert(test.array_view() == (int[]){ 2, 3 });
|
||||
}
|
||||
|
||||
fn void compact()
|
||||
@@ -52,13 +52,13 @@ fn void reverse()
|
||||
test.reverse();
|
||||
test.add_array({ 1, 2 });
|
||||
test.push(3);
|
||||
assert(test.array_view() == int[] { 1, 2, 3});
|
||||
assert(test.array_view() == (int[]) { 1, 2, 3});
|
||||
test.reverse();
|
||||
assert(test.array_view() == int[] { 3, 2, 1 });
|
||||
assert(test.array_view() == (int[]) { 3, 2, 1 });
|
||||
test.push(10);
|
||||
assert(test.array_view() == int[] { 3, 2, 1, 10 });
|
||||
assert(test.array_view() == (int[]) { 3, 2, 1, 10 });
|
||||
test.reverse();
|
||||
assert(test.array_view() == int[] { 10, 1, 2, 3 });
|
||||
assert(test.array_view() == (int[]) { 10, 1, 2, 3 });
|
||||
}
|
||||
|
||||
fn void remove_if()
|
||||
@@ -69,13 +69,13 @@ fn void remove_if()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_if(&filter);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
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});
|
||||
assert(test.array_view() == (int[]){11, 10, 20});
|
||||
}
|
||||
|
||||
|
||||
@@ -87,13 +87,13 @@ fn void remove_using_test()
|
||||
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});
|
||||
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});
|
||||
assert(test.array_view() == (int[]){11, 10, 20});
|
||||
}
|
||||
|
||||
fn void retain_if()
|
||||
@@ -104,13 +104,13 @@ fn void retain_if()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.retain_if(&select);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
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});
|
||||
assert(test.array_view() == (int[]){11, 10, 20});
|
||||
}
|
||||
|
||||
fn void retain_using_test()
|
||||
@@ -121,13 +121,13 @@ fn void retain_using_test()
|
||||
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});
|
||||
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});
|
||||
assert(test.array_view() == (int[]){11, 10, 20});
|
||||
}
|
||||
|
||||
module elastic_array_test;
|
||||
|
||||
@@ -31,25 +31,25 @@ fn void delete_contains_index()
|
||||
assert(test.contains(2));
|
||||
assert(!test.contains(0));
|
||||
assert(!test.contains(3));
|
||||
assert(test.array_view() == int[]{ 1, 2 });
|
||||
assert(test.array_view() == { 1, 2 });
|
||||
test.push(3);
|
||||
assert(test.array_view() == int[]{ 1, 2, 3 });
|
||||
assert(test.array_view() == { 1, 2, 3 });
|
||||
assert(test.contains(3));
|
||||
test[0] = 10;
|
||||
assert(test.contains(10));
|
||||
test.remove_item(10);
|
||||
assert(test.array_view() == int[]{ 2, 3 });
|
||||
assert(test.array_view() == { 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.array_view() == { 0, 2, 3, 0 });
|
||||
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 });
|
||||
assert(test.array_view() == { 2, 3 });
|
||||
}
|
||||
|
||||
fn void compact()
|
||||
@@ -74,13 +74,13 @@ fn void reverse()
|
||||
test.reverse();
|
||||
test.add_array({ 1, 2 });
|
||||
test.push(3);
|
||||
assert(test.array_view() == int[] { 1, 2, 3});
|
||||
assert(test.array_view() == { 1, 2, 3});
|
||||
test.reverse();
|
||||
assert(test.array_view() == int[] { 3, 2, 1 });
|
||||
assert(test.array_view() == { 3, 2, 1 });
|
||||
test.push(10);
|
||||
assert(test.array_view() == int[] { 3, 2, 1, 10 });
|
||||
assert(test.array_view() == { 3, 2, 1, 10 });
|
||||
test.reverse();
|
||||
assert(test.array_view() == int[] { 10, 1, 2, 3 });
|
||||
assert(test.array_view() == { 10, 1, 2, 3 });
|
||||
}
|
||||
|
||||
fn void remove_if()
|
||||
@@ -92,13 +92,13 @@ fn void remove_if()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.remove_if(&filter);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
assert(test.array_view() == {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});
|
||||
assert(test.array_view() == {11, 10, 20});
|
||||
}
|
||||
|
||||
fn void init_with_array()
|
||||
@@ -127,13 +127,13 @@ fn void remove_using_test()
|
||||
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});
|
||||
assert(test.array_view() == {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});
|
||||
assert(test.array_view() == {11, 10, 20});
|
||||
}
|
||||
|
||||
fn void retain_if()
|
||||
@@ -145,13 +145,13 @@ fn void retain_if()
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
removed = test.retain_if(&select);
|
||||
assert(removed == 3);
|
||||
assert(test.array_view() == int[]{1, 2});
|
||||
assert(test.array_view() == {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});
|
||||
assert(test.array_view() == {11, 10, 20});
|
||||
}
|
||||
|
||||
fn void retain_using_test()
|
||||
@@ -163,13 +163,13 @@ fn void retain_using_test()
|
||||
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});
|
||||
assert(test.array_view() == {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});
|
||||
assert(test.array_view() == {11, 10, 20});
|
||||
}
|
||||
|
||||
module list_test;
|
||||
|
||||
@@ -24,9 +24,9 @@ fn void concat()
|
||||
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 }));
|
||||
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 });
|
||||
assert (c == (int[]){ 2, 3, 1, 2, 3 });
|
||||
}
|
||||
|
||||
@@ -62,16 +62,16 @@ fn void test_prefetch()
|
||||
|
||||
fn void test_hash()
|
||||
{
|
||||
char{}.hash();
|
||||
ichar{}.hash();
|
||||
short{}.hash();
|
||||
ushort{}.hash();
|
||||
int{}.hash();
|
||||
uint{}.hash();
|
||||
long{}.hash();
|
||||
ulong{}.hash();
|
||||
int128{}.hash();
|
||||
uint128{}.hash();
|
||||
(char){}.hash();
|
||||
(ichar){}.hash();
|
||||
(short){}.hash();
|
||||
(ushort){}.hash();
|
||||
(int){}.hash();
|
||||
(uint){}.hash();
|
||||
(long){}.hash();
|
||||
(ulong){}.hash();
|
||||
(int128){}.hash();
|
||||
(uint128){}.hash();
|
||||
String x = "abc";
|
||||
char[] y = "abc";
|
||||
assert(x.hash() == y.hash());
|
||||
|
||||
@@ -10,7 +10,7 @@ fn usz! Foo.to_format(&self, Formatter *f) @dynamic
|
||||
|
||||
fn void test_ref() @test
|
||||
{
|
||||
Foo* f = &&Foo{ 8 };
|
||||
Foo* f = &&(Foo){ 8 };
|
||||
Foo* f0 = null;
|
||||
int* a = (void*)(uptr)0x40;
|
||||
int* b = null;
|
||||
|
||||
@@ -36,7 +36,7 @@ fn void csv_each_row()
|
||||
String[] want = t.want;
|
||||
|
||||
CsvReader r;
|
||||
r.init(ByteReader{}.init(t.input), t.sep);
|
||||
r.init((ByteReader){}.init(t.input), t.sep);
|
||||
r.@each_row(; String[] row) {
|
||||
foreach (i, s : row) {
|
||||
assert(want.len > 0,
|
||||
@@ -58,7 +58,7 @@ fn void csv_row()
|
||||
","
|
||||
};
|
||||
CsvReader r;
|
||||
r.init(ByteReader{}.init(t.input), t.sep);
|
||||
r.init((ByteReader){}.init(t.input), t.sep);
|
||||
CsvRow row = r.read_temp_row()!!;
|
||||
assert(row.list.len == t.want.len, "not enough records found");
|
||||
for (int i = 0; i < row.list.len; i++) {
|
||||
|
||||
@@ -8,7 +8,7 @@ fn void test_multiwriter()
|
||||
defer mw.free();
|
||||
|
||||
String want = "foobar";
|
||||
io::copy_to(ByteReader{}.init(want), &mw)!!;
|
||||
io::copy_to((ByteReader){}.init(want), &mw)!!;
|
||||
|
||||
assert(w1.str_view() == want,
|
||||
"invalid write; got: %s, want: %s", w1.str_view(), want);
|
||||
|
||||
@@ -5,7 +5,7 @@ fn void test_teereader()
|
||||
String want = "foobar";
|
||||
|
||||
ByteWriter w;
|
||||
TeeReader r = tee_reader(ByteReader{}.init(want), w.temp_init());
|
||||
TeeReader r = tee_reader((ByteReader){}.init(want), w.temp_init());
|
||||
|
||||
char[16] buf;
|
||||
usz n = r.read(buf[..])!!;
|
||||
|
||||
@@ -11,9 +11,9 @@ fn void test_abs() @test
|
||||
assert(math::abs(z) == 21.0f);
|
||||
$assert @typeis(math::abs(z), float);
|
||||
int[<3>] xx = { -1, -1000, 1000 };
|
||||
assert(math::abs(xx) == int[<3>] { 1, 1000, 1000 });
|
||||
assert(math::abs(xx) == (int[<3>]) { 1, 1000, 1000 });
|
||||
double[<3>] yy = { -1, -0.5, 1000 };
|
||||
assert(math::abs(yy) == double[<3>] { 1, 0.5, 1000 });
|
||||
assert(math::abs(yy) == (double[<3>]) { 1, 0.5, 1000 });
|
||||
}
|
||||
|
||||
fn void test_acos() @test
|
||||
@@ -269,7 +269,7 @@ fn void test_ceil() @test
|
||||
assert(math::ceil(f) == 0.0f);
|
||||
$assert @typeis(math::ceil(f), float);
|
||||
double[<5>] vec = { -123.1, 123.1, 0.1, -0.9, 0 };
|
||||
assert(math::ceil(vec) == double[<5>] { -123, 124, 1, 0, 0 });
|
||||
assert(math::ceil(vec) == (double[<5>]) { -123, 124, 1, 0, 0 });
|
||||
}
|
||||
|
||||
fn void test_cos() @test
|
||||
@@ -351,7 +351,7 @@ fn void test_floor() @test
|
||||
assert(math::floor(f) == -1.0f);
|
||||
$assert @typeis(math::floor(f), float);
|
||||
double[<5>] vec = { -123.1, 123.1, 0.9, -0.1, 0 };
|
||||
assert(math::floor(vec) == double[<5>] { -124, 123, 0, -1, 0 });
|
||||
assert(math::floor(vec) == (double[<5>]) { -124, 123, 0, -1, 0 });
|
||||
}
|
||||
|
||||
fn void test_log() @test
|
||||
@@ -536,7 +536,7 @@ fn void test_trunc() @test
|
||||
assert(math::trunc(f) == -0.0f);
|
||||
$assert @typeis(math::trunc(f), float);
|
||||
double[<5>] vec = { -123.9, 123.9, 0.9, -0.9, 0 };
|
||||
assert(math::trunc(vec) == double[<5>] { -123, 123, 0, 0, 0 });
|
||||
assert(math::trunc(vec) == (double[<5>]) { -123, 123, 0, 0, 0 });
|
||||
}
|
||||
|
||||
fn void test_round_decimals() @test
|
||||
@@ -579,14 +579,14 @@ fn void test_muldiv()
|
||||
assert(h.muldiv(2_000_000_000_000u64, 1_000_000_000u64) == 2_000_000_000_000_000u64);
|
||||
|
||||
char[<4>] i = {20, 30, 40, 50};
|
||||
assert(i.muldiv(12,10) == char[<4>] {24, 36, 48, 60});
|
||||
assert(i.muldiv(char[<4>]{11, 12, 13, 14}, char[<4>]{10,10,10,10}) == char[<4>]{22, 36, 52, 70});
|
||||
assert(i.muldiv(12,10) == (char[<4>]) {24, 36, 48, 60});
|
||||
assert(i.muldiv((char[<4>]){11, 12, 13, 14}, (char[<4>]){10,10,10,10}) == (char[<4>]){22, 36, 52, 70});
|
||||
|
||||
long[<4>] j = {1_000_000_000_000i64, 2_000_000_000_000i64, 3_000_000_000_000i64, 4_000_000_000_000i64};
|
||||
assert(j.muldiv(2_000_000_000_000i64, 1_000_000_000i64) == long[<4>]{2_000_000_000_000_000i64, 4_000_000_000_000_000i64, 6_000_000_000_000_000i64, 8_000_000_000_000_000i64});
|
||||
assert(j.muldiv(2_000_000_000_000i64, 1_000_000_000i64) == (long[<4>]){2_000_000_000_000_000i64, 4_000_000_000_000_000i64, 6_000_000_000_000_000i64, 8_000_000_000_000_000i64});
|
||||
|
||||
ichar[<4>] k = {20, 30, 40, 50};
|
||||
assert(k.muldiv(20,-10) == ichar[<4>]{-40,-60,-80,-100});
|
||||
assert(k.muldiv(20,-10) == (ichar[<4>]){-40,-60,-80,-100});
|
||||
}
|
||||
|
||||
fn void test_gcd() @test
|
||||
|
||||
@@ -12,36 +12,36 @@ def ComplexType = Complex(<ElementType>);
|
||||
fn void complex_mul_imaginary()
|
||||
{
|
||||
ComplexType i = complex::IMAGINARY(<ElementType>);
|
||||
assert(i.mul(i).equals(ComplexType{-1, 0}));
|
||||
assert(i.mul(i).mul(i).equals(ComplexType{0, -1}));
|
||||
assert(i.mul(i).equals((ComplexType){-1, 0}));
|
||||
assert(i.mul(i).mul(i).equals((ComplexType){0, -1}));
|
||||
}
|
||||
|
||||
fn void complex_add()
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
ComplexType b = {1, 2};
|
||||
assert(a.add(b).equals(ComplexType{4, 6}));
|
||||
assert(a.add_each(1).equals(ComplexType{4, 5}));
|
||||
assert(a.add(b).equals((ComplexType){4, 6}));
|
||||
assert(a.add_each(1).equals((ComplexType){4, 5}));
|
||||
}
|
||||
|
||||
fn void complex_sub()
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
ComplexType b = {1, 2};
|
||||
assert(a.sub(b).equals(ComplexType{2, 2}));
|
||||
assert(a.sub_each(1).equals(ComplexType{2, 3}));
|
||||
assert(a.sub(b).equals((ComplexType){2, 2}));
|
||||
assert(a.sub_each(1).equals((ComplexType){2, 3}));
|
||||
}
|
||||
|
||||
fn void complex_scale()
|
||||
{
|
||||
ComplexType a = {2, 1};
|
||||
assert(a.scale(2).equals(ComplexType{4, 2}));
|
||||
assert(a.scale(2).equals((ComplexType){4, 2}));
|
||||
}
|
||||
|
||||
fn void complex_conjugate()
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
assert(a.conjugate().equals(ComplexType{3, -4}));
|
||||
assert(a.conjugate().equals((ComplexType){3, -4}));
|
||||
}
|
||||
|
||||
fn void complex_inverse() @if(types::is_float(ElementType))
|
||||
@@ -54,6 +54,6 @@ fn void complex_div() @if(types::is_float(ElementType))
|
||||
{
|
||||
ComplexType a = {2, 5};
|
||||
ComplexType b = {4, -1};
|
||||
assert(a.div(b).equals(ComplexType{3.0/17.0, 22.0/17.0}));
|
||||
assert(a.div(b).equals((ComplexType){3.0/17.0, 22.0/17.0}));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ fn void test_mat4()
|
||||
Matrix4 calc = mat.mul(mat2);
|
||||
assert(calc.m == mat.m);
|
||||
|
||||
Matrix4 translated = mat.translate(Vec3{0.0, 0.0, 0.0});
|
||||
Matrix4 translated = mat.translate({0.0, 0.0, 0.0});
|
||||
assert(translated.m == mat.m);
|
||||
};
|
||||
|
||||
@@ -117,6 +117,6 @@ fn void test_mat2_inverse()
|
||||
|
||||
fn void test_vec3()
|
||||
{
|
||||
Vec3 cross = Vec3{2,3,4}.cross(Vec3{5,6,7});
|
||||
assert(cross == Vec3{-3,6,-3});
|
||||
Vec3 cross = (Vec3){2,3,4}.cross({5,6,7});
|
||||
assert(cross == {-3,6,-3});
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ fn void test()
|
||||
0.000000, 0.000000, 0.000000, 1.000000
|
||||
};
|
||||
|
||||
Matrix4 rotation = Quaternion {0.5, 0.5, 0.5, 1}.to_matrix();
|
||||
Matrix4f rotation_f = Quaternionf {0.5, 0.5, 0.5, 1}.to_matrixf();
|
||||
Matrix4 rotation = (Quaternion) {0.5, 0.5, 0.5, 1}.to_matrix();
|
||||
Matrix4f rotation_f = (Quaternionf) {0.5, 0.5, 0.5, 1}.to_matrixf();
|
||||
|
||||
assert(math::round_to_decimals((double[<16>])result.m, 2) == math::round_to_decimals((double[<16>])rotation.m, 2));
|
||||
assert(math::round_to_decimals((float[<16>])result.m, 2) == math::round_to_decimals((float[<16>])rotation_f.m, 2));
|
||||
|
||||
@@ -12,190 +12,66 @@ struct EncodeTest
|
||||
}
|
||||
|
||||
EncodeTest[?] decode_with_error_tests @local = {
|
||||
{
|
||||
"",
|
||||
"",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"abc",
|
||||
"abc",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"1%41",
|
||||
"1A",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"1%41%42%43",
|
||||
"1ABC",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%4a",
|
||||
"J",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%6F",
|
||||
"o",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%",
|
||||
"",
|
||||
UrlDecodingError.INVALID_HEX,
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%a",
|
||||
"",
|
||||
UrlDecodingError.INVALID_HEX,
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%1",
|
||||
"",
|
||||
UrlDecodingError.INVALID_HEX,
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"123%45%6",
|
||||
"",
|
||||
UrlDecodingError.INVALID_HEX,
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"%zzzzz",
|
||||
"",
|
||||
UrlDecodingError.INVALID_HEX,
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"a+b",
|
||||
"a b",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"a%20b",
|
||||
"a b",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{ "", "", {}, QUERY, },
|
||||
{ "abc", "abc", {}, QUERY, },
|
||||
{ "1%41", "1A", {}, QUERY, },
|
||||
{ "1%41%42%43", "1ABC", {}, QUERY, },
|
||||
{ "%4a", "J", {}, QUERY, },
|
||||
{ "%6F", "o", {}, QUERY, },
|
||||
{ "%", "", UrlDecodingError.INVALID_HEX, QUERY, },
|
||||
{ "%a", "", UrlDecodingError.INVALID_HEX, QUERY, },
|
||||
{ "%1", "", UrlDecodingError.INVALID_HEX, QUERY, },
|
||||
{ "123%45%6", "", UrlDecodingError.INVALID_HEX, QUERY, },
|
||||
{ "%zzzzz", "", UrlDecodingError.INVALID_HEX, QUERY, },
|
||||
{ "a+b", "a b", {}, QUERY, },
|
||||
{ "a%20b", "a b", {}, QUERY, },
|
||||
};
|
||||
|
||||
fn void test_decoding_with_error()
|
||||
fn void test_decoding_with_error() => @pool()
|
||||
{
|
||||
String! actual;
|
||||
@pool() {
|
||||
foreach (test: decode_with_error_tests)
|
||||
foreach (test: decode_with_error_tests)
|
||||
{
|
||||
String! actual = url::temp_decode(test.in, test.mode);
|
||||
if (catch excuse = actual)
|
||||
{
|
||||
actual = url::temp_decode(test.in, test.mode);
|
||||
if (catch excuse = actual)
|
||||
{
|
||||
assert(excuse == test.err, "unescape(%s, %s); "
|
||||
assert(excuse == test.err, "unescape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, excuse, test.err);
|
||||
continue;
|
||||
}
|
||||
assert(actual == test.out, "unescape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.out);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
assert(actual == test.out, "unescape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.out);
|
||||
}
|
||||
}
|
||||
|
||||
EncodeTest[?] encode_tests @local = {
|
||||
{
|
||||
"",
|
||||
"",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
{ "", "", {}, PATH, },
|
||||
{ "abc", "abc", {}, PATH, },
|
||||
{ "abc+def", "abc+def", {}, PATH, },
|
||||
{ "a/b", "a/b", {}, PATH, },
|
||||
{ "one two", "one%20two", {}, PATH, },
|
||||
{ "10%", "10%25", {}, PATH, },
|
||||
{ "", "", {}, QUERY, },
|
||||
{ "abc", "abc", {}, QUERY, },
|
||||
{ "one two", "one+two", {}, QUERY, },
|
||||
{ "10%", "10%25", {}, QUERY, },
|
||||
{ " ?&=#+%!<>#\"{}|\\^[]`☺\t:/@$'()*,;",
|
||||
"+%3F%26%3D%23%2B%25%21%3C%3E%23%22%7B%7D%7C%5C%5E%5B%5D%60%E2%98%BA%09%3A%2F%40%24%27%28%29%2A%2C%3B",
|
||||
{}, QUERY,
|
||||
},
|
||||
{
|
||||
"abc",
|
||||
"abc",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
},
|
||||
{
|
||||
"abc+def",
|
||||
"abc+def",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
},
|
||||
{
|
||||
"a/b",
|
||||
"a/b",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
},
|
||||
{
|
||||
"one two",
|
||||
"one%20two",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
},
|
||||
{
|
||||
"10%",
|
||||
"10%25",
|
||||
anyfault{},
|
||||
UrlEncodingMode.PATH,
|
||||
},
|
||||
{
|
||||
"",
|
||||
"",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"abc",
|
||||
"abc",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"one two",
|
||||
"one+two",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
"10%",
|
||||
"10%25",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
{
|
||||
" ?&=#+%!<>#\"{}|\\^[]`☺\t:/@$'()*,;",
|
||||
"+%3F%26%3D%23%2B%25%21%3C%3E%23%22%7B%7D%7C%5C%5E%5B%5D%60%E2%98%BA%09%3A%2F%40%24%27%28%29%2A%2C%3B",
|
||||
anyfault{},
|
||||
UrlEncodingMode.QUERY,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
fn void test_percent_encode_and_decode()
|
||||
fn void test_percent_encode_and_decode() => @pool()
|
||||
{
|
||||
String actual;
|
||||
@pool() {
|
||||
foreach (test: encode_tests)
|
||||
{
|
||||
actual = url::temp_encode(test.in, test.mode);
|
||||
assert(actual == test.out, "escape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.out);
|
||||
foreach (test: encode_tests)
|
||||
{
|
||||
String actual = url::temp_encode(test.in, test.mode);
|
||||
assert(actual == test.out, "escape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.out);
|
||||
|
||||
actual = url::temp_decode(test.out, test.mode)!!;
|
||||
assert(actual == test.in, "unescape(%s, %s); "
|
||||
actual = url::temp_decode(test.out, test.mode)!!;
|
||||
assert(actual == test.in, "unescape(%s, %s); "
|
||||
"got: %s, want: %s", test.out, test.mode, actual, test.in);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
struct ShouldEncodeTest
|
||||
@@ -206,60 +82,59 @@ struct ShouldEncodeTest
|
||||
}
|
||||
|
||||
ShouldEncodeTest[?] should_encode_tests = {
|
||||
{'a', UrlEncodingMode.PATH, false},
|
||||
{'a', UrlEncodingMode.USERPASS, false},
|
||||
{'a', UrlEncodingMode.QUERY, false},
|
||||
{'a', UrlEncodingMode.FRAGMENT, false},
|
||||
{'a', UrlEncodingMode.HOST, false},
|
||||
{'z', UrlEncodingMode.PATH, false},
|
||||
{'A', UrlEncodingMode.PATH, false},
|
||||
{'Z', UrlEncodingMode.PATH, false},
|
||||
{'0', UrlEncodingMode.PATH, false},
|
||||
{'9', UrlEncodingMode.PATH, false},
|
||||
{'-', UrlEncodingMode.PATH, false},
|
||||
{'-', UrlEncodingMode.USERPASS, false},
|
||||
{'-', UrlEncodingMode.QUERY, false},
|
||||
{'-', UrlEncodingMode.FRAGMENT, false},
|
||||
{'.', UrlEncodingMode.PATH, false},
|
||||
{'_', UrlEncodingMode.PATH, false},
|
||||
{'~', UrlEncodingMode.PATH, false},
|
||||
{'a', PATH, false},
|
||||
{'a', USERPASS, false},
|
||||
{'a', QUERY, false},
|
||||
{'a', FRAGMENT, false},
|
||||
{'a', HOST, false},
|
||||
{'z', PATH, false},
|
||||
{'A', PATH, false},
|
||||
{'Z', PATH, false},
|
||||
{'0', PATH, false},
|
||||
{'9', PATH, false},
|
||||
{'-', PATH, false},
|
||||
{'-', USERPASS, false},
|
||||
{'-', QUERY, false},
|
||||
{'-', FRAGMENT, false},
|
||||
{'.', PATH, false},
|
||||
{'_', PATH, false},
|
||||
{'~', PATH, false},
|
||||
|
||||
{'/', UrlEncodingMode.USERPASS, true},
|
||||
{'?', UrlEncodingMode.USERPASS, true},
|
||||
{'@', UrlEncodingMode.USERPASS, true},
|
||||
{'$', UrlEncodingMode.USERPASS, false},
|
||||
{'&', UrlEncodingMode.USERPASS, false},
|
||||
{'+', UrlEncodingMode.USERPASS, false},
|
||||
{',', UrlEncodingMode.USERPASS, false},
|
||||
{';', UrlEncodingMode.USERPASS, false},
|
||||
{'=', UrlEncodingMode.USERPASS, false},
|
||||
{'/', USERPASS, true},
|
||||
{'?', USERPASS, true},
|
||||
{'@', USERPASS, true},
|
||||
{'$', USERPASS, false},
|
||||
{'&', USERPASS, false},
|
||||
{'+', USERPASS, false},
|
||||
{',', USERPASS, false},
|
||||
{';', USERPASS, false},
|
||||
{'=', USERPASS, false},
|
||||
|
||||
{'!', UrlEncodingMode.HOST, false},
|
||||
{'$', UrlEncodingMode.HOST, false},
|
||||
{'&', UrlEncodingMode.HOST, false},
|
||||
{'\'', UrlEncodingMode.HOST, false},
|
||||
{'(', UrlEncodingMode.HOST, false},
|
||||
{')', UrlEncodingMode.HOST, false},
|
||||
{'*', UrlEncodingMode.HOST, false},
|
||||
{'+', UrlEncodingMode.HOST, false},
|
||||
{',', UrlEncodingMode.HOST, false},
|
||||
{';', UrlEncodingMode.HOST, false},
|
||||
{'=', UrlEncodingMode.HOST, false},
|
||||
{'0', UrlEncodingMode.HOST, false},
|
||||
{'9', UrlEncodingMode.HOST, false},
|
||||
{'A', UrlEncodingMode.HOST, false},
|
||||
{'z', UrlEncodingMode.HOST, false},
|
||||
{'_', UrlEncodingMode.HOST, false},
|
||||
{'-', UrlEncodingMode.HOST, false},
|
||||
{'.', UrlEncodingMode.HOST, false},
|
||||
{'!', HOST, false},
|
||||
{'$', HOST, false},
|
||||
{'&', HOST, false},
|
||||
{'\'',HOST, false},
|
||||
{'(', HOST, false},
|
||||
{')', HOST, false},
|
||||
{'*', HOST, false},
|
||||
{'+', HOST, false},
|
||||
{',', HOST, false},
|
||||
{';', HOST, false},
|
||||
{'=', HOST, false},
|
||||
{'0', HOST, false},
|
||||
{'9', HOST, false},
|
||||
{'A', HOST, false},
|
||||
{'z', HOST, false},
|
||||
{'_', HOST, false},
|
||||
{'-', HOST, false},
|
||||
{'.', HOST, false},
|
||||
};
|
||||
|
||||
fn void test_should_encode()
|
||||
{
|
||||
bool actual;
|
||||
foreach (test: should_encode_tests)
|
||||
foreach (test : should_encode_tests)
|
||||
{
|
||||
actual = url::should_encode(test.in, test.mode);
|
||||
bool actual = url::should_encode(test.in, test.mode);
|
||||
assert(actual == test.escape, "should_encode(%c, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.escape);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user