mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Deprecate old void! @benchmark and @test functions.
This commit is contained in:
@@ -14,7 +14,7 @@ bitstruct Bar : char[13]
|
||||
bool gh : 25;
|
||||
}
|
||||
|
||||
fn void! test_bitops() @test
|
||||
fn void test_bitops() @test
|
||||
{
|
||||
Foo f1 = { true, true };
|
||||
Foo f2 = { true, false };
|
||||
|
||||
@@ -14,7 +14,7 @@ bitstruct Bar : char[13]
|
||||
bool gh;
|
||||
}
|
||||
|
||||
fn void! test_bitops() @test
|
||||
fn void test_bitops() @test
|
||||
{
|
||||
Foo f1 = { true, true };
|
||||
Foo f2 = { true, false };
|
||||
@@ -42,7 +42,7 @@ fn void! test_bitops() @test
|
||||
assert(b3.z == true && b3.w == false && b3.gh == true);
|
||||
}
|
||||
|
||||
fn void! test_bitops_const() @test
|
||||
fn void test_bitops_const() @test
|
||||
{
|
||||
const Foo F1 = { true, true };
|
||||
const Foo F2 = { true, false };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module ct_slice @test;
|
||||
|
||||
fn void! slice_bytes()
|
||||
fn void slice_bytes()
|
||||
{
|
||||
char[4] $a = x'aabbccdd';
|
||||
var $b = $a[1..2];
|
||||
@@ -9,7 +9,7 @@ fn void! slice_bytes()
|
||||
assert(y == char[2] { 187, 204 });
|
||||
}
|
||||
|
||||
fn void! slice_string()
|
||||
fn void slice_string()
|
||||
{
|
||||
String $a = "abcd";
|
||||
assert($a == "abcd");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fn void! vector_inc_dec() @test
|
||||
fn void vector_inc_dec() @test
|
||||
{
|
||||
int[<3>] x;
|
||||
int[<3>] y;
|
||||
@@ -13,7 +13,7 @@ fn void! vector_inc_dec() @test
|
||||
assert(g == { 1, 1, 0 });
|
||||
}
|
||||
|
||||
fn void! int_inc_dec() @test
|
||||
fn void int_inc_dec() @test
|
||||
{
|
||||
int x;
|
||||
assert(x++ == 0);
|
||||
@@ -23,7 +23,7 @@ fn void! int_inc_dec() @test
|
||||
assert(--x == 0);
|
||||
}
|
||||
|
||||
fn void! float_inc_dec() @test
|
||||
fn void float_inc_dec() @test
|
||||
{
|
||||
double x;
|
||||
assert(x++ == 0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fn void! int_min() @test
|
||||
fn void int_min() @test
|
||||
{
|
||||
assert(int.min == -2147483648);
|
||||
assert((float)int.min == -2147483648.0f);
|
||||
|
||||
@@ -8,7 +8,7 @@ fn void test_swizzle()
|
||||
assert($$swizzle2(a, b, 0, 1, 4, 6, 2) == int[<5>] { 1, 2, 100, 10000, 3 });
|
||||
}
|
||||
|
||||
fn void! swizzle_builtin()
|
||||
fn void swizzle_builtin()
|
||||
{
|
||||
int[<4>] abc = { 1, 2, 3, 4 };
|
||||
assert(abc.rb == { 1, 3 });
|
||||
|
||||
@@ -5,7 +5,7 @@ fn bool! get_bool()
|
||||
return true;
|
||||
}
|
||||
|
||||
fn void! bool_chain_unwrap() @test
|
||||
fn void bool_chain_unwrap() @test
|
||||
{
|
||||
bool b;
|
||||
if (try v = get_bool() && b)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import std::math;
|
||||
|
||||
fn void! vector_method_reduce() @test
|
||||
fn void vector_method_reduce() @test
|
||||
{
|
||||
float[<3>] x = { 1, 2.0, 4.0 };
|
||||
int[<*>] y = { -23, 1, 4 };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import std::io;
|
||||
|
||||
fn void! test_int_mod() @test
|
||||
fn void test_int_mod() @test
|
||||
{
|
||||
int[<2>] y = { 10, 99 };
|
||||
int[<2>] z = { 3, 5 };
|
||||
@@ -10,7 +10,7 @@ fn void! test_int_mod() @test
|
||||
assert(int[<2>]{ 10, 99 } / int[<2>]{ 3, 5 } == { 3, 19 });
|
||||
}
|
||||
|
||||
fn void! test_conv() @test
|
||||
fn void test_conv() @test
|
||||
{
|
||||
float[<4>] y = { 1, 2, 3, 4 };
|
||||
float[<4>] z = { 0, 2, 2, -100 };
|
||||
@@ -35,7 +35,7 @@ fn void! test_conv() @test
|
||||
assert(b == { true, false });
|
||||
}
|
||||
|
||||
fn void! testf() @test
|
||||
fn void testf() @test
|
||||
{
|
||||
float[<4>] x = { 4, 0, -1, 33 };
|
||||
assert({ true, false, true, true} == (bool[<4>])x);
|
||||
@@ -63,7 +63,7 @@ fn void! testf() @test
|
||||
assert(ww == { -1, 0, -1, -1 });
|
||||
}
|
||||
|
||||
fn void! testb() @test
|
||||
fn void testb() @test
|
||||
{
|
||||
bool[<4>] y = { true, false, true, true };
|
||||
bool[<4>] z = { false, false, true, true };
|
||||
@@ -81,7 +81,7 @@ fn void! testb() @test
|
||||
assert(ww == { -1, 0, 0, 0 });
|
||||
}
|
||||
|
||||
fn void! testi() @test
|
||||
fn void testi() @test
|
||||
{
|
||||
int[<4>] x = { 4, 0, -1, 33 };
|
||||
assert({ true, false, true, true} == (bool[<4>])x);
|
||||
|
||||
@@ -5,7 +5,7 @@ import std::atomic;
|
||||
uint a;
|
||||
float fa;
|
||||
|
||||
fn void! add() @test
|
||||
fn void add() @test
|
||||
{
|
||||
Thread[100] ts;
|
||||
a = 0;
|
||||
@@ -33,16 +33,16 @@ fn void! add() @test
|
||||
thread::sleep_ms(5);
|
||||
atomic::fetch_add(&a, 5);
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(a == ts.len * 10 * 5, "Threads returned %d, expected %d", a, ts.len * 10 * 5);
|
||||
}
|
||||
|
||||
fn void! sub() @test
|
||||
fn void sub() @test
|
||||
{
|
||||
Thread[100] ts;
|
||||
a = ts.len * 10 * 5;
|
||||
@@ -70,16 +70,16 @@ fn void! sub() @test
|
||||
thread::sleep_ms(5);
|
||||
atomic::fetch_sub(&a, 5);
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(a == 0, "Threads returned %d, expected %d", a, 0);
|
||||
}
|
||||
|
||||
fn void! div() @test
|
||||
fn void div() @test
|
||||
{
|
||||
Thread[8] ts;
|
||||
a = 8 * 8 * 8 * 8 * 8 * 8 * 8 * 8 * 8;
|
||||
@@ -89,16 +89,16 @@ fn void! div() @test
|
||||
thread::sleep_ms(5);
|
||||
atomic::fetch_div(&a, 8);
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(a == 8, "Threads returned %d, expected %d", a, 8);
|
||||
}
|
||||
|
||||
fn void! max() @test
|
||||
fn void max() @test
|
||||
{
|
||||
Thread[100] ts;
|
||||
a = 0;
|
||||
@@ -125,16 +125,16 @@ fn void! max() @test
|
||||
atomic::fetch_max(&a, la);
|
||||
la++;
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(a == 5, "Threads returned %d, expected %d", a, 5);
|
||||
}
|
||||
|
||||
fn void! min() @test
|
||||
fn void min() @test
|
||||
{
|
||||
Thread[100] ts;
|
||||
a = 10;
|
||||
@@ -161,16 +161,16 @@ fn void! min() @test
|
||||
atomic::fetch_min(&a, la);
|
||||
la--;
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(a == 0, "Threads returned %d, expected %d", a, 0);
|
||||
}
|
||||
|
||||
fn void! fadd() @test
|
||||
fn void fadd() @test
|
||||
{
|
||||
Thread[100] ts;
|
||||
fa = 0;
|
||||
@@ -198,16 +198,16 @@ fn void! fadd() @test
|
||||
thread::sleep_ms(5);
|
||||
atomic::fetch_add(&fa, 0.5f);
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(fa == ts.len * 10 * 0.5, "Threads returned %f, expected %f", fa, ts.len * 10 * 0.5);
|
||||
}
|
||||
|
||||
fn void! fsub() @test
|
||||
fn void fsub() @test
|
||||
{
|
||||
Thread[100] ts;
|
||||
fa = ts.len * 10 * 0.5;
|
||||
@@ -235,11 +235,11 @@ fn void! fsub() @test
|
||||
thread::sleep_ms(5);
|
||||
atomic::fetch_sub(&fa, 0.5f);
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(fa == 0, "Threads returned %f, expected %f", fa, 0);
|
||||
}
|
||||
@@ -7,7 +7,7 @@ def AtomicFloat = Atomic(<float>);
|
||||
AtomicUint a;
|
||||
AtomicFloat fa;
|
||||
|
||||
fn void! add() @test
|
||||
fn void add() @test
|
||||
{
|
||||
Thread[100] ts;
|
||||
a.store(0);
|
||||
@@ -35,16 +35,16 @@ fn void! add() @test
|
||||
thread::sleep_ms(5);
|
||||
a.add(5);
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(a.load() == ts.len * 10 * 5, "Threads returned %d, expected %d", a.load(), ts.len * 10 * 5);
|
||||
}
|
||||
|
||||
fn void! sub() @test
|
||||
fn void sub() @test
|
||||
{
|
||||
Thread[100] ts;
|
||||
a.store(ts.len * 10 * 5);
|
||||
@@ -72,16 +72,16 @@ fn void! sub() @test
|
||||
thread::sleep_ms(5);
|
||||
a.sub(5);
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(a.load() == 0, "Threads returned %d, expected %d", a.load(), 0);
|
||||
}
|
||||
|
||||
fn void! fadd() @test
|
||||
fn void fadd() @test
|
||||
{
|
||||
Thread[100] ts;
|
||||
fa.store(0);
|
||||
@@ -109,16 +109,16 @@ fn void! fadd() @test
|
||||
thread::sleep_ms(5);
|
||||
fa.add(0.5);
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(fa.load() == ts.len * 10 * 0.5, "Threads returned %f, expected %f", fa.load(), ts.len * 10 * 0.5);
|
||||
}
|
||||
|
||||
fn void! fsub() @test
|
||||
fn void fsub() @test
|
||||
{
|
||||
Thread[100] ts;
|
||||
fa.store(ts.len * 10 * 0.5);
|
||||
@@ -146,11 +146,11 @@ fn void! fsub() @test
|
||||
thread::sleep_ms(5);
|
||||
fa.sub(0.5);
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(fa.load() == 0, "Threads returned %f, expected %f", fa.load(), 0);
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -10,7 +10,7 @@ enum FooEnum
|
||||
|
||||
def FooEnumMap = EnumMap(<FooEnum, uint>);
|
||||
|
||||
fn void! enums()
|
||||
fn void enums()
|
||||
{
|
||||
FooEnumMap nm;
|
||||
nm.set(ONE, 1);
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -26,42 +26,42 @@ fn void assert_utf8_is_error(String in)
|
||||
assert(@catch(conv::utf8_to_char32(in.ptr, &len)), "Expected error");
|
||||
}
|
||||
|
||||
fn void! test_char32_ut8_boundary() @test
|
||||
fn void test_char32_ut8_boundary() @test
|
||||
{
|
||||
// First sequence per len
|
||||
comparison_helper_32_to_8(0x00000000, { 0 })!;
|
||||
comparison_helper_32_to_8(0x00000080, { 0xc2, 0x80 })!;
|
||||
comparison_helper_32_to_8(0x00000800, { 0xe0, 0xa0, 0x80 })!;
|
||||
comparison_helper_32_to_8(0x00010000, { 0xf0, 0x90, 0x80, 0x80 })!;
|
||||
comparison_helper_32_to_8(0x00000000, { 0 })!!;
|
||||
comparison_helper_32_to_8(0x00000080, { 0xc2, 0x80 })!!;
|
||||
comparison_helper_32_to_8(0x00000800, { 0xe0, 0xa0, 0x80 })!!;
|
||||
comparison_helper_32_to_8(0x00010000, { 0xf0, 0x90, 0x80, 0x80 })!!;
|
||||
assert(@catch(comparison_helper_32_to_8(0x10ffff + 1, { 0 })), "Expected error");
|
||||
// Last seq per len
|
||||
comparison_helper_32_to_8(0x0000007f, { 0x7f })!;
|
||||
comparison_helper_32_to_8(0x000007ff, { 0xdf, 0xbf })!;
|
||||
comparison_helper_32_to_8(0x0000ffff, { 0xef, 0xbf, 0xbf })!;
|
||||
comparison_helper_32_to_8(0x0010ffff, { 0xf4, 0x8f, 0xbf, 0xbf })!;
|
||||
comparison_helper_32_to_8(0x0000007f, { 0x7f })!!;
|
||||
comparison_helper_32_to_8(0x000007ff, { 0xdf, 0xbf })!!;
|
||||
comparison_helper_32_to_8(0x0000ffff, { 0xef, 0xbf, 0xbf })!!;
|
||||
comparison_helper_32_to_8(0x0010ffff, { 0xf4, 0x8f, 0xbf, 0xbf })!!;
|
||||
// Other boundaries
|
||||
comparison_helper_32_to_8(0x0000d7ff, { 0xed, 0x9f, 0xbf})!;
|
||||
comparison_helper_32_to_8(0x0000e000, { 0xee, 0x80, 0x80 })!;
|
||||
comparison_helper_32_to_8(0x0000fffd, { 0xef, 0xbf, 0xbd })!;
|
||||
comparison_helper_32_to_8(0x0000d7ff, { 0xed, 0x9f, 0xbf})!!;
|
||||
comparison_helper_32_to_8(0x0000e000, { 0xee, 0x80, 0x80 })!!;
|
||||
comparison_helper_32_to_8(0x0000fffd, { 0xef, 0xbf, 0xbd })!!;
|
||||
|
||||
}
|
||||
|
||||
fn void! test_utf8_to_char32_boundary() @test
|
||||
fn void test_utf8_to_char32_boundary() @test
|
||||
{
|
||||
// First sequence per len
|
||||
comparison_helper_8_to_32("\0", 0x0 )!;
|
||||
comparison_helper_8_to_32({ 0xc2, 0x80 }, 0x80)!;
|
||||
comparison_helper_8_to_32({ 0xe0, 0xa0, 0x80 }, 0x800 )!;
|
||||
comparison_helper_8_to_32({ 0xf0, 0x90, 0x80, 0x80 }, 0x10000)!;
|
||||
comparison_helper_8_to_32("\0", 0x0 )!!;
|
||||
comparison_helper_8_to_32({ 0xc2, 0x80 }, 0x80)!!;
|
||||
comparison_helper_8_to_32({ 0xe0, 0xa0, 0x80 }, 0x800 )!!;
|
||||
comparison_helper_8_to_32({ 0xf0, 0x90, 0x80, 0x80 }, 0x10000)!!;
|
||||
// Last seq per len
|
||||
comparison_helper_8_to_32({ 0x7f }, 0x7f)!;
|
||||
comparison_helper_8_to_32({ 0xdf, 0xbf }, 0x7ff )!;
|
||||
comparison_helper_8_to_32({ 0xef, 0xbf, 0xbf }, 0xffff)!;
|
||||
comparison_helper_8_to_32({ 0xf4, 0x8f, 0xbf, 0xbf }, 0x10ffff)!;
|
||||
comparison_helper_8_to_32({ 0x7f }, 0x7f)!!;
|
||||
comparison_helper_8_to_32({ 0xdf, 0xbf }, 0x7ff )!!;
|
||||
comparison_helper_8_to_32({ 0xef, 0xbf, 0xbf }, 0xffff)!!;
|
||||
comparison_helper_8_to_32({ 0xf4, 0x8f, 0xbf, 0xbf }, 0x10ffff)!!;
|
||||
// Other boundaries
|
||||
comparison_helper_8_to_32({ 0xed, 0x9f, 0xbf }, 0xd7ff)!;
|
||||
comparison_helper_8_to_32({ 0xee, 0x80, 0x80 }, 0xe000)!;
|
||||
comparison_helper_8_to_32({ 0xef, 0xbf, 0xbd }, 0xfffd)!;
|
||||
comparison_helper_8_to_32({ 0xed, 0x9f, 0xbf }, 0xd7ff)!!;
|
||||
comparison_helper_8_to_32({ 0xee, 0x80, 0x80 }, 0xe000)!!;
|
||||
comparison_helper_8_to_32({ 0xef, 0xbf, 0xbd }, 0xfffd)!!;
|
||||
|
||||
assert_utf8_is_error({ 0x80 });
|
||||
assert_utf8_is_error({ 0xbf });
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
module arraytests @test;
|
||||
|
||||
fn void! find()
|
||||
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(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()
|
||||
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(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()
|
||||
fn void concat()
|
||||
{
|
||||
int[3] a = { 1, 2, 3 };
|
||||
(void)array::concat_new(a, a);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module std::core::bitorder @test;
|
||||
|
||||
fn void! test_read()
|
||||
fn void test_read()
|
||||
{
|
||||
char[*] bytes = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
|
||||
@@ -26,7 +26,7 @@ fn void! test_read()
|
||||
assert(bitorder::read(bytes[..], ULongLE) == 0x0807060504030201);
|
||||
}
|
||||
|
||||
fn void! test_write()
|
||||
fn void test_write()
|
||||
{
|
||||
char[*] bytes = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
char[8] buf;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
module std::core::builtins @test;
|
||||
|
||||
fn void! test_anycast()
|
||||
fn void test_anycast()
|
||||
{
|
||||
int a;
|
||||
any b = &a;
|
||||
assert(anycast(b, int)! == &a);
|
||||
assert(anycast(b, int)!! == &a);
|
||||
assert(@catch(anycast(b, double)) == CastResult.TYPE_MISMATCH);
|
||||
}
|
||||
|
||||
fn void! test_bitcast()
|
||||
fn void test_bitcast()
|
||||
{
|
||||
int a = 123;
|
||||
float z = bitcast(a, float);
|
||||
@@ -21,10 +21,10 @@ enum Tester
|
||||
DEF,
|
||||
}
|
||||
|
||||
fn void! test_enum_by_name()
|
||||
fn void test_enum_by_name()
|
||||
{
|
||||
assert(enum_by_name(Tester, "ABC")! == Tester.ABC);
|
||||
assert(enum_by_name(Tester, "DEF")! == Tester.DEF);
|
||||
assert(enum_by_name(Tester, "ABC")!! == Tester.ABC);
|
||||
assert(enum_by_name(Tester, "DEF")!! == Tester.DEF);
|
||||
assert(@catch(enum_by_name(Tester, "GHI")) == SearchResult.MISSING);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module std::core::runtime_test;
|
||||
import std::sort;
|
||||
|
||||
fn void! cmp_unit() @test
|
||||
fn void cmp_unit() @test
|
||||
{
|
||||
TestUnit[] list = {
|
||||
{ .name = "http::url_test::url_query" },
|
||||
|
||||
@@ -123,11 +123,11 @@ fn void test_split_skip_empty()
|
||||
assert(strings[1] == "b||c|");
|
||||
}
|
||||
|
||||
fn void! test_split_to_buffer_skip_empty()
|
||||
fn void test_split_to_buffer_skip_empty()
|
||||
{
|
||||
String[10] buffer;
|
||||
String test = "abc|b||c|";
|
||||
String[] strings = test.split_to_buffer("|", &buffer, skip_empty: true)!;
|
||||
String[] strings = test.split_to_buffer("|", &buffer, skip_empty: true)!!;
|
||||
assert(strings.len == 3);
|
||||
assert(strings[0] == "abc");
|
||||
assert(strings[1] == "b");
|
||||
@@ -138,11 +138,11 @@ fn void! test_split_to_buffer_skip_empty()
|
||||
assert(strings[1] == "b||c|");
|
||||
}
|
||||
|
||||
fn void! test_split_to_buffer()
|
||||
fn void test_split_to_buffer()
|
||||
{
|
||||
String[5] b;
|
||||
String test = "abc|b||c|";
|
||||
String[] strings = test.split_to_buffer("|", &b)!;
|
||||
String[] strings = test.split_to_buffer("|", &b)!!;
|
||||
assert(strings.len == 5);
|
||||
assert(strings[0] == "abc");
|
||||
assert(strings[1] == "b");
|
||||
@@ -157,46 +157,46 @@ fn void! test_split_to_buffer()
|
||||
assert(strings[1] == "b||c|");
|
||||
}
|
||||
|
||||
fn void! test_index_of()
|
||||
fn void test_index_of()
|
||||
{
|
||||
String test = "hello world hello";
|
||||
assert(test.index_of("o")! == 4);
|
||||
assert(test.index_of("ll")! == 2);
|
||||
assert(test.index_of(" hello")! == 11);
|
||||
assert(test.index_of("o")!! == 4);
|
||||
assert(test.index_of("ll")!! == 2);
|
||||
assert(test.index_of(" hello")!! == 11);
|
||||
assert(@catch(test.index_of("wi")));
|
||||
}
|
||||
|
||||
fn void! test_rindex_of()
|
||||
fn void test_rindex_of()
|
||||
{
|
||||
String test = "hello world hello";
|
||||
assert(test.rindex_of("o")! == 16);
|
||||
assert(test.rindex_of("ll")! == 14);
|
||||
assert(test.rindex_of("he")! == 12);
|
||||
assert(test.rindex_of("world")! == 6);
|
||||
assert(test.rindex_of("hello ")! == 0);
|
||||
assert(test.rindex_of("o")!! == 16);
|
||||
assert(test.rindex_of("ll")!! == 14);
|
||||
assert(test.rindex_of("he")!! == 12);
|
||||
assert(test.rindex_of("world")!! == 6);
|
||||
assert(test.rindex_of("hello ")!! == 0);
|
||||
assert(@catch(test.rindex_of("wi")));
|
||||
}
|
||||
|
||||
fn void! test_index_of_char()
|
||||
fn void test_index_of_char()
|
||||
{
|
||||
String test = "hello world hello";
|
||||
assert(test.index_of_char('o')! == 4);
|
||||
assert(test.index_of_char('l')! == 2);
|
||||
assert(test.index_of_char('h')! == 0);
|
||||
assert(test.index_of_char('o')!! == 4);
|
||||
assert(test.index_of_char('l')!! == 2);
|
||||
assert(test.index_of_char('h')!! == 0);
|
||||
assert(@catch(test.index_of_char('x')));
|
||||
}
|
||||
|
||||
fn void! test_rindex_of_char()
|
||||
fn void test_rindex_of_char()
|
||||
{
|
||||
String test = "hello world hello";
|
||||
assert(test.rindex_of_char('o')! == 16);
|
||||
assert(test.rindex_of_char('l')! == 15);
|
||||
assert(test.rindex_of_char('h')! == 12);
|
||||
assert(test.rindex_of_char('o')!! == 16);
|
||||
assert(test.rindex_of_char('l')!! == 15);
|
||||
assert(test.rindex_of_char('h')!! == 12);
|
||||
assert(@catch(test.index_of_char('x')));
|
||||
}
|
||||
|
||||
fn void! test_hex_conversion()
|
||||
fn void test_hex_conversion()
|
||||
{
|
||||
assert("0x123aCd".to_long()! == 0x123acd);
|
||||
assert("123acD".to_long(16)! == 0x123acd);
|
||||
assert("0x123aCd".to_long()!! == 0x123acd);
|
||||
assert("123acD".to_long(16)!! == 0x123acd);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ fn void test_at_start()
|
||||
{
|
||||
String test = "abcd";
|
||||
StringIterator iterator = test.iterator();
|
||||
assert(iterator.get()! == 'a');
|
||||
assert(iterator.peek()! == 'a');
|
||||
iterator.next()!;
|
||||
assert(iterator.next()! == 'b');
|
||||
assert(iterator.get()!! == 'a');
|
||||
assert(iterator.peek()!! == 'a');
|
||||
iterator.next()!!;
|
||||
assert(iterator.next()!! == 'b');
|
||||
assert(iterator.has_next());
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ fn void test_general()
|
||||
{
|
||||
String test = "åƦs1";
|
||||
StringIterator iterator = test.iterator();
|
||||
assert(iterator.get()! == 'å');
|
||||
iterator.next()!;
|
||||
assert(iterator.peek()! == 'Ʀ');
|
||||
assert(iterator.next()! == 'Ʀ');
|
||||
assert(iterator.get()!! == 'å');
|
||||
iterator.next()!!;
|
||||
assert(iterator.peek()!! == 'Ʀ');
|
||||
assert(iterator.next()!! == 'Ʀ');
|
||||
iterator.reset();
|
||||
assert(iterator.current == 0);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ fn void test_end()
|
||||
String test = "åƦ";
|
||||
StringIterator iterator = test.iterator();
|
||||
assert(@ok(iterator.next()));
|
||||
assert(iterator.peek()! == 'Ʀ');
|
||||
assert(iterator.peek()!! == 'Ʀ');
|
||||
assert(@ok(iterator.next()));
|
||||
assert(@catch(iterator.next()));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import std::crypto;
|
||||
import std::io;
|
||||
|
||||
fn void! rc_crypt() @test
|
||||
fn void rc_crypt() @test
|
||||
{
|
||||
Rc4 rc;
|
||||
rc.init(&&x"63727970746969");
|
||||
|
||||
@@ -92,16 +92,16 @@ fn void decode_nopadding()
|
||||
decode_tests(hex_tests, &base32::HEX, base32::NO_PAD);
|
||||
}
|
||||
|
||||
fn void! base32_api()
|
||||
fn void base32_api()
|
||||
{
|
||||
@pool()
|
||||
{
|
||||
foreach (t : std_tests)
|
||||
{
|
||||
String got = base32::encode_temp(t.dec)!;
|
||||
String got = base32::encode_temp(t.dec)!!;
|
||||
assert(got == t.enc, "got: %s, want: %s", got, t.enc);
|
||||
|
||||
char[] got_chars = base32::decode_temp(t.enc)!;
|
||||
char[] got_chars = base32::decode_temp(t.enc)!!;
|
||||
assert(got_chars == t.dec, "got: %s, want: %s", got_chars, t.dec);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -71,9 +71,9 @@ fn void decode()
|
||||
};
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
usz n = base64::decode_len(tc.in.len, base64::DEFAULT_PAD)!;
|
||||
usz n = base64::decode_len(tc.in.len, base64::DEFAULT_PAD)!!;
|
||||
char[64] buf;
|
||||
char[] res = base64::decode_buffer(tc.in, buf[:n])!;
|
||||
char[] res = base64::decode_buffer(tc.in, buf[:n])!!;
|
||||
assert(res == tc.out);
|
||||
}
|
||||
}
|
||||
@@ -92,14 +92,14 @@ fn void decode_nopadding()
|
||||
};
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
usz n = base64::decode_len(tc.in.len, base64::NO_PAD)!;
|
||||
usz n = base64::decode_len(tc.in.len, base64::NO_PAD)!!;
|
||||
char[64] buf;
|
||||
char[] res = base64::decode_buffer(tc.in, buf[:n], base64::NO_PAD)!;
|
||||
char[] res = base64::decode_buffer(tc.in, buf[:n], base64::NO_PAD)!!;
|
||||
assert(res == tc.out);
|
||||
}
|
||||
}
|
||||
|
||||
fn void! urlencode() {
|
||||
fn void urlencode() {
|
||||
TestCase[] tcases = {
|
||||
{ x"14fb9c03d97e", "FPucA9l-"},
|
||||
};
|
||||
@@ -114,7 +114,7 @@ fn void! urlencode() {
|
||||
char[] res = base64::encode_buffer(t.in, buf[..], alphabet: &base64::URL);
|
||||
assert (res == t.out, "got: %s, want: %s", (String)res, (String)t.out);
|
||||
|
||||
res = base64::decode_buffer(t.out, buf[..], alphabet: &base64::URL)!;
|
||||
res = base64::decode_buffer(t.out, buf[..], alphabet: &base64::URL)!!;
|
||||
assert (res == t.in, "got: %s, want: %s", (String)res, (String)t.in);
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ TestCase[] tests = {
|
||||
{{0xe3, 0xa1}, "E3A1"},
|
||||
};
|
||||
|
||||
fn void! encode()
|
||||
fn void encode()
|
||||
{
|
||||
usz n;
|
||||
char[64] buf;
|
||||
@@ -33,17 +33,17 @@ fn void! encode()
|
||||
}
|
||||
}
|
||||
|
||||
fn void! decode()
|
||||
fn void decode()
|
||||
{
|
||||
usz n;
|
||||
char[64] buf;
|
||||
foreach (t : tests)
|
||||
{
|
||||
n = hex::decode_bytes(t.enc, buf[..])!;
|
||||
n = hex::decode_bytes(t.enc, buf[..])!!;
|
||||
assert(t.dec == buf[:n], "decode failed: got: %s, want: %s", buf[:n], t.dec);
|
||||
@pool()
|
||||
{
|
||||
assert(t.dec == hex::decode_temp(t.enc)!);
|
||||
assert(t.dec == hex::decode_temp(t.enc)!!);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,49 +3,49 @@ import std::collections::object;
|
||||
import std::io;
|
||||
import std::encoding::json;
|
||||
|
||||
fn void! simple_test()
|
||||
fn void simple_test()
|
||||
{
|
||||
ByteReader reader;
|
||||
reader.init(`{ "b": 123, "c": [ { "d": 66 }, null, "hello\tworld", false, { "id": "xyz" } ] }`);
|
||||
Object* o = json::parse(&reader)!;
|
||||
Object* o = json::parse(&reader)!!;
|
||||
defer o.free();
|
||||
assert(o.get_int("b")! == 123);
|
||||
assert(o.get("c").get_len()! == 5);
|
||||
assert(o.get("c").get_at(0).get_int("d")! == 66);
|
||||
assert(o.get("c").get_at(1).is_null()!);
|
||||
assert(o.get("c").get_string_at(2)! == "hello\tworld");
|
||||
assert(o.get("c").get_bool_at(3)! == false);
|
||||
assert(o.get("c").get_at(4).get_string("id")! == "xyz");
|
||||
assert(o.get_int("b")!! == 123);
|
||||
assert(o.get("c").get_len()!! == 5);
|
||||
assert(o.get("c").get_at(0).get_int("d")!! == 66);
|
||||
assert(o.get("c").get_at(1).is_null()!!);
|
||||
assert(o.get("c").get_string_at(2)!! == "hello\tworld");
|
||||
assert(o.get("c").get_bool_at(3)!! == false);
|
||||
assert(o.get("c").get_at(4).get_string("id")!! == "xyz");
|
||||
}
|
||||
|
||||
fn void! simple_test2()
|
||||
fn void simple_test2()
|
||||
{
|
||||
ByteReader reader;
|
||||
reader.init(`{"jsonrpc":"2.0","id":null,"method":"initialize"}`);
|
||||
Object* o = json::parse(&reader)!;
|
||||
Object* o = json::parse(&reader)!!;
|
||||
defer o.free();
|
||||
}
|
||||
|
||||
|
||||
fn void! test_string()
|
||||
fn void test_string()
|
||||
{
|
||||
Object* o = json::parse_string(`{"jsonrpc":"2","id":null,"method":"initialize"}`)!;
|
||||
Object* o = json::parse_string(`{"jsonrpc":"2","id":null,"method":"initialize"}`)!!;
|
||||
defer o.free();
|
||||
String s = string::tformat("%s", *o);
|
||||
Object* o2 = json::parse_string(s)!;
|
||||
Object* o2 = json::parse_string(s)!!;
|
||||
defer o2.free();
|
||||
String s2 = string::tformat("%s", *o2);
|
||||
assert(s2 == s, "Unexpectedly got %s and not %s", s2, s);
|
||||
}
|
||||
|
||||
fn void! test_temp_string()
|
||||
fn void test_temp_string()
|
||||
{
|
||||
@pool()
|
||||
{
|
||||
Object* o = json::temp_parse_string(`{"jsonrpc":"2","id":null,"method":"initialize"}`)!;
|
||||
Object* o = json::temp_parse_string(`{"jsonrpc":"2","id":null,"method":"initialize"}`)!!;
|
||||
defer o.free();
|
||||
String s = string::tformat("%s", *o);
|
||||
Object* o2 = json::temp_parse_string(s)!;
|
||||
Object* o2 = json::temp_parse_string(s)!!;
|
||||
defer o2.free();
|
||||
String s2 = string::tformat("%s", *o2);
|
||||
assert(s2 == s, "Unexpectedly got %s and not %s", s2, s);
|
||||
|
||||
@@ -1,249 +1,249 @@
|
||||
module std::io::bits @test;
|
||||
import std::io;
|
||||
|
||||
fn void! test_write_0b1() {
|
||||
fn void test_write_0b1() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0b11111111, 1)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0b11111111, 1)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"80"); // 0b1000 0000
|
||||
}
|
||||
|
||||
fn void! test_write_0b1111() {
|
||||
fn void test_write_0b1111() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0b11111111, 4)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0b11111111, 4)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"f0"); // 0b1111 0000
|
||||
}
|
||||
|
||||
fn void! test_write_0b1111_1111() {
|
||||
fn void test_write_0b1111_1111() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0b11111111, 8)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0b11111111, 8)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"ff");
|
||||
}
|
||||
|
||||
fn void! test_write_0b1000() {
|
||||
fn void test_write_0b1000() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0b0001000, 4)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0b0001000, 4)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"80"); // 0b1000 0000
|
||||
}
|
||||
|
||||
fn void! test_write_0b01000() {
|
||||
fn void test_write_0b01000() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0b0001000, 5)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0b0001000, 5)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"40"); // 0b0100 0000
|
||||
}
|
||||
|
||||
fn void! test_write_0b0001() {
|
||||
fn void test_write_0b0001() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0b0000001, 4)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0b0000001, 4)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"10"); // 0b0001 0000
|
||||
}
|
||||
|
||||
|
||||
fn void! test_write_0b0000_0001() {
|
||||
fn void test_write_0b0000_0001() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0b0000001, 8)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0b0000001, 8)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"01"); // 0b0000 0001
|
||||
}
|
||||
|
||||
fn void! test_write_10_bits() {
|
||||
fn void test_write_10_bits() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0x789, 10)!; // 01|11 1000 1001
|
||||
bw.flush()!;
|
||||
bw.write_bits(0x789, 10)!!; // 01|11 1000 1001
|
||||
bw.flush()!!;
|
||||
|
||||
// e 2 4 0
|
||||
assert(w.str_view() == x"e2 40"); // 0b1110 0010 0100 0000
|
||||
}
|
||||
|
||||
fn void! test_write_16_bits() {
|
||||
fn void test_write_16_bits() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0xfafb, 16)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0xfafb, 16)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"fa fb");
|
||||
}
|
||||
|
||||
fn void! test_write_24_bits() {
|
||||
fn void test_write_24_bits() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0xfafbfc, 24)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0xfafbfc, 24)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"fa fb fc");
|
||||
}
|
||||
|
||||
fn void! test_write_30_bits() {
|
||||
fn void test_write_30_bits() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0xf0f1f2f3, 30)!; // 11 | 110000111100011111001011110011
|
||||
bw.flush()!;
|
||||
bw.write_bits(0xf0f1f2f3, 30)!!; // 11 | 110000111100011111001011110011
|
||||
bw.flush()!!;
|
||||
// c 3 c 7 c b c c
|
||||
assert(w.str_view() == x"c3 c7 cb cc"); // 1100 0011 1100 0111 1100 1011 1100 1100
|
||||
}
|
||||
|
||||
fn void! test_write_32_bits() {
|
||||
fn void test_write_32_bits() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0xfafbfcfd, 32)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0xfafbfcfd, 32)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"fa fb fc fd");
|
||||
}
|
||||
|
||||
fn void! test_write_2_bits_multiple() {
|
||||
fn void test_write_2_bits_multiple() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0b11111111, 2)!;
|
||||
bw.write_bits(0b00000001, 2)!;
|
||||
bw.write_bits(0b11111111, 2)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0b11111111, 2)!!;
|
||||
bw.write_bits(0b00000001, 2)!!;
|
||||
bw.write_bits(0b11111111, 2)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"dc"); // 0b1101 1100
|
||||
}
|
||||
|
||||
fn void! test_write_10_bits_multiple() {
|
||||
fn void test_write_10_bits_multiple() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0x789, 10)!; // 01 | 11 1000 1001
|
||||
bw.write_bits(0xabc, 10)!; // 10 | 10 1011 1100
|
||||
bw.write_bits(0xdef, 10)!; // 11 | 01 1110 1111
|
||||
bw.flush()!;
|
||||
bw.write_bits(0x789, 10)!!; // 01 | 11 1000 1001
|
||||
bw.write_bits(0xabc, 10)!!; // 10 | 10 1011 1100
|
||||
bw.write_bits(0xdef, 10)!!; // 11 | 01 1110 1111
|
||||
bw.flush()!!;
|
||||
|
||||
// e 2 6 b c 7 b c
|
||||
assert(w.str_view() == x"e2 6b c7 bc"); // 0b1110 0010 0110 1011 1100 0111 1011 1100
|
||||
}
|
||||
|
||||
fn void! test_write_24_bits_multiple() {
|
||||
fn void test_write_24_bits_multiple() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0xfafbfc, 24)!;
|
||||
bw.write_bits(0xfdfeff, 24)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0xfafbfc, 24)!!;
|
||||
bw.write_bits(0xfdfeff, 24)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"fa fb fc fd fe ff");
|
||||
}
|
||||
|
||||
fn void! test_write_30_bits_multiple() {
|
||||
fn void test_write_30_bits_multiple() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0xf0f1f2f3, 30)!; // 11 | 110000111100011111001011110011
|
||||
bw.write_bits(0xfafbfcfd, 30)!; // 11 | 111010111110111111110011111101
|
||||
bw.flush()!;
|
||||
bw.write_bits(0xf0f1f2f3, 30)!!; // 11 | 110000111100011111001011110011
|
||||
bw.write_bits(0xfafbfcfd, 30)!!; // 11 | 111010111110111111110011111101
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"c3 c7 cb cf af bf cf d0");
|
||||
}
|
||||
|
||||
fn void! test_write_32_bits_multiple() {
|
||||
fn void test_write_32_bits_multiple() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0xf0f1f2f3, 32)!;
|
||||
bw.write_bits(0xfafbfcfd, 32)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0xf0f1f2f3, 32)!!;
|
||||
bw.write_bits(0xfafbfcfd, 32)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"f0 f1 f2 f3 fa fb fc fd");
|
||||
}
|
||||
|
||||
fn void! test_write_mixed_multiple() {
|
||||
fn void test_write_mixed_multiple() {
|
||||
ByteWriter w;
|
||||
w.temp_init();
|
||||
|
||||
BitWriter bw;
|
||||
bw.init(&w);
|
||||
|
||||
bw.write_bits(0xf0f1f2f3, 8)!;
|
||||
bw.write_bits(0xf0f1f2f3, 32)!;
|
||||
bw.write_bits(0xfafbfcfd, 30)!;
|
||||
bw.write_bits(0xf4f5f6f7, 10)!;
|
||||
bw.flush()!;
|
||||
bw.write_bits(0xf0f1f2f3, 8)!!;
|
||||
bw.write_bits(0xf0f1f2f3, 32)!!;
|
||||
bw.write_bits(0xfafbfcfd, 30)!!;
|
||||
bw.write_bits(0xf4f5f6f7, 10)!!;
|
||||
bw.flush()!!;
|
||||
|
||||
assert(w.str_view() == x"f3 f0 f1 f2 f3 eb ef f3 f6 f7");
|
||||
}
|
||||
@@ -2,7 +2,7 @@ module std::io @test;
|
||||
|
||||
const DATA = "Lorem ipsum blandit.";
|
||||
|
||||
fn void! readbuffer_large()
|
||||
fn void readbuffer_large()
|
||||
{
|
||||
ByteReader src;
|
||||
src.init(DATA);
|
||||
@@ -11,14 +11,14 @@ fn void! readbuffer_large()
|
||||
reader_buf.init(&src, buf[..]);
|
||||
|
||||
char[DATA.len] bytes;
|
||||
usz n = reader_buf.read(bytes[..])!;
|
||||
usz n = reader_buf.read(bytes[..])!!;
|
||||
|
||||
assert(n == DATA.len, "large read failed: got %d; want %d", n, DATA.len);
|
||||
String got = (String)bytes[..];
|
||||
assert(got == DATA, "large read failed: got %s; want %s", got, DATA);
|
||||
}
|
||||
|
||||
fn void! readbuffer()
|
||||
fn void readbuffer()
|
||||
{
|
||||
ByteReader src;
|
||||
src.init(DATA);
|
||||
@@ -29,14 +29,14 @@ fn void! readbuffer()
|
||||
ByteWriter bw;
|
||||
bw.temp_init();
|
||||
|
||||
usz n = io::copy_to(&reader_buf, &bw)!;
|
||||
usz n = io::copy_to(&reader_buf, &bw)!!;
|
||||
|
||||
assert(n == DATA.len, "got %d; want %d", n, DATA.len);
|
||||
String got = bw.str_view();
|
||||
assert(got == DATA, "got %s; want %s", got, DATA);
|
||||
}
|
||||
|
||||
fn void! writebuffer_large()
|
||||
fn void writebuffer_large()
|
||||
{
|
||||
ByteWriter out;
|
||||
out.temp_init();
|
||||
@@ -44,14 +44,14 @@ fn void! writebuffer_large()
|
||||
WriteBuffer write_buf;
|
||||
write_buf.init(&out, buf[..]);
|
||||
|
||||
usz n = write_buf.write(DATA)!;
|
||||
usz n = write_buf.write(DATA)!!;
|
||||
|
||||
assert(n == DATA.len, "large write failed: got %d; want %d", n, DATA.len);
|
||||
String got = out.str_view();
|
||||
assert(got == DATA, "large write failed: got %s; want %s", got, DATA);
|
||||
}
|
||||
|
||||
fn void! writebuffer()
|
||||
fn void writebuffer()
|
||||
{
|
||||
ByteReader br;
|
||||
br.init(DATA);
|
||||
@@ -61,14 +61,14 @@ fn void! writebuffer()
|
||||
WriteBuffer write_buf;
|
||||
write_buf.init(&out, buf[..]);
|
||||
|
||||
usz n = io::copy_to(&br, &write_buf)!;
|
||||
usz n = io::copy_to(&br, &write_buf)!!;
|
||||
|
||||
assert(n == DATA.len, "got %d; want %d", n, DATA.len);
|
||||
String got = out.str_view();
|
||||
assert(got == DATA, "got %s; want %s", got, DATA);
|
||||
}
|
||||
|
||||
fn void! writebuffer_write_byte()
|
||||
fn void writebuffer_write_byte()
|
||||
{
|
||||
ByteWriter out;
|
||||
out.temp_init();
|
||||
@@ -76,19 +76,19 @@ fn void! writebuffer_write_byte()
|
||||
WriteBuffer write_buf;
|
||||
write_buf.init(&out, buf[..]);
|
||||
|
||||
write_buf.write_byte('a')!;
|
||||
write_buf.write_byte('a')!!;
|
||||
assert(write_buf.str_view() == "a");
|
||||
assert(out.str_view() == "");
|
||||
|
||||
write_buf.write_byte('b')!;
|
||||
write_buf.write_byte('b')!!;
|
||||
assert(write_buf.str_view() == "ab");
|
||||
assert(out.str_view() == "");
|
||||
|
||||
write_buf.write_byte('c')!;
|
||||
write_buf.write_byte('c')!!;
|
||||
assert(write_buf.str_view() == "c");
|
||||
assert(out.str_view() == "ab");
|
||||
|
||||
write_buf.flush()!;
|
||||
write_buf.flush()!!;
|
||||
assert(write_buf.str_view() == "");
|
||||
assert(out.str_view() == "abc");
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
module std::io::bytebuffer @test;
|
||||
import std::io;
|
||||
|
||||
fn void! write_read()
|
||||
fn void write_read()
|
||||
{
|
||||
ByteBuffer buffer;
|
||||
buffer.new_init(0)!;
|
||||
buffer.new_init(0)!!;
|
||||
|
||||
buffer.write("hello")!;
|
||||
buffer.write("hello")!!;
|
||||
|
||||
char[8] bytes;
|
||||
usz n = buffer.read(bytes[..])!;
|
||||
usz n = buffer.read(bytes[..])!!;
|
||||
assert(n == 5);
|
||||
assert((String)bytes[:n] == "hello");
|
||||
|
||||
buffer.write("hello world")!;
|
||||
n = buffer.read(bytes[..])!;
|
||||
buffer.write("hello world")!!;
|
||||
n = buffer.read(bytes[..])!!;
|
||||
assert(n == bytes.len);
|
||||
assert((String)bytes[:n] == "hello wo");
|
||||
assert(buffer.read_idx == 1);
|
||||
|
||||
char c = buffer.read_byte()!;
|
||||
char c = buffer.read_byte()!!;
|
||||
assert(c == 'r');
|
||||
buffer.pushback_byte()!;
|
||||
buffer.pushback_byte()!!;
|
||||
|
||||
n = buffer.read(bytes[..])!;
|
||||
n = buffer.read(bytes[..])!!;
|
||||
assert((String)bytes[:n] == "rld");
|
||||
assert(buffer.read_idx == 1);
|
||||
}
|
||||
@@ -1,29 +1,29 @@
|
||||
module std::io @test;
|
||||
|
||||
fn void! bytestream()
|
||||
fn void bytestream()
|
||||
{
|
||||
ByteReader r;
|
||||
r.init("abc");
|
||||
InStream s = &r;
|
||||
assert(s.len() == 3);
|
||||
char[5] buffer;
|
||||
assert('a' == s.read_byte()!);
|
||||
s.pushback_byte()!;
|
||||
usz len = s.read(&buffer)!;
|
||||
assert('a' == s.read_byte()!!);
|
||||
s.pushback_byte()!!;
|
||||
usz len = s.read(&buffer)!!;
|
||||
assert((String)buffer[:len] == "abc");
|
||||
ByteWriter w;
|
||||
w.new_init();
|
||||
OutStream ws = &w;
|
||||
ws.write("helloworld")!;
|
||||
ws.write("helloworld")!!;
|
||||
assert(w.str_view() == "helloworld");
|
||||
s.seek(0, SET)!;
|
||||
io::copy_to(s, ws)!;
|
||||
s.seek(1, SET)!;
|
||||
s.write_to(ws)!;
|
||||
s.seek(0, SET)!!;
|
||||
io::copy_to(s, ws)!!;
|
||||
s.seek(1, SET)!!;
|
||||
s.write_to(ws)!!;
|
||||
assert(w.str_view() == "helloworldabcbc");
|
||||
}
|
||||
|
||||
fn void! bytewriter_buffer()
|
||||
fn void bytewriter_buffer()
|
||||
{
|
||||
ByteWriter writer;
|
||||
char[8] z;
|
||||
@@ -36,7 +36,7 @@ fn void! bytewriter_buffer()
|
||||
assert(@catch(s.write("xxxx")));
|
||||
}
|
||||
|
||||
fn void! bytewriter_read_from()
|
||||
fn void bytewriter_read_from()
|
||||
{
|
||||
char[] data = "Lorem ipsum dolor sit amet biam.";
|
||||
TestReader r = { .bytes = data };
|
||||
@@ -44,7 +44,7 @@ fn void! bytewriter_read_from()
|
||||
|
||||
ByteWriter bw;
|
||||
bw.temp_init();
|
||||
bw.read_from(s)!;
|
||||
bw.read_from(s)!!;
|
||||
|
||||
assert(bw.str_view() == data);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module std::io @test;
|
||||
|
||||
fn void! test_writing()
|
||||
fn void test_writing()
|
||||
{
|
||||
DString foo;
|
||||
foo.new_init();
|
||||
@@ -10,7 +10,7 @@ fn void! test_writing()
|
||||
s.write("what?-------------------------------------------------------")!!;
|
||||
ByteReader r;
|
||||
String test_str = "2134";
|
||||
io::copy_to(r.init(test_str), s)!;
|
||||
io::copy_to(r.init(test_str), s)!!;
|
||||
String o = foo.str_view();
|
||||
assert(o == "hello-what?-------------------------------------------------------2134");
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ struct Data {
|
||||
}
|
||||
}
|
||||
|
||||
fn void! read_write_any()
|
||||
fn void read_write_any()
|
||||
{
|
||||
Data data;
|
||||
data.boolean = false;
|
||||
@@ -58,7 +58,7 @@ fn void! read_write_any()
|
||||
File file = file::open("__file_read_write_any_test_file", "wb")!!;
|
||||
|
||||
io::write_any(&file, &data)!!;
|
||||
file.flush()!;
|
||||
file.flush()!!;
|
||||
file.close()!!;
|
||||
|
||||
file = file::open("__file_read_write_any_test_file", "rb")!!;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module std::io @test;
|
||||
|
||||
|
||||
fn void! limitreader()
|
||||
fn void limitreader()
|
||||
{
|
||||
const DATA = "Hello World!";
|
||||
ByteReader src;
|
||||
@@ -11,7 +11,7 @@ fn void! limitreader()
|
||||
lmr.init(&src, LIMIT);
|
||||
|
||||
char[DATA.len] bytes;
|
||||
usz n = lmr.read(bytes[..])!;
|
||||
usz n = lmr.read(bytes[..])!!;
|
||||
|
||||
assert(n == LIMIT, "got %d; want %d", n, LIMIT);
|
||||
String got = (String)bytes[:n];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module std::io @test;
|
||||
|
||||
fn void! test_multireader()
|
||||
fn void test_multireader()
|
||||
{
|
||||
MultiReader mr;
|
||||
mr.temp_init(
|
||||
@@ -12,7 +12,7 @@ fn void! test_multireader()
|
||||
defer mr.free();
|
||||
|
||||
ByteWriter w;
|
||||
io::copy_to(&mr, w.temp_init())!;
|
||||
io::copy_to(&mr, w.temp_init())!!;
|
||||
|
||||
String want = "foo bar!";
|
||||
assert(w.str_view() == want,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module std::io @test;
|
||||
|
||||
fn void! test_multiwriter()
|
||||
fn void test_multiwriter()
|
||||
{
|
||||
ByteWriter w1, w2;
|
||||
MultiWriter mw;
|
||||
@@ -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);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
module std::io::path @test;
|
||||
|
||||
fn void! test_dot()
|
||||
fn void test_dot()
|
||||
{
|
||||
Path p = path::new(".")!;
|
||||
Path p = path::new(".")!!;
|
||||
assert(@catch(p.parent()));
|
||||
// It must be possible to form the absolute version.
|
||||
Path p2 = p.new_absolute()!;
|
||||
p2 = p.new_append("/hello/world")!;
|
||||
Path p2 = p.new_absolute()!!;
|
||||
p2 = p.new_append("/hello/world")!!;
|
||||
if (p2.env == POSIX)
|
||||
{
|
||||
assert(p2.str_view() == "hello/world");
|
||||
@@ -17,21 +17,21 @@ fn void! test_dot()
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_parent()
|
||||
fn void test_parent()
|
||||
{
|
||||
Path p = path::new("")!;
|
||||
Path p = path::new("")!!;
|
||||
assert(@catch(p.parent()));
|
||||
p = path::new("/", path_env: PathEnv.POSIX)!;
|
||||
p = path::new("/", path_env: PathEnv.POSIX)!!;
|
||||
assert(@catch(p.parent()));
|
||||
p = path::new("/a/b/c", path_env: PathEnv.POSIX)!;
|
||||
assert(p.parent().str_view()! == "/a/b");
|
||||
p = path::new("/a/b/c", path_env: PathEnv.WIN32)!;
|
||||
assert(p.parent().str_view()! == `\a\b`);
|
||||
p = path::new("/a/b/c", path_env: PathEnv.POSIX)!!;
|
||||
assert(p.parent().str_view()!! == "/a/b");
|
||||
p = path::new("/a/b/c", path_env: PathEnv.WIN32)!!;
|
||||
assert(p.parent().str_view()!! == `\a\b`);
|
||||
}
|
||||
|
||||
fn void! test_path_normalized()
|
||||
fn void test_path_normalized()
|
||||
{
|
||||
assert(path::new("", path_env: PathEnv.WIN32).str_view()! == "");
|
||||
assert(path::new("", path_env: PathEnv.WIN32).str_view()!! == "");
|
||||
assert(@catch(path::new("1:\\a\\b\\c.txt", path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(":", path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new("1:", path_env: PathEnv.WIN32)));
|
||||
@@ -52,160 +52,160 @@ fn void! test_path_normalized()
|
||||
assert(@catch(path::new(`C:/../a`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(`C:/..`, path_env: PathEnv.WIN32)));
|
||||
|
||||
assert(path::new("/", path_env: PathEnv.POSIX).str_view()! == "/");
|
||||
assert(path::new("/./", path_env: PathEnv.POSIX).str_view()! == "/");
|
||||
assert(path::new("/foo/../", path_env: PathEnv.POSIX).str_view()! == "/");
|
||||
assert(path::new("/foo/bar/../", path_env: PathEnv.POSIX).str_view()! == "/foo");
|
||||
assert(path::new("/foo//bar", path_env: PathEnv.POSIX).str_view()! == "/foo/bar");
|
||||
assert(path::new("/foo//bar/../", path_env: PathEnv.POSIX).str_view()! == "/foo");
|
||||
assert(path::new("/foo/.bar", path_env: PathEnv.POSIX).str_view()! == "/foo/.bar");
|
||||
assert(path::new(`\foo\.bar`, path_env: PathEnv.WIN32).str_view()! == `\foo\.bar`);
|
||||
assert(path::new("a\\b/c.txt", path_env: PathEnv.WIN32).str_view()! == `a\b\c.txt`);
|
||||
assert(path::new("a\\b/c.txt", path_env: PathEnv.POSIX).str_view()! == "a\\b/c.txt");
|
||||
assert(path::new("C:\\a\\b/c.txt", path_env: PathEnv.WIN32).str_view()! == `C:\a\b\c.txt`);
|
||||
assert(path::new("C:\\a\\b/c.txt", path_env: PathEnv.POSIX).str_view()! == "C:\\a\\b/c.txt");
|
||||
assert(path::new(`\\server\a\b/c.txt`, path_env: PathEnv.WIN32).str_view()! == `\\server\a\b\c.txt`);
|
||||
assert(path::new(`\\server\a\b/c.txt`, path_env: PathEnv.POSIX).str_view()! == `\\server\a\b/c.txt`);
|
||||
assert(path::new(`c:\hello//bar\\\\foo.txt`, path_env: PathEnv.WIN32).str_view()! == `c:\hello\bar\foo.txt`);
|
||||
assert(path::new("/", path_env: PathEnv.POSIX).str_view()!! == "/");
|
||||
assert(path::new("/./", path_env: PathEnv.POSIX).str_view()!! == "/");
|
||||
assert(path::new("/foo/../", path_env: PathEnv.POSIX).str_view()!! == "/");
|
||||
assert(path::new("/foo/bar/../", path_env: PathEnv.POSIX).str_view()!! == "/foo");
|
||||
assert(path::new("/foo//bar", path_env: PathEnv.POSIX).str_view()!! == "/foo/bar");
|
||||
assert(path::new("/foo//bar/../", path_env: PathEnv.POSIX).str_view()!! == "/foo");
|
||||
assert(path::new("/foo/.bar", path_env: PathEnv.POSIX).str_view()!! == "/foo/.bar");
|
||||
assert(path::new(`\foo\.bar`, path_env: PathEnv.WIN32).str_view()!! == `\foo\.bar`);
|
||||
assert(path::new("a\\b/c.txt", path_env: PathEnv.WIN32).str_view()!! == `a\b\c.txt`);
|
||||
assert(path::new("a\\b/c.txt", path_env: PathEnv.POSIX).str_view()!! == "a\\b/c.txt");
|
||||
assert(path::new("C:\\a\\b/c.txt", path_env: PathEnv.WIN32).str_view()!! == `C:\a\b\c.txt`);
|
||||
assert(path::new("C:\\a\\b/c.txt", path_env: PathEnv.POSIX).str_view()!! == "C:\\a\\b/c.txt");
|
||||
assert(path::new(`\\server\a\b/c.txt`, path_env: PathEnv.WIN32).str_view()!! == `\\server\a\b\c.txt`);
|
||||
assert(path::new(`\\server\a\b/c.txt`, path_env: PathEnv.POSIX).str_view()!! == `\\server\a\b/c.txt`);
|
||||
assert(path::new(`c:\hello//bar\\\\foo.txt`, path_env: PathEnv.WIN32).str_view()!! == `c:\hello\bar\foo.txt`);
|
||||
|
||||
assert(path::new(`~\a\b/c.txt`, path_env: PathEnv.WIN32).str_view()! == `~\a\b\c.txt`);
|
||||
assert(path::new(`~\a\b/c.txt`, path_env: PathEnv.POSIX).str_view()! == `~\a\b/c.txt`);
|
||||
assert(path::new(`~\a\b/c.txt`, path_env: PathEnv.WIN32).str_view()!! == `~\a\b\c.txt`);
|
||||
assert(path::new(`~\a\b/c.txt`, path_env: PathEnv.POSIX).str_view()!! == `~\a\b/c.txt`);
|
||||
|
||||
|
||||
assert(path::new(`a/b/../../../c`, path_env: PathEnv.WIN32).str_view()! == `..\c`);
|
||||
assert(path::new(`a/b/../../../c`, path_env: PathEnv.POSIX).str_view()! == `../c`);
|
||||
assert(path::new(`a/b/../../..`, path_env: PathEnv.WIN32).str_view()! == `..`);
|
||||
assert(path::new(`a/b/../../..`, path_env: PathEnv.POSIX).str_view()! == `..`);
|
||||
assert(path::new(`../a`, path_env: PathEnv.WIN32).str_view()! == `..\a`);
|
||||
assert(path::new(`../a`, path_env: PathEnv.POSIX).str_view()! == `../a`);
|
||||
assert(path::new(`..`, path_env: PathEnv.WIN32).str_view()! == `..`);
|
||||
assert(path::new(`..`, path_env: PathEnv.POSIX).str_view()! == `..`);
|
||||
assert(path::new(`a/b/../c`, path_env: PathEnv.WIN32).str_view()! == `a\c`);
|
||||
assert(path::new(`a/b/../c`, path_env: PathEnv.POSIX).str_view()! == `a/c`);
|
||||
assert(path::new(`a/b/../../c`, path_env: PathEnv.WIN32).str_view()! == `c`);
|
||||
assert(path::new(`a/b/../../c`, path_env: PathEnv.POSIX).str_view()! == `c`);
|
||||
assert(path::new(`a/b/..`, path_env: PathEnv.WIN32).str_view()! == `a`);
|
||||
assert(path::new(`a/b/..`, path_env: PathEnv.POSIX).str_view()! == `a`);
|
||||
assert(path::new(`a/b/../`, path_env: PathEnv.WIN32).str_view()! == `a`);
|
||||
assert(path::new(`a/b/../`, path_env: PathEnv.POSIX).str_view()! == `a`);
|
||||
assert(path::new(`a/b/../..`, path_env: PathEnv.WIN32).str_view()! == ".");
|
||||
assert(path::new(`a/b/../..`, path_env: PathEnv.POSIX).str_view()! == ".");
|
||||
assert(path::new(`a/b/../../`, path_env: PathEnv.WIN32).str_view()! == ".");
|
||||
assert(path::new(`a/b/../../`, path_env: PathEnv.POSIX).str_view()! == ".");
|
||||
assert(path::new(`a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()! == `a\d`);
|
||||
assert(path::new(`a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()! == `a/d`);
|
||||
assert(path::new(`a/b/../c/../d/`, path_env: PathEnv.WIN32).str_view()! == `a\d`);
|
||||
assert(path::new(`a/b/../c/../d/`, path_env: PathEnv.POSIX).str_view()! == `a/d`);
|
||||
assert(path::new(`a/b//d`, path_env: PathEnv.WIN32).str_view()! == `a\b\d`);
|
||||
assert(path::new(`a/b//d`, path_env: PathEnv.POSIX).str_view()! == `a/b/d`);
|
||||
assert(path::new(`a/b/././.`, path_env: PathEnv.WIN32).str_view()! == `a\b`);
|
||||
assert(path::new(`a/b/././.`, path_env: PathEnv.POSIX).str_view()! == `a/b`);
|
||||
assert(path::new(`a/b/./././`, path_env: PathEnv.WIN32).str_view()! == `a\b`);
|
||||
assert(path::new(`a/b/./././`, path_env: PathEnv.POSIX).str_view()! == `a/b`);
|
||||
assert(path::new(`./a/`, path_env: PathEnv.WIN32).str_view()! == `a`);
|
||||
assert(path::new(`./a/`, path_env: PathEnv.POSIX).str_view()! == `a`);
|
||||
assert(path::new(`./`, path_env: PathEnv.WIN32).str_view()! == `.`);
|
||||
assert(path::new(`./`, path_env: PathEnv.POSIX).str_view()! == `.`);
|
||||
assert(path::new(`.`, path_env: PathEnv.WIN32).str_view()! == `.`);
|
||||
assert(path::new(`.`, path_env: PathEnv.POSIX).str_view()! == `.`);
|
||||
assert(path::new(``, path_env: PathEnv.WIN32).str_view()! == ``);
|
||||
assert(path::new(``, path_env: PathEnv.POSIX).str_view()! == ``);
|
||||
assert(path::new(`/a`, path_env: PathEnv.WIN32).str_view()! == `\a`);
|
||||
assert(path::new(`/a`, path_env: PathEnv.POSIX).str_view()! == `/a`);
|
||||
assert(path::new(`/a/`, path_env: PathEnv.WIN32).str_view()! == `\a`);
|
||||
assert(path::new(`/a/`, path_env: PathEnv.POSIX).str_view()! == `/a`);
|
||||
assert(path::new(`/a/b/../c`, path_env: PathEnv.WIN32).str_view()! == `\a\c`);
|
||||
assert(path::new(`/a/b/../c`, path_env: PathEnv.POSIX).str_view()! == `/a/c`);
|
||||
assert(path::new(`/a/b/../../c`, path_env: PathEnv.WIN32).str_view()! == `\c`);
|
||||
assert(path::new(`/a/b/../../c`, path_env: PathEnv.POSIX).str_view()! == `/c`);
|
||||
assert(path::new(`/a/b/..`, path_env: PathEnv.WIN32).str_view()! == `\a`);
|
||||
assert(path::new(`/a/b/..`, path_env: PathEnv.POSIX).str_view()! == `/a`);
|
||||
assert(path::new(`/a/b/../..`, path_env: PathEnv.WIN32).str_view()! == `\`);
|
||||
assert(path::new(`/a/b/../..`, path_env: PathEnv.POSIX).str_view()! == `/`);
|
||||
assert(path::new(`/a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()! == `\a\d`);
|
||||
assert(path::new(`/a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()! == `/a/d`);
|
||||
assert(path::new(`/a/b//d`, path_env: PathEnv.WIN32).str_view()! == `\a\b\d`);
|
||||
assert(path::new(`/a/b//d`, path_env: PathEnv.POSIX).str_view()! == `/a/b/d`);
|
||||
assert(path::new(`/./a/`, path_env: PathEnv.WIN32).str_view()! == `\a`);
|
||||
assert(path::new(`/./a/`, path_env: PathEnv.POSIX).str_view()! == `/a`);
|
||||
assert(path::new(`/./`, path_env: PathEnv.WIN32).str_view()! == `\`);
|
||||
assert(path::new(`/./`, path_env: PathEnv.POSIX).str_view()! == `/`);
|
||||
assert(path::new(`/.`, path_env: PathEnv.WIN32).str_view()! == `\`);
|
||||
assert(path::new(`/.`, path_env: PathEnv.POSIX).str_view()! == `/`);
|
||||
assert(path::new(`/`, path_env: PathEnv.WIN32).str_view()! == `\`);
|
||||
assert(path::new(`/`, path_env: PathEnv.POSIX).str_view()! == `/`);
|
||||
assert(path::new(`C:/a`, path_env: PathEnv.WIN32).str_view()! == `C:\a`);
|
||||
assert(path::new(`C:/a`, path_env: PathEnv.POSIX).str_view()! == `C:/a`);
|
||||
assert(path::new(`C:/a/b/../c`, path_env: PathEnv.WIN32).str_view()! == `C:\a\c`);
|
||||
assert(path::new(`C:/a/b/../c`, path_env: PathEnv.POSIX).str_view()! == `C:/a/c`);
|
||||
assert(path::new(`C:/a/b/../../c`, path_env: PathEnv.WIN32).str_view()! == `C:\c`);
|
||||
assert(path::new(`C:/a/b/../../c`, path_env: PathEnv.POSIX).str_view()! == `C:/c`);
|
||||
assert(path::new(`C:/a/b/../../../c`, path_env: PathEnv.POSIX).str_view()! == `c`);
|
||||
assert(path::new(`C:/a/b/..`, path_env: PathEnv.WIN32).str_view()! == `C:\a`);
|
||||
assert(path::new(`C:/a/b/..`, path_env: PathEnv.POSIX).str_view()! == `C:/a`);
|
||||
assert(path::new(`C:/a/b/../..`, path_env: PathEnv.WIN32).str_view()! == `C:\`);
|
||||
assert(path::new(`C:/a/b/../..`, path_env: PathEnv.POSIX).str_view()! == `C:`);
|
||||
assert(path::new(`C:/a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()! == `C:\a\d`);
|
||||
assert(path::new(`C:/a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()! == `C:/a/d`);
|
||||
assert(path::new(`C:/a/b//d`, path_env: PathEnv.WIN32).str_view()! == `C:\a\b\d`);
|
||||
assert(path::new(`C:/a/b//d`, path_env: PathEnv.POSIX).str_view()! == `C:/a/b/d`);
|
||||
assert(path::new(`C:/a/b/././.`, path_env: PathEnv.WIN32).str_view()! == `C:\a\b`);
|
||||
assert(path::new(`C:/a/b/././.`, path_env: PathEnv.POSIX).str_view()! == `C:/a/b`);
|
||||
assert(path::new(`C:/./a`, path_env: PathEnv.WIN32).str_view()! == `C:\a`);
|
||||
assert(path::new(`C:/./a`, path_env: PathEnv.POSIX).str_view()! == `C:/a`);
|
||||
assert(path::new(`C:/./`, path_env: PathEnv.WIN32).str_view()! == `C:\`);
|
||||
assert(path::new(`C:/./`, path_env: PathEnv.POSIX).str_view()! == `C:`);
|
||||
assert(path::new(`C:/../a`, path_env: PathEnv.POSIX).str_view()! == `a`);
|
||||
assert(path::new(`C:/..`, path_env: PathEnv.POSIX).str_view()! == `.`);
|
||||
assert(path::new(`C:/`, path_env: PathEnv.WIN32).str_view()! == `C:\`);
|
||||
assert(path::new(`C:/`, path_env: PathEnv.POSIX).str_view()! == `C:`);
|
||||
assert(path::new(`C:a`, path_env: PathEnv.WIN32).str_view()! == `C:a`);
|
||||
assert(path::new(`C:a`, path_env: PathEnv.POSIX).str_view()! == `C:a`);
|
||||
assert(path::new(`C:a/`, path_env: PathEnv.WIN32).str_view()! == `C:a`);
|
||||
assert(path::new(`C:a/`, path_env: PathEnv.POSIX).str_view()! == `C:a`);
|
||||
assert(path::new(`a/b/../../../c`, path_env: PathEnv.WIN32).str_view()!! == `..\c`);
|
||||
assert(path::new(`a/b/../../../c`, path_env: PathEnv.POSIX).str_view()!! == `../c`);
|
||||
assert(path::new(`a/b/../../..`, path_env: PathEnv.WIN32).str_view()!! == `..`);
|
||||
assert(path::new(`a/b/../../..`, path_env: PathEnv.POSIX).str_view()!! == `..`);
|
||||
assert(path::new(`../a`, path_env: PathEnv.WIN32).str_view()!! == `..\a`);
|
||||
assert(path::new(`../a`, path_env: PathEnv.POSIX).str_view()!! == `../a`);
|
||||
assert(path::new(`..`, path_env: PathEnv.WIN32).str_view()!! == `..`);
|
||||
assert(path::new(`..`, path_env: PathEnv.POSIX).str_view()!! == `..`);
|
||||
assert(path::new(`a/b/../c`, path_env: PathEnv.WIN32).str_view()!! == `a\c`);
|
||||
assert(path::new(`a/b/../c`, path_env: PathEnv.POSIX).str_view()!! == `a/c`);
|
||||
assert(path::new(`a/b/../../c`, path_env: PathEnv.WIN32).str_view()!! == `c`);
|
||||
assert(path::new(`a/b/../../c`, path_env: PathEnv.POSIX).str_view()!! == `c`);
|
||||
assert(path::new(`a/b/..`, path_env: PathEnv.WIN32).str_view()!! == `a`);
|
||||
assert(path::new(`a/b/..`, path_env: PathEnv.POSIX).str_view()!! == `a`);
|
||||
assert(path::new(`a/b/../`, path_env: PathEnv.WIN32).str_view()!! == `a`);
|
||||
assert(path::new(`a/b/../`, path_env: PathEnv.POSIX).str_view()!! == `a`);
|
||||
assert(path::new(`a/b/../..`, path_env: PathEnv.WIN32).str_view()!! == ".");
|
||||
assert(path::new(`a/b/../..`, path_env: PathEnv.POSIX).str_view()!! == ".");
|
||||
assert(path::new(`a/b/../../`, path_env: PathEnv.WIN32).str_view()!! == ".");
|
||||
assert(path::new(`a/b/../../`, path_env: PathEnv.POSIX).str_view()!! == ".");
|
||||
assert(path::new(`a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()!! == `a\d`);
|
||||
assert(path::new(`a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()!! == `a/d`);
|
||||
assert(path::new(`a/b/../c/../d/`, path_env: PathEnv.WIN32).str_view()!! == `a\d`);
|
||||
assert(path::new(`a/b/../c/../d/`, path_env: PathEnv.POSIX).str_view()!! == `a/d`);
|
||||
assert(path::new(`a/b//d`, path_env: PathEnv.WIN32).str_view()!! == `a\b\d`);
|
||||
assert(path::new(`a/b//d`, path_env: PathEnv.POSIX).str_view()!! == `a/b/d`);
|
||||
assert(path::new(`a/b/././.`, path_env: PathEnv.WIN32).str_view()!! == `a\b`);
|
||||
assert(path::new(`a/b/././.`, path_env: PathEnv.POSIX).str_view()!! == `a/b`);
|
||||
assert(path::new(`a/b/./././`, path_env: PathEnv.WIN32).str_view()!! == `a\b`);
|
||||
assert(path::new(`a/b/./././`, path_env: PathEnv.POSIX).str_view()!! == `a/b`);
|
||||
assert(path::new(`./a/`, path_env: PathEnv.WIN32).str_view()!! == `a`);
|
||||
assert(path::new(`./a/`, path_env: PathEnv.POSIX).str_view()!! == `a`);
|
||||
assert(path::new(`./`, path_env: PathEnv.WIN32).str_view()!! == `.`);
|
||||
assert(path::new(`./`, path_env: PathEnv.POSIX).str_view()!! == `.`);
|
||||
assert(path::new(`.`, path_env: PathEnv.WIN32).str_view()!! == `.`);
|
||||
assert(path::new(`.`, path_env: PathEnv.POSIX).str_view()!! == `.`);
|
||||
assert(path::new(``, path_env: PathEnv.WIN32).str_view()!! == ``);
|
||||
assert(path::new(``, path_env: PathEnv.POSIX).str_view()!! == ``);
|
||||
assert(path::new(`/a`, path_env: PathEnv.WIN32).str_view()!! == `\a`);
|
||||
assert(path::new(`/a`, path_env: PathEnv.POSIX).str_view()!! == `/a`);
|
||||
assert(path::new(`/a/`, path_env: PathEnv.WIN32).str_view()!! == `\a`);
|
||||
assert(path::new(`/a/`, path_env: PathEnv.POSIX).str_view()!! == `/a`);
|
||||
assert(path::new(`/a/b/../c`, path_env: PathEnv.WIN32).str_view()!! == `\a\c`);
|
||||
assert(path::new(`/a/b/../c`, path_env: PathEnv.POSIX).str_view()!! == `/a/c`);
|
||||
assert(path::new(`/a/b/../../c`, path_env: PathEnv.WIN32).str_view()!! == `\c`);
|
||||
assert(path::new(`/a/b/../../c`, path_env: PathEnv.POSIX).str_view()!! == `/c`);
|
||||
assert(path::new(`/a/b/..`, path_env: PathEnv.WIN32).str_view()!! == `\a`);
|
||||
assert(path::new(`/a/b/..`, path_env: PathEnv.POSIX).str_view()!! == `/a`);
|
||||
assert(path::new(`/a/b/../..`, path_env: PathEnv.WIN32).str_view()!! == `\`);
|
||||
assert(path::new(`/a/b/../..`, path_env: PathEnv.POSIX).str_view()!! == `/`);
|
||||
assert(path::new(`/a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()!! == `\a\d`);
|
||||
assert(path::new(`/a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()!! == `/a/d`);
|
||||
assert(path::new(`/a/b//d`, path_env: PathEnv.WIN32).str_view()!! == `\a\b\d`);
|
||||
assert(path::new(`/a/b//d`, path_env: PathEnv.POSIX).str_view()!! == `/a/b/d`);
|
||||
assert(path::new(`/./a/`, path_env: PathEnv.WIN32).str_view()!! == `\a`);
|
||||
assert(path::new(`/./a/`, path_env: PathEnv.POSIX).str_view()!! == `/a`);
|
||||
assert(path::new(`/./`, path_env: PathEnv.WIN32).str_view()!! == `\`);
|
||||
assert(path::new(`/./`, path_env: PathEnv.POSIX).str_view()!! == `/`);
|
||||
assert(path::new(`/.`, path_env: PathEnv.WIN32).str_view()!! == `\`);
|
||||
assert(path::new(`/.`, path_env: PathEnv.POSIX).str_view()!! == `/`);
|
||||
assert(path::new(`/`, path_env: PathEnv.WIN32).str_view()!! == `\`);
|
||||
assert(path::new(`/`, path_env: PathEnv.POSIX).str_view()!! == `/`);
|
||||
assert(path::new(`C:/a`, path_env: PathEnv.WIN32).str_view()!! == `C:\a`);
|
||||
assert(path::new(`C:/a`, path_env: PathEnv.POSIX).str_view()!! == `C:/a`);
|
||||
assert(path::new(`C:/a/b/../c`, path_env: PathEnv.WIN32).str_view()!! == `C:\a\c`);
|
||||
assert(path::new(`C:/a/b/../c`, path_env: PathEnv.POSIX).str_view()!! == `C:/a/c`);
|
||||
assert(path::new(`C:/a/b/../../c`, path_env: PathEnv.WIN32).str_view()!! == `C:\c`);
|
||||
assert(path::new(`C:/a/b/../../c`, path_env: PathEnv.POSIX).str_view()!! == `C:/c`);
|
||||
assert(path::new(`C:/a/b/../../../c`, path_env: PathEnv.POSIX).str_view()!! == `c`);
|
||||
assert(path::new(`C:/a/b/..`, path_env: PathEnv.WIN32).str_view()!! == `C:\a`);
|
||||
assert(path::new(`C:/a/b/..`, path_env: PathEnv.POSIX).str_view()!! == `C:/a`);
|
||||
assert(path::new(`C:/a/b/../..`, path_env: PathEnv.WIN32).str_view()!! == `C:\`);
|
||||
assert(path::new(`C:/a/b/../..`, path_env: PathEnv.POSIX).str_view()!! == `C:`);
|
||||
assert(path::new(`C:/a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()!! == `C:\a\d`);
|
||||
assert(path::new(`C:/a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()!! == `C:/a/d`);
|
||||
assert(path::new(`C:/a/b//d`, path_env: PathEnv.WIN32).str_view()!! == `C:\a\b\d`);
|
||||
assert(path::new(`C:/a/b//d`, path_env: PathEnv.POSIX).str_view()!! == `C:/a/b/d`);
|
||||
assert(path::new(`C:/a/b/././.`, path_env: PathEnv.WIN32).str_view()!! == `C:\a\b`);
|
||||
assert(path::new(`C:/a/b/././.`, path_env: PathEnv.POSIX).str_view()!! == `C:/a/b`);
|
||||
assert(path::new(`C:/./a`, path_env: PathEnv.WIN32).str_view()!! == `C:\a`);
|
||||
assert(path::new(`C:/./a`, path_env: PathEnv.POSIX).str_view()!! == `C:/a`);
|
||||
assert(path::new(`C:/./`, path_env: PathEnv.WIN32).str_view()!! == `C:\`);
|
||||
assert(path::new(`C:/./`, path_env: PathEnv.POSIX).str_view()!! == `C:`);
|
||||
assert(path::new(`C:/../a`, path_env: PathEnv.POSIX).str_view()!! == `a`);
|
||||
assert(path::new(`C:/..`, path_env: PathEnv.POSIX).str_view()!! == `.`);
|
||||
assert(path::new(`C:/`, path_env: PathEnv.WIN32).str_view()!! == `C:\`);
|
||||
assert(path::new(`C:/`, path_env: PathEnv.POSIX).str_view()!! == `C:`);
|
||||
assert(path::new(`C:a`, path_env: PathEnv.WIN32).str_view()!! == `C:a`);
|
||||
assert(path::new(`C:a`, path_env: PathEnv.POSIX).str_view()!! == `C:a`);
|
||||
assert(path::new(`C:a/`, path_env: PathEnv.WIN32).str_view()!! == `C:a`);
|
||||
assert(path::new(`C:a/`, path_env: PathEnv.POSIX).str_view()!! == `C:a`);
|
||||
|
||||
assert(path::new(`C:a/b/../c`, path_env: PathEnv.WIN32).str_view()! == `C:a\c`);
|
||||
assert(path::new(`C:a/b/../c`, path_env: PathEnv.POSIX).str_view()! == `C:a/c`);
|
||||
assert(path::new(`C:a/b/../../c`, path_env: PathEnv.WIN32).str_view()! == `C:c`);
|
||||
assert(path::new(`C:a/b/../../c`, path_env: PathEnv.POSIX).str_view()! == `c`);
|
||||
assert(path::new(`C:a/b/..`, path_env: PathEnv.WIN32).str_view()! == `C:a`);
|
||||
assert(path::new(`C:a/b/..`, path_env: PathEnv.POSIX).str_view()! == `C:a`);
|
||||
assert(path::new(`C:a/b/../..`, path_env: PathEnv.WIN32).str_view()! == `C:`);
|
||||
assert(path::new(`C:a/b/../..`, path_env: PathEnv.POSIX).str_view()! == `.`);
|
||||
assert(path::new(`C:a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()! == `C:a\d`);
|
||||
assert(path::new(`C:a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()! == `C:a/d`);
|
||||
assert(path::new(`C:a/b//d`, path_env: PathEnv.WIN32).str_view()! == `C:a\b\d`);
|
||||
assert(path::new(`C:a/b//d`, path_env: PathEnv.POSIX).str_view()! == `C:a/b/d`);
|
||||
assert(path::new(`C:a/b/././.`, path_env: PathEnv.WIN32).str_view()! == `C:a\b`);
|
||||
assert(path::new(`C:a/b/././.`, path_env: PathEnv.POSIX).str_view()! == `C:a/b`);
|
||||
assert(path::new(`C:a/b/../../../c`, path_env: PathEnv.WIN32).str_view()! == `C:..\c`);
|
||||
assert(path::new(`C:./a`, path_env: PathEnv.WIN32).str_view()! == `C:a`);
|
||||
assert(path::new(`C:./a`, path_env: PathEnv.POSIX).str_view()! == `C:./a`);
|
||||
assert(path::new(`C:./`, path_env: PathEnv.WIN32).str_view()! == `C:`);
|
||||
assert(path::new(`C:./`, path_env: PathEnv.POSIX).str_view()! == `C:.`);
|
||||
assert(path::new(`C:../a`, path_env: PathEnv.POSIX).str_view()! == `C:../a`);
|
||||
assert(path::new(`C:../a`, path_env: PathEnv.WIN32).str_view()! == `C:..\a`);
|
||||
assert(path::new(`C:..`, path_env: PathEnv.POSIX).str_view()! == `C:..`);
|
||||
assert(path::new(`C:..`, path_env: PathEnv.WIN32).str_view()! == `C:..`);
|
||||
assert(path::new(`C:`, path_env: PathEnv.WIN32).str_view()! == `C:`);
|
||||
assert(path::new(`C:`, path_env: PathEnv.POSIX).str_view()! == `C:`);
|
||||
assert(path::new(`C:a/b/../c`, path_env: PathEnv.WIN32).str_view()!! == `C:a\c`);
|
||||
assert(path::new(`C:a/b/../c`, path_env: PathEnv.POSIX).str_view()!! == `C:a/c`);
|
||||
assert(path::new(`C:a/b/../../c`, path_env: PathEnv.WIN32).str_view()!! == `C:c`);
|
||||
assert(path::new(`C:a/b/../../c`, path_env: PathEnv.POSIX).str_view()!! == `c`);
|
||||
assert(path::new(`C:a/b/..`, path_env: PathEnv.WIN32).str_view()!! == `C:a`);
|
||||
assert(path::new(`C:a/b/..`, path_env: PathEnv.POSIX).str_view()!! == `C:a`);
|
||||
assert(path::new(`C:a/b/../..`, path_env: PathEnv.WIN32).str_view()!! == `C:`);
|
||||
assert(path::new(`C:a/b/../..`, path_env: PathEnv.POSIX).str_view()!! == `.`);
|
||||
assert(path::new(`C:a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()!! == `C:a\d`);
|
||||
assert(path::new(`C:a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()!! == `C:a/d`);
|
||||
assert(path::new(`C:a/b//d`, path_env: PathEnv.WIN32).str_view()!! == `C:a\b\d`);
|
||||
assert(path::new(`C:a/b//d`, path_env: PathEnv.POSIX).str_view()!! == `C:a/b/d`);
|
||||
assert(path::new(`C:a/b/././.`, path_env: PathEnv.WIN32).str_view()!! == `C:a\b`);
|
||||
assert(path::new(`C:a/b/././.`, path_env: PathEnv.POSIX).str_view()!! == `C:a/b`);
|
||||
assert(path::new(`C:a/b/../../../c`, path_env: PathEnv.WIN32).str_view()!! == `C:..\c`);
|
||||
assert(path::new(`C:./a`, path_env: PathEnv.WIN32).str_view()!! == `C:a`);
|
||||
assert(path::new(`C:./a`, path_env: PathEnv.POSIX).str_view()!! == `C:./a`);
|
||||
assert(path::new(`C:./`, path_env: PathEnv.WIN32).str_view()!! == `C:`);
|
||||
assert(path::new(`C:./`, path_env: PathEnv.POSIX).str_view()!! == `C:.`);
|
||||
assert(path::new(`C:../a`, path_env: PathEnv.POSIX).str_view()!! == `C:../a`);
|
||||
assert(path::new(`C:../a`, path_env: PathEnv.WIN32).str_view()!! == `C:..\a`);
|
||||
assert(path::new(`C:..`, path_env: PathEnv.POSIX).str_view()!! == `C:..`);
|
||||
assert(path::new(`C:..`, path_env: PathEnv.WIN32).str_view()!! == `C:..`);
|
||||
assert(path::new(`C:`, path_env: PathEnv.WIN32).str_view()!! == `C:`);
|
||||
assert(path::new(`C:`, path_env: PathEnv.POSIX).str_view()!! == `C:`);
|
||||
|
||||
assert(path::new(`\\server\foo/a`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\a`);
|
||||
assert(path::new(`\\server\foo/a`, path_env: PathEnv.POSIX).str_view()! == `\\server\foo/a`);
|
||||
assert(path::new(`\\server\foo\a\b\..\c`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\a\c`);
|
||||
assert(path::new(`\\server\foo\a\b\..\..\c`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\c`);
|
||||
assert(path::new(`\\server\foo\a\b\..`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\a`);
|
||||
assert(path::new(`\\server\foo\a\..`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\`);
|
||||
assert(path::new(`\\server\foo\a\b\..\c\..\d`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\a\d`);
|
||||
assert(path::new(`\\server\foo\a\b\\d`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\a\b\d`);
|
||||
assert(path::new(`\\server\foo\a\b\.\.\.`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\a\b`);
|
||||
assert(path::new(`\\server\foo\.\a`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\a`);
|
||||
assert(path::new(`\\server\foo\.`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\`);
|
||||
assert(path::new(`\\server\foo\`, path_env: PathEnv.WIN32).str_view()! == `\\server\foo\`);
|
||||
assert(path::new(`\\server\foo/a`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a`);
|
||||
assert(path::new(`\\server\foo/a`, path_env: PathEnv.POSIX).str_view()!! == `\\server\foo/a`);
|
||||
assert(path::new(`\\server\foo\a\b\..\c`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a\c`);
|
||||
assert(path::new(`\\server\foo\a\b\..\..\c`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\c`);
|
||||
assert(path::new(`\\server\foo\a\b\..`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a`);
|
||||
assert(path::new(`\\server\foo\a\..`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\`);
|
||||
assert(path::new(`\\server\foo\a\b\..\c\..\d`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a\d`);
|
||||
assert(path::new(`\\server\foo\a\b\\d`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a\b\d`);
|
||||
assert(path::new(`\\server\foo\a\b\.\.\.`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a\b`);
|
||||
assert(path::new(`\\server\foo\.\a`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a`);
|
||||
assert(path::new(`\\server\foo\.`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\`);
|
||||
assert(path::new(`\\server\foo\`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\`);
|
||||
|
||||
}
|
||||
|
||||
fn void! test_extension()
|
||||
fn void test_extension()
|
||||
{
|
||||
assert(@catch(path::new(`C:`, path_env: PathEnv.WIN32).extension()));
|
||||
assert(@catch(path::new(`C:`, path_env: PathEnv.POSIX).extension()));
|
||||
@@ -213,159 +213,159 @@ fn void! test_extension()
|
||||
assert(@catch(path::new(`file`, path_env: PathEnv.POSIX).extension()));
|
||||
assert(@catch(path::new(`C:\temp\foo.bar\README`, path_env: PathEnv.WIN32).extension()));
|
||||
|
||||
assert(path::new_windows("file.txt").extension()! == "txt");
|
||||
assert(path::new_posix("file.txt").extension()! == "txt");
|
||||
assert(path::new_windows("file.txt").extension()!! == "txt");
|
||||
assert(path::new_posix("file.txt").extension()!! == "txt");
|
||||
|
||||
assert(path::new_windows("a/b/file.txt").extension()! == "txt");
|
||||
assert(path::new_posix("a/b/file.txt").extension()! == "txt");
|
||||
assert(path::new_windows("a/b/file.txt").extension()!! == "txt");
|
||||
assert(path::new_posix("a/b/file.txt").extension()!! == "txt");
|
||||
|
||||
assert(path::new_windows("a\\b\\file.txt").extension()! == "txt");
|
||||
assert(path::new_windows("a\\b\\file.txt").extension()!! == "txt");
|
||||
|
||||
assert(path::new_windows("a.b/file.txt").extension()! == "txt");
|
||||
assert(path::new_posix("a.b/file.txt").extension()! == "txt");
|
||||
assert(path::new_windows("a.b/file.txt").extension()! == "txt");
|
||||
assert(path::new_posix("a.b/file.txt").extension()! == "txt");
|
||||
assert(path::new_windows("a.b/file.txt").extension()!! == "txt");
|
||||
assert(path::new_posix("a.b/file.txt").extension()!! == "txt");
|
||||
assert(path::new_windows("a.b/file.txt").extension()!! == "txt");
|
||||
assert(path::new_posix("a.b/file.txt").extension()!! == "txt");
|
||||
|
||||
assert(path::new_windows("a.b\\file.txt").extension()! == "txt");
|
||||
assert(path::new_windows("a.b\\file.txt").extension()!! == "txt");
|
||||
|
||||
assert(path::new_windows("domain.dot.com").extension()! == "com");
|
||||
assert(path::new_posix("domain.dot.com").extension()! == "com");
|
||||
assert(path::new_windows("domain.dot.com").extension()!! == "com");
|
||||
assert(path::new_posix("domain.dot.com").extension()!! == "com");
|
||||
|
||||
assert(path::new_windows("image.jpeg").extension()! == "jpeg");
|
||||
assert(path::new_posix("image.jpeg").extension()! == "jpeg");
|
||||
assert(path::new_windows("image.jpeg").extension()!! == "jpeg");
|
||||
assert(path::new_posix("image.jpeg").extension()!! == "jpeg");
|
||||
|
||||
assert(path::new_windows("../filename.ext").extension()! == "ext");
|
||||
assert(path::new_posix("../filename.ext").extension()! == "ext");
|
||||
assert(path::new_windows("../filename.ext").extension()!! == "ext");
|
||||
assert(path::new_posix("../filename.ext").extension()!! == "ext");
|
||||
|
||||
}
|
||||
|
||||
fn void! test_has_extension()
|
||||
fn void test_has_extension()
|
||||
{
|
||||
assert(!path::new(`C:\temp\foo.bar\README`, path_env: PathEnv.WIN32)!.has_extension(`bar\README`));
|
||||
assert(!path::new(`C:\temp\foo.bar\README`, path_env: PathEnv.WIN32)!!.has_extension(`bar\README`));
|
||||
|
||||
assert(path::new_windows("file.txt")!.has_extension("txt"));
|
||||
assert(path::new_posix("file.txt")!.has_extension("txt"));
|
||||
assert(path::new_windows("file.txt")!!.has_extension("txt"));
|
||||
assert(path::new_posix("file.txt")!!.has_extension("txt"));
|
||||
|
||||
assert(path::new_windows("a/b/file.txt")!.has_extension("txt"));
|
||||
assert(path::new_posix("a/b/file.txt")!.has_extension("txt"));
|
||||
assert(path::new_windows("a/b/file.txt")!!.has_extension("txt"));
|
||||
assert(path::new_posix("a/b/file.txt")!!.has_extension("txt"));
|
||||
|
||||
assert(path::new_windows("a\\b\\file.txt")!.has_extension("txt"));
|
||||
assert(path::new_windows("a\\b\\file.txt")!!.has_extension("txt"));
|
||||
|
||||
assert(path::new_windows("a.b/file.txt")!.has_extension("txt"));
|
||||
assert(path::new_posix("a.b/file.txt")!.has_extension("txt"));
|
||||
assert(path::new_windows("a.b/file.txt")!.has_extension("txt"));
|
||||
assert(path::new_posix("a.b/file.txt")!.has_extension("txt"));
|
||||
assert(path::new_windows("a.b/file.txt")!!.has_extension("txt"));
|
||||
assert(path::new_posix("a.b/file.txt")!!.has_extension("txt"));
|
||||
assert(path::new_windows("a.b/file.txt")!!.has_extension("txt"));
|
||||
assert(path::new_posix("a.b/file.txt")!!.has_extension("txt"));
|
||||
|
||||
assert(path::new_windows("a.b\\file.txt")!.has_extension("txt"));
|
||||
assert(path::new_windows("a.b\\file.txt")!!.has_extension("txt"));
|
||||
|
||||
assert(path::new_windows("domain.dot.com")!.has_extension("com"));
|
||||
assert(path::new_posix("domain.dot.com")!.has_extension("com"));
|
||||
assert(path::new_windows("domain.dot.com")!!.has_extension("com"));
|
||||
assert(path::new_posix("domain.dot.com")!!.has_extension("com"));
|
||||
|
||||
assert(path::new_windows("image.jpeg")!.has_extension("jpeg"));
|
||||
assert(path::new_posix("image.jpeg")!.has_extension("jpeg"));
|
||||
assert(path::new_windows("image.jpeg")!!.has_extension("jpeg"));
|
||||
assert(path::new_posix("image.jpeg")!!.has_extension("jpeg"));
|
||||
|
||||
assert(path::new_windows("../filename.ext")!.has_extension("ext"));
|
||||
assert(path::new_posix("../filename.ext")!.has_extension("ext"));
|
||||
assert(path::new_windows("../filename.ext")!!.has_extension("ext"));
|
||||
assert(path::new_posix("../filename.ext")!!.has_extension("ext"));
|
||||
|
||||
}
|
||||
|
||||
fn void! test_basename()
|
||||
fn void test_basename()
|
||||
{
|
||||
assert(path::new_windows("file.txt").basename()! == "file.txt");
|
||||
assert(path::new_posix("file.txt").basename()! == "file.txt");
|
||||
assert(path::new_windows("file.txt").basename()!! == "file.txt");
|
||||
assert(path::new_posix("file.txt").basename()!! == "file.txt");
|
||||
|
||||
assert(path::new_windows("a/b/file.txt").basename()! == "file.txt");
|
||||
assert(path::new_posix("a/b/file.txt").basename()! == "file.txt");
|
||||
assert(path::new_windows("a/b/file.txt").basename()!! == "file.txt");
|
||||
assert(path::new_posix("a/b/file.txt").basename()!! == "file.txt");
|
||||
|
||||
assert(path::new_windows("a.b/file.txt").basename()! == "file.txt");
|
||||
assert(path::new_posix("a.b/file.txt").basename()! == "file.txt");
|
||||
assert(path::new_windows("a.b/file.txt").basename()!! == "file.txt");
|
||||
assert(path::new_posix("a.b/file.txt").basename()!! == "file.txt");
|
||||
|
||||
assert(path::new_windows("a.b/file.txt").basename()! == "file.txt");
|
||||
assert(path::new_posix("a.b/file.txt").basename()! == "file.txt");
|
||||
assert(path::new_windows("a.b/file.txt").basename()!! == "file.txt");
|
||||
assert(path::new_posix("a.b/file.txt").basename()!! == "file.txt");
|
||||
|
||||
assert(path::new_windows("../filename.ext").basename()! == "filename.ext");
|
||||
assert(path::new_posix("../filename.ext").basename()! == "filename.ext");
|
||||
assert(path::new_windows("../filename.ext").basename()!! == "filename.ext");
|
||||
assert(path::new_posix("../filename.ext").basename()!! == "filename.ext");
|
||||
|
||||
assert(path::new_windows("C:").basename()! == "");
|
||||
assert(path::new_posix("C:").basename()! == "C:");
|
||||
assert(path::new_windows("C:").basename()!! == "");
|
||||
assert(path::new_posix("C:").basename()!! == "C:");
|
||||
|
||||
assert(path::new_windows("../..").basename()! == "..");
|
||||
assert(path::new_posix("../..").basename()! == "..");
|
||||
assert(path::new_windows("../..").basename()!! == "..");
|
||||
assert(path::new_posix("../..").basename()!! == "..");
|
||||
|
||||
assert(path::new_windows(`\\server\abc`).basename()! == "");
|
||||
assert(path::new_posix(`\\server\abc`).basename()! == `\\server\abc`);
|
||||
assert(path::new_windows(`\\server\abc`).basename()!! == "");
|
||||
assert(path::new_posix(`\\server\abc`).basename()!! == `\\server\abc`);
|
||||
}
|
||||
|
||||
fn void! test_dirname()
|
||||
fn void test_dirname()
|
||||
{
|
||||
assert(path::new_posix("").dirname()! == ".");
|
||||
assert(path::new_posix("/file").dirname()! == "/");
|
||||
assert(path::new_posix("///").dirname()! == "/");
|
||||
assert(path::new_windows("d:").dirname()! == "d:");
|
||||
assert(path::new_windows("d:file").dirname()! == "d:");
|
||||
assert(path::new_windows(`d:\file`).dirname()! == `d:\`);
|
||||
assert(path::new_posix("").dirname()!! == ".");
|
||||
assert(path::new_posix("/file").dirname()!! == "/");
|
||||
assert(path::new_posix("///").dirname()!! == "/");
|
||||
assert(path::new_windows("d:").dirname()!! == "d:");
|
||||
assert(path::new_windows("d:file").dirname()!! == "d:");
|
||||
assert(path::new_windows(`d:\file`).dirname()!! == `d:\`);
|
||||
|
||||
assert(path::new_windows("file.txt").dirname()! == ".");
|
||||
assert(path::new_posix("file.txt").dirname()! == ".");
|
||||
assert(path::new_windows("file.txt").dirname()!! == ".");
|
||||
assert(path::new_posix("file.txt").dirname()!! == ".");
|
||||
|
||||
assert(path::new_windows("a/b/file.txt").dirname()! == `a\b`);
|
||||
assert(path::new_posix("a/b/file.txt").dirname()! == "a/b");
|
||||
assert(path::new_windows("a/b/file.txt").dirname()!! == `a\b`);
|
||||
assert(path::new_posix("a/b/file.txt").dirname()!! == "a/b");
|
||||
|
||||
assert(path::new_windows("a.b/file.txt").dirname()! == "a.b");
|
||||
assert(path::new_posix("a.b/file.txt").dirname()! == "a.b");
|
||||
assert(path::new_windows("a.b/file.txt").dirname()!! == "a.b");
|
||||
assert(path::new_posix("a.b/file.txt").dirname()!! == "a.b");
|
||||
|
||||
assert(path::new_windows("../filename.ext").dirname()! == "..");
|
||||
assert(path::new_posix("../filename.ext").dirname()! == "..");
|
||||
assert(path::new_windows("../filename.ext").dirname()!! == "..");
|
||||
assert(path::new_posix("../filename.ext").dirname()!! == "..");
|
||||
|
||||
assert(path::new_windows("C:").dirname()! == "C:");
|
||||
assert(path::new_posix("C:").dirname()! == ".");
|
||||
assert(path::new_windows("C:").dirname()!! == "C:");
|
||||
assert(path::new_posix("C:").dirname()!! == ".");
|
||||
|
||||
assert(path::new_windows("C:/").dirname()! == "C:\\");
|
||||
assert(path::new_posix("C:/").dirname()! == ".");
|
||||
assert(path::new_windows("C:/").dirname()!! == "C:\\");
|
||||
assert(path::new_posix("C:/").dirname()!! == ".");
|
||||
|
||||
assert(path::new_windows("C:/a").dirname()! == "C:\\");
|
||||
assert(path::new_posix("C:/a").dirname()! == "C:");
|
||||
assert(path::new_windows("C:/a").dirname()!! == "C:\\");
|
||||
assert(path::new_posix("C:/a").dirname()!! == "C:");
|
||||
|
||||
assert(path::new_windows("../..").dirname()! == "..");
|
||||
assert(path::new_posix("../..").dirname()! == "..");
|
||||
assert(path::new_windows("../..").dirname()!! == "..");
|
||||
assert(path::new_posix("../..").dirname()!! == "..");
|
||||
|
||||
assert(path::new_windows(`\\server\share\dir\file`).dirname()! == `\\server\share\dir`);
|
||||
assert(path::new_windows(`\\server\share\file`).dirname()! == `\\server\share`);
|
||||
assert(path::new_windows(`\\server\share\`).dirname()! == `\\server\share`);
|
||||
assert(path::new_windows(`\\server\share`).dirname()! == `\\server\share`);
|
||||
assert(path::new_posix(`\\server\`).dirname()! == `.`);
|
||||
assert(path::new_windows(`\\server\share\dir\file`).dirname()!! == `\\server\share\dir`);
|
||||
assert(path::new_windows(`\\server\share\file`).dirname()!! == `\\server\share`);
|
||||
assert(path::new_windows(`\\server\share\`).dirname()!! == `\\server\share`);
|
||||
assert(path::new_windows(`\\server\share`).dirname()!! == `\\server\share`);
|
||||
assert(path::new_posix(`\\server\`).dirname()!! == `.`);
|
||||
}
|
||||
|
||||
fn void! test_path_volume()
|
||||
fn void test_path_volume()
|
||||
{
|
||||
assert(path::new_windows(`C:\abs`).volume_name()! == `C:`);
|
||||
assert(path::new_windows(`C:abs`).volume_name()! == `C:`);
|
||||
assert(path::new_posix(`C:/abs`).volume_name()! == ``);
|
||||
assert(path::new_posix(`C:abs`).volume_name()! == ``);
|
||||
assert(path::new_windows(`\\server\foo`).volume_name()! == `\\server\foo`);
|
||||
assert(path::new_windows(`\\server\foo\abc`).volume_name()! == `\\server\foo`);
|
||||
assert(path::new_windows(`C:\abs`).volume_name()!! == `C:`);
|
||||
assert(path::new_windows(`C:abs`).volume_name()!! == `C:`);
|
||||
assert(path::new_posix(`C:/abs`).volume_name()!! == ``);
|
||||
assert(path::new_posix(`C:abs`).volume_name()!! == ``);
|
||||
assert(path::new_windows(`\\server\foo`).volume_name()!! == `\\server\foo`);
|
||||
assert(path::new_windows(`\\server\foo\abc`).volume_name()!! == `\\server\foo`);
|
||||
}
|
||||
|
||||
fn void! test_path_is_absolute()
|
||||
fn void test_path_is_absolute()
|
||||
{
|
||||
assert(!path::new_posix("").is_absolute()!);
|
||||
assert(path::new_posix("/").is_absolute()!);
|
||||
assert(path::new_posix("/a/b").is_absolute()!);
|
||||
assert(!path::new_posix("a/b").is_absolute()!);
|
||||
assert(!path::new_posix("").is_absolute()!!);
|
||||
assert(path::new_posix("/").is_absolute()!!);
|
||||
assert(path::new_posix("/a/b").is_absolute()!!);
|
||||
assert(!path::new_posix("a/b").is_absolute()!!);
|
||||
|
||||
assert(!path::new_windows(`C:`).is_absolute()!);
|
||||
assert(path::new_windows(`C:\abs`).is_absolute()!);
|
||||
assert(!path::new_windows(`C:abs`).is_absolute()!);
|
||||
assert(path::new_windows(`\\server\foo`).is_absolute()!);
|
||||
assert(path::new_windows(`\\server\foo\abc`).is_absolute()!);
|
||||
assert(!path::new_windows(`C:`).is_absolute()!!);
|
||||
assert(path::new_windows(`C:\abs`).is_absolute()!!);
|
||||
assert(!path::new_windows(`C:abs`).is_absolute()!!);
|
||||
assert(path::new_windows(`\\server\foo`).is_absolute()!!);
|
||||
assert(path::new_windows(`\\server\foo\abc`).is_absolute()!!);
|
||||
}
|
||||
|
||||
fn void! test_path_absolute()
|
||||
fn void test_path_absolute()
|
||||
{
|
||||
$if env::WIN32:
|
||||
assert(path::new_windows(`C:\abs`).new_absolute()!.str_view() == `C:\abs`);
|
||||
assert(path::new_windows(`C:\abs`).new_absolute()!!.str_view() == `C:\abs`);
|
||||
$else
|
||||
assert(path::new_posix("/").new_absolute()!.str_view() == "/");
|
||||
assert(path::new_posix(".").new_absolute()!.str_view() == path::temp_cwd()!!.str_view());
|
||||
assert(path::new_posix("/").new_absolute()!!.str_view() == "/");
|
||||
assert(path::new_posix(".").new_absolute()!!.str_view() == path::temp_cwd()!!.str_view());
|
||||
$endif
|
||||
}
|
||||
@@ -10,7 +10,7 @@ struct ScanTest
|
||||
String left_over;
|
||||
}
|
||||
|
||||
fn void! scanner()
|
||||
fn void scanner()
|
||||
{
|
||||
ScanTest[] tcases = {
|
||||
{"aa,,bb", {"aa"}, "bb"},
|
||||
@@ -35,7 +35,7 @@ fn void! scanner()
|
||||
case SearchResult.MISSING:
|
||||
break LOOP;
|
||||
default:
|
||||
return err?;
|
||||
return err?!!;
|
||||
}
|
||||
String str = (String)res;
|
||||
results.push(str.tconcat(""));
|
||||
@@ -49,7 +49,7 @@ fn void! scanner()
|
||||
}
|
||||
}
|
||||
|
||||
fn void! scanner_as_reader()
|
||||
fn void scanner_as_reader()
|
||||
{
|
||||
ByteReader br;
|
||||
br.init("Lorem ipsum sit.");
|
||||
@@ -57,10 +57,10 @@ fn void! scanner_as_reader()
|
||||
char[8] buffer;
|
||||
sc.init(&br, buffer[..]);
|
||||
|
||||
sc.scan(" ")!;
|
||||
sc.scan(" ")!!;
|
||||
|
||||
char[16] res;
|
||||
usz n = sc.read(&res)!;
|
||||
usz n = sc.read(&res)!!;
|
||||
String str = (String)res[:n];
|
||||
|
||||
assert(str == "ipsum sit.", "got '%s'; want 'ipsum sit.'", str);
|
||||
|
||||
@@ -75,13 +75,13 @@ fn void write_short_bytearray_test()
|
||||
fn void read_tiny_bytearray_test()
|
||||
{
|
||||
ByteReader reader = io::wrap_bytes(&&x'07aabbcc00112233');
|
||||
char[] read = io::read_tiny_bytearray(&reader, allocator: allocator::heap())!;
|
||||
char[] read = io::read_tiny_bytearray(&reader, allocator: allocator::heap())!!;
|
||||
assert(read == &&x'aabbcc00112233');
|
||||
}
|
||||
|
||||
fn void read_short_bytearray_test()
|
||||
{
|
||||
ByteReader reader = io::wrap_bytes(&&x'0007aabbcc00112233');
|
||||
char[] read = io::read_short_bytearray(&reader, allocator: allocator::heap())!;
|
||||
char[] read = io::read_short_bytearray(&reader, allocator: allocator::heap())!!;
|
||||
assert(read == &&x'aabbcc00112233');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module std::io @test;
|
||||
|
||||
fn void! test_teereader()
|
||||
fn void test_teereader()
|
||||
{
|
||||
String want = "foobar";
|
||||
|
||||
@@ -8,7 +8,7 @@ fn void! test_teereader()
|
||||
TeeReader r = tee_reader(ByteReader{}.init(want), w.temp_init());
|
||||
|
||||
char[16] buf;
|
||||
usz n = r.read(buf[..])!;
|
||||
usz n = r.read(buf[..])!!;
|
||||
|
||||
String got = w.str_view();
|
||||
assert(n == want.len, "teereader: invalid length");
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
module std::io::varint @test;
|
||||
import std::io;
|
||||
|
||||
fn void! write_read()
|
||||
fn void write_read()
|
||||
{
|
||||
ByteBuffer buf;
|
||||
buf.temp_init(16)!;
|
||||
buf.temp_init(16)!!;
|
||||
usz n;
|
||||
uint x;
|
||||
uint y;
|
||||
|
||||
n = io::write_varint(&buf, 123)!;
|
||||
n = io::write_varint(&buf, 123)!!;
|
||||
assert(n == 1, "got %d; want 1", n);
|
||||
io::read_varint(&buf, &y)!;
|
||||
io::read_varint(&buf, &y)!!;
|
||||
assert(y == 123, "got %d; want 123", y);
|
||||
|
||||
n = io::write_varint(&buf, 123456789)!;
|
||||
n = io::write_varint(&buf, 123456789)!!;
|
||||
assert(n == 4, "got %d; want 4", n);
|
||||
io::read_varint(&buf, &y)!;
|
||||
io::read_varint(&buf, &y)!!;
|
||||
assert(y == 123456789, "got %d; want 123456789", y);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ struct VarIntTest
|
||||
char[] bytes;
|
||||
}
|
||||
|
||||
fn void! samples()
|
||||
fn void samples()
|
||||
{
|
||||
VarIntTest[] tcases = {
|
||||
{ 0, { 0x00 } },
|
||||
@@ -46,7 +46,7 @@ fn void! samples()
|
||||
{
|
||||
ByteWriter bw;
|
||||
bw.temp_init();
|
||||
usz n = io::write_varint(&bw, tc.in)!;
|
||||
usz n = io::write_varint(&bw, tc.in)!!;
|
||||
assert(n == tc.bytes.len, "got %d; want %d", n, tc.bytes.len);
|
||||
char[] bytes = bw.bytes[:bw.index];
|
||||
assert(bytes == tc.bytes, "got %d; want %d", bytes, tc.bytes);
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
module core_builtin_tests;
|
||||
|
||||
fn void! test_likely() @test
|
||||
fn void test_likely() @test
|
||||
{
|
||||
assert(@likely(2 > 1));
|
||||
assert(@likely(2 > 1, 0.5));
|
||||
}
|
||||
|
||||
fn void! test_unlikely() @test
|
||||
fn void test_unlikely() @test
|
||||
{
|
||||
assert(!@unlikely(2 < 1));
|
||||
assert(!@unlikely(2 < 1, 0.5));
|
||||
}
|
||||
|
||||
fn void! test_expect() @test
|
||||
fn void test_expect() @test
|
||||
{
|
||||
assert(@expect(2 > 1, true));
|
||||
assert(!@expect(2 < 1, false));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module math_tests;
|
||||
import std::math;
|
||||
|
||||
fn void! test_abs() @test
|
||||
fn void test_abs() @test
|
||||
{
|
||||
int x = -21;
|
||||
assert(math::abs(x) == 21);
|
||||
@@ -16,7 +16,7 @@ fn void! test_abs() @test
|
||||
assert(math::abs(yy) == double[<3>] { 1, 0.5, 1000 });
|
||||
}
|
||||
|
||||
fn void! test_acos() @test
|
||||
fn void test_acos() @test
|
||||
{
|
||||
int [<5>] in = { 231, -231, 1, 0, -1 };
|
||||
double [<3>] out = { 0., math::PI_2, math::PI };
|
||||
@@ -54,7 +54,7 @@ fn void! test_acos() @test
|
||||
}
|
||||
|
||||
|
||||
fn void! test_acosh() @test
|
||||
fn void test_acosh() @test
|
||||
{
|
||||
int [<5>] in = { 0, -1, 1, 2, 231 };
|
||||
double [<3>] out = { 0., 1.3169578969248166, 6.135560205979194 };
|
||||
@@ -79,7 +79,7 @@ fn void! test_acosh() @test
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_asin() @test
|
||||
fn void test_asin() @test
|
||||
{
|
||||
int [<5>] in = { 231, -231, 1, 0, -1 };
|
||||
double [<3>] out = { math::PI_2, 0., -math::PI_2 };
|
||||
@@ -113,7 +113,7 @@ fn void! test_asin() @test
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_asinh() @test
|
||||
fn void test_asinh() @test
|
||||
{
|
||||
int [<5>] in = { 231, 1, 0, -1, -231 };
|
||||
double [<5>] out = { 6.135569576118435, 0.881373587019543, 0., -0.881373587019543, -6.135569576118435 };
|
||||
@@ -131,7 +131,7 @@ fn void! test_asinh() @test
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_atan() @test
|
||||
fn void test_atan() @test
|
||||
{
|
||||
int [<9>] in = { 231, 3, 2, 1, 0, -1, -2, -3, -231 };
|
||||
double [<9>] out = { 1.5664673495078372, 1.2490457723982544, 1.1071487177940904, math::PI_4, 0., -math::PI_4, -1.1071487177940904, -1.2490457723982544, -1.5664673495078372 };
|
||||
@@ -158,7 +158,7 @@ fn void! test_atan() @test
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_atanh() @test
|
||||
fn void test_atanh() @test
|
||||
{
|
||||
int [<4>] in = { 231, -231, 1, -1 };
|
||||
double [<6>] in2 = {0.8, 0.5, 0.3, -0.3, -0.5, -0.8 };
|
||||
@@ -190,7 +190,7 @@ fn void! test_atanh() @test
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_ceil() @test
|
||||
fn void test_ceil() @test
|
||||
{
|
||||
double d = -123.1;
|
||||
assert(math::ceil(d) == -123.0);
|
||||
@@ -214,7 +214,7 @@ fn void! test_ceil() @test
|
||||
assert(math::ceil(vec) == double[<5>] { -123, 124, 1, 0, 0 });
|
||||
}
|
||||
|
||||
fn void! test_cos() @test
|
||||
fn void test_cos() @test
|
||||
{
|
||||
int [<5>] in = { 231, 1, 0, -1, -231 };
|
||||
double [<5>] out = { 0.09280621889587707, 0.54030230586813972 , 1., 0.54030230586813972, 0.09280621889587707 };
|
||||
@@ -243,7 +243,7 @@ fn void! test_cos() @test
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_exp() @test
|
||||
fn void test_exp() @test
|
||||
{
|
||||
int [<5>] in = { 2, 1, 0, -1, -2 };
|
||||
double [<5>] out = { 7.38905609893065, math::E , 1., 0.36787944117144233, 0.1353352832366127 };
|
||||
@@ -272,7 +272,7 @@ fn void! test_exp() @test
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_floor() @test
|
||||
fn void test_floor() @test
|
||||
{
|
||||
double d = -123.1;
|
||||
assert(math::floor(d) == -124.0);
|
||||
@@ -296,7 +296,7 @@ fn void! test_floor() @test
|
||||
assert(math::floor(vec) == double[<5>] { -124, 123, 0, -1, 0 });
|
||||
}
|
||||
|
||||
fn void! test_log() @test
|
||||
fn void test_log() @test
|
||||
{
|
||||
double x = math::E;
|
||||
assert(math::log(x, x) == 1.0);
|
||||
@@ -309,7 +309,7 @@ fn void! test_log() @test
|
||||
assert(math::log(yy, 10) == float[<3>] { 1.0, 2.0, 3.0 });
|
||||
}
|
||||
|
||||
fn void! test_sign() @test
|
||||
fn void test_sign() @test
|
||||
{
|
||||
int x = -21;
|
||||
assert(math::sign(x) == -1);
|
||||
@@ -327,7 +327,7 @@ fn void! test_sign() @test
|
||||
}
|
||||
|
||||
|
||||
fn void! test_sin() @test
|
||||
fn void test_sin() @test
|
||||
{
|
||||
int [<5>] in = { 231, 1, 0, -1, -231 };
|
||||
double [<5>] out = { -0.99568418975810324, 0.84147098480789651 , 0., -0.84147098480789651, 0.99568418975810324 };
|
||||
@@ -356,7 +356,7 @@ fn void! test_sin() @test
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_tan() @test
|
||||
fn void test_tan() @test
|
||||
{
|
||||
int [<5>] in = { 231, 1, 0, -1, -231 };
|
||||
double [<5>] out = { -10.7286365246191129, 1.5574077246549022 , 0., -1.5574077246549022, 10.7286365246191129 };
|
||||
@@ -385,7 +385,7 @@ fn void! test_tan() @test
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_trunc() @test
|
||||
fn void test_trunc() @test
|
||||
{
|
||||
double d = -123.9;
|
||||
assert(math::trunc(d) == -123.0);
|
||||
@@ -409,7 +409,7 @@ fn void! test_trunc() @test
|
||||
assert(math::trunc(vec) == double[<5>] { -123, 123, 0, 0, 0 });
|
||||
}
|
||||
|
||||
fn void! test_round_decimals() @test
|
||||
fn void test_round_decimals() @test
|
||||
{
|
||||
double d = 0.532451241142;
|
||||
float d_f = 0.532451241142;
|
||||
@@ -420,7 +420,7 @@ fn void! test_round_decimals() @test
|
||||
assert(math::round_to_decimals(d_f, 5) == 0.53245f);
|
||||
}
|
||||
|
||||
fn void! test() @test
|
||||
fn void test() @test
|
||||
{
|
||||
double radians = math::deg_to_rad(45);
|
||||
float radians_f = (float)math::deg_to_rad(45);
|
||||
@@ -429,7 +429,7 @@ fn void! test() @test
|
||||
assert(math::round_to_decimals(radians_f, 3) == 0.785f);
|
||||
}
|
||||
|
||||
fn void! test_muldiv()
|
||||
fn void test_muldiv()
|
||||
{
|
||||
char a = 20;
|
||||
assert(a.muldiv(20, 10) == 40);
|
||||
@@ -459,7 +459,7 @@ fn void! test_muldiv()
|
||||
assert(k.muldiv(20,-10) == ichar[<4>]{-40,-60,-80,-100});
|
||||
}
|
||||
|
||||
fn void! test_gcd() @test
|
||||
fn void test_gcd() @test
|
||||
{
|
||||
assert(math::gcd(20,15) == 5);
|
||||
assert(math::gcd(15,20) == 5);
|
||||
@@ -471,7 +471,7 @@ fn void! test_gcd() @test
|
||||
assert(math::gcd(2,4,6,8) == 2);
|
||||
}
|
||||
|
||||
fn void! test_lcm() @test
|
||||
fn void test_lcm() @test
|
||||
{
|
||||
assert(math::lcm(4,5) == 20);
|
||||
assert(math::lcm(6,10) == 30);
|
||||
|
||||
@@ -9,14 +9,14 @@ import std::math;
|
||||
|
||||
def ComplexType = Complex(<ElementType>);
|
||||
|
||||
fn void! complex_mul_imaginary()
|
||||
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}));
|
||||
}
|
||||
|
||||
fn void! complex_add()
|
||||
fn void complex_add()
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
ComplexType b = {1, 2};
|
||||
@@ -24,7 +24,7 @@ fn void! complex_add()
|
||||
assert(a.add_each(1).equals(ComplexType{4, 5}));
|
||||
}
|
||||
|
||||
fn void! complex_sub()
|
||||
fn void complex_sub()
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
ComplexType b = {1, 2};
|
||||
@@ -32,25 +32,25 @@ fn void! complex_sub()
|
||||
assert(a.sub_each(1).equals(ComplexType{2, 3}));
|
||||
}
|
||||
|
||||
fn void! complex_scale()
|
||||
fn void complex_scale()
|
||||
{
|
||||
ComplexType a = {2, 1};
|
||||
assert(a.scale(2).equals(ComplexType{4, 2}));
|
||||
}
|
||||
|
||||
fn void! complex_conjugate()
|
||||
fn void complex_conjugate()
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
assert(a.conjugate().equals(ComplexType{3, -4}));
|
||||
}
|
||||
|
||||
fn void! complex_inverse() @if(types::is_float(ElementType))
|
||||
fn void complex_inverse() @if(types::is_float(ElementType))
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
assert(a.inverse().mul(a).equals(complex::IDENTITY(<ElementType>)));
|
||||
}
|
||||
|
||||
fn void! complex_div() @if(types::is_float(ElementType))
|
||||
fn void complex_div() @if(types::is_float(ElementType))
|
||||
{
|
||||
ComplexType a = {2, 5};
|
||||
ComplexType b = {4, -1};
|
||||
|
||||
@@ -16,7 +16,7 @@ macro test(start, ...)
|
||||
$endfor;
|
||||
}
|
||||
|
||||
fn void! tests() @test
|
||||
fn void tests() @test
|
||||
{
|
||||
test(0, char, ushort, uint, ulong, uptr, usz, uint128);
|
||||
test(-4, ichar, short, int, long, iptr, isz, int128);
|
||||
|
||||
@@ -106,10 +106,10 @@ fn void test_mat2()
|
||||
assert(calc.m == value.m);
|
||||
}
|
||||
|
||||
fn void! test_mat2_inverse()
|
||||
fn void test_mat2_inverse()
|
||||
{
|
||||
Matrix2 a = { 3, 5, 6, 2 };
|
||||
Matrix2 a_inv = a.inverse()!;
|
||||
Matrix2 a_inv = a.inverse()!!;
|
||||
double sum = ((double[<4>])a_inv.mul(a).m).sum();
|
||||
assert(math::abs(sum - 2.0) < math::FLOAT_EPSILON,
|
||||
"wrong inverse: sum of all elements should be 2, but got: %g", sum);
|
||||
|
||||
@@ -57,12 +57,12 @@ fn String inner4(String s, Allocator a)
|
||||
};
|
||||
}
|
||||
|
||||
fn void! test_temp_allocator() @test
|
||||
fn void test_temp_allocator() @test
|
||||
{
|
||||
assert("foofoofoofoofoofooabcaaaaaa" == add("abc", allocator::temp(), 5), "was %s", add("abc", allocator::temp(), 5));
|
||||
}
|
||||
|
||||
fn void! test_temp_allocator2() @test
|
||||
fn void test_temp_allocator2() @test
|
||||
{
|
||||
assert("fooxyz0123456789xy**********" == breakit("xyz0123456789", allocator::temp()));
|
||||
}
|
||||
|
||||
@@ -9,30 +9,30 @@ fn void test_ipv4()
|
||||
|
||||
}
|
||||
|
||||
fn void! test_ipv4_to_string()
|
||||
fn void test_ipv4_to_string()
|
||||
{
|
||||
InetAddress a = net::ipv4_from_str("127.0.0.1")!;
|
||||
InetAddress a = net::ipv4_from_str("127.0.0.1")!!;
|
||||
assert(a.to_new_string() == "127.0.0.1");
|
||||
}
|
||||
|
||||
fn void! test_ipv6_to_string()
|
||||
fn void test_ipv6_to_string()
|
||||
{
|
||||
InetAddress a = net::ipv6_from_str("2001:db8::2:1")!;
|
||||
InetAddress a = net::ipv6_from_str("2001:db8::2:1")!!;
|
||||
a.to_new_string();
|
||||
assert(a.to_new_string() == "2001:0db8:0000:0000:0000:0000:0002:0001");
|
||||
assert(net::ipv6_from_str("2001:db8::1").to_new_string()! == "2001:0db8:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("::1").to_new_string()! == "0000:0000:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("2001::1").to_new_string()! == "2001:0000:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("2001:db8:1234::").to_new_string()! == "2001:0db8:1234:0000:0000:0000:0000:0000");
|
||||
assert(net::ipv6_from_str("2001::").to_new_string()! == "2001:0000:0000:0000:0000:0000:0000:0000");
|
||||
assert(net::ipv6_from_str("::").to_new_string()! == "0000:0000:0000:0000:0000:0000:0000:0000");
|
||||
assert(net::ipv6_from_str("2001:db8::1").to_new_string()!! == "2001:0db8:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("::1").to_new_string()!! == "0000:0000:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("2001::1").to_new_string()!! == "2001:0000:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("2001:db8:1234::").to_new_string()!! == "2001:0db8:1234:0000:0000:0000:0000:0000");
|
||||
assert(net::ipv6_from_str("2001::").to_new_string()!! == "2001:0000:0000:0000:0000:0000:0000:0000");
|
||||
assert(net::ipv6_from_str("::").to_new_string()!! == "0000:0000:0000:0000:0000:0000:0000:0000");
|
||||
}
|
||||
|
||||
fn void! test_ipv4_parse()
|
||||
fn void test_ipv4_parse()
|
||||
{
|
||||
InetAddress a = net::ipv4_from_str("127.0.0.1")!;
|
||||
InetAddress a = net::ipv4_from_str("127.0.0.1")!!;
|
||||
assert(a.ipv4.a == 127 && a.ipv4.b == 0 && a.ipv4.c == 0 && a.ipv4.d == 1);
|
||||
a = net::ipv4_from_str("255.254.253.255")!;
|
||||
a = net::ipv4_from_str("255.254.253.255")!!;
|
||||
assert(a.ipv4.a == 255 && a.ipv4.b == 254 && a.ipv4.c == 253 && a.ipv4.d == 255);
|
||||
assert(@catch(net::ipv4_from_str(".1.1.1.1")));
|
||||
assert(@catch(net::ipv4_from_str("1..1.1")));
|
||||
|
||||
@@ -5,9 +5,9 @@ import std::net::url;
|
||||
|
||||
// Parser tests
|
||||
|
||||
fn void! test_parse_foo()
|
||||
fn void test_parse_foo()
|
||||
{
|
||||
Url url = url::parse("foo://example.com:8042/over/there?name=ferret#nose")!;
|
||||
Url url = url::parse("foo://example.com:8042/over/there?name=ferret#nose")!!;
|
||||
|
||||
assert(url.scheme == "foo", "got '%s'", url.scheme);
|
||||
assert(url.host == "example.com", "got '%s'", url.host);
|
||||
@@ -19,9 +19,9 @@ fn void! test_parse_foo()
|
||||
assert(url.fragment == "nose", "got: '%s'", url.fragment);
|
||||
}
|
||||
|
||||
fn void! test_parse_urn()
|
||||
fn void test_parse_urn()
|
||||
{
|
||||
Url url = url::parse("urn:example:animal:ferret:nose")!;
|
||||
Url url = url::parse("urn:example:animal:ferret:nose")!!;
|
||||
|
||||
assert(url.scheme == "urn");
|
||||
assert(url.host == "");
|
||||
@@ -33,9 +33,9 @@ fn void! test_parse_urn()
|
||||
assert(url.fragment == "");
|
||||
}
|
||||
|
||||
fn void! test_parse_jdbc()
|
||||
fn void test_parse_jdbc()
|
||||
{
|
||||
Url url = url::parse("jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true")!;
|
||||
Url url = url::parse("jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true")!!;
|
||||
|
||||
assert(url.scheme == "jdbc:mysql");
|
||||
assert(url.host == "localhost");
|
||||
@@ -47,9 +47,9 @@ fn void! test_parse_jdbc()
|
||||
assert(url.fragment == "");
|
||||
}
|
||||
|
||||
fn void! test_parse_ftp()
|
||||
fn void test_parse_ftp()
|
||||
{
|
||||
Url url = url::parse("ftp://ftp.is.co.za/rfc/rfc1808.txt")!;
|
||||
Url url = url::parse("ftp://ftp.is.co.za/rfc/rfc1808.txt")!!;
|
||||
|
||||
assert(url.scheme == "ftp");
|
||||
assert(url.host == "ftp.is.co.za");
|
||||
@@ -61,9 +61,9 @@ fn void! test_parse_ftp()
|
||||
assert(url.fragment == "");
|
||||
}
|
||||
|
||||
fn void! test_parse_http()
|
||||
fn void test_parse_http()
|
||||
{
|
||||
Url url = url::parse("http://www.ietf.org/rfc/rfc2396.txt#header1")!;
|
||||
Url url = url::parse("http://www.ietf.org/rfc/rfc2396.txt#header1")!!;
|
||||
|
||||
assert(url.scheme == "http");
|
||||
assert(url.host == "www.ietf.org");
|
||||
@@ -75,9 +75,9 @@ fn void! test_parse_http()
|
||||
assert(url.fragment == "header1");
|
||||
}
|
||||
|
||||
fn void! test_parse_ldap()
|
||||
fn void test_parse_ldap()
|
||||
{
|
||||
Url url = url::parse("ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two")!;
|
||||
Url url = url::parse("ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two")!!;
|
||||
|
||||
assert(url.scheme == "ldap");
|
||||
assert(url.host == "[2001:db8::7]");
|
||||
@@ -89,9 +89,9 @@ fn void! test_parse_ldap()
|
||||
assert(url.fragment == "");
|
||||
}
|
||||
|
||||
fn void! test_parse_mailto()
|
||||
fn void test_parse_mailto()
|
||||
{
|
||||
Url url = url::parse("mailto:John.Doe@example.com")!;
|
||||
Url url = url::parse("mailto:John.Doe@example.com")!!;
|
||||
|
||||
assert(url.scheme == "mailto");
|
||||
assert(url.host == "");
|
||||
@@ -103,9 +103,9 @@ fn void! test_parse_mailto()
|
||||
assert(url.fragment == "");
|
||||
}
|
||||
|
||||
fn void! test_parse_news()
|
||||
fn void test_parse_news()
|
||||
{
|
||||
Url url = url::parse("news:comp.infosystems.www.servers.unix")!;
|
||||
Url url = url::parse("news:comp.infosystems.www.servers.unix")!!;
|
||||
|
||||
assert(url.scheme == "news");
|
||||
assert(url.host == "");
|
||||
@@ -117,9 +117,9 @@ fn void! test_parse_news()
|
||||
assert(url.fragment == "");
|
||||
}
|
||||
|
||||
fn void! test_parse_tel()
|
||||
fn void test_parse_tel()
|
||||
{
|
||||
Url url = url::parse("tel:+1-816-555-1212")!;
|
||||
Url url = url::parse("tel:+1-816-555-1212")!!;
|
||||
|
||||
assert(url.scheme == "tel");
|
||||
assert(url.host == "");
|
||||
@@ -131,9 +131,9 @@ fn void! test_parse_tel()
|
||||
assert(url.fragment == "");
|
||||
}
|
||||
|
||||
fn void! test_parse_telnet()
|
||||
fn void test_parse_telnet()
|
||||
{
|
||||
Url url = url::parse("telnet://192.0.2.16:80/")!;
|
||||
Url url = url::parse("telnet://192.0.2.16:80/")!!;
|
||||
|
||||
assert(url.scheme == "telnet");
|
||||
assert(url.host == "192.0.2.16");
|
||||
@@ -145,9 +145,9 @@ fn void! test_parse_telnet()
|
||||
assert(url.fragment == "");
|
||||
}
|
||||
|
||||
fn void! test_parse_urn2()
|
||||
fn void test_parse_urn2()
|
||||
{
|
||||
Url url = url::parse("urn:oasis:names:specification:docbook:dtd:xml:4.1.2")!;
|
||||
Url url = url::parse("urn:oasis:names:specification:docbook:dtd:xml:4.1.2")!!;
|
||||
|
||||
assert(url.scheme == "urn");
|
||||
assert(url.host == "");
|
||||
@@ -161,7 +161,7 @@ fn void! test_parse_urn2()
|
||||
|
||||
fn void test_parse_empty()
|
||||
{
|
||||
Url url = url::parse(" ")!;
|
||||
Url url = url::parse(" ")!!;
|
||||
|
||||
assert(url.scheme == "");
|
||||
assert(url.host == "");
|
||||
@@ -175,7 +175,7 @@ fn void test_parse_empty()
|
||||
|
||||
// to_string() tests
|
||||
|
||||
fn void! test_string_foo()
|
||||
fn void test_string_foo()
|
||||
{
|
||||
Url url = {.scheme="foo", .host="example.com", .port=8042, .path="/over/there", .query="name=ferret", .fragment="nose"};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -183,7 +183,7 @@ fn void! test_string_foo()
|
||||
assert(str == "foo://example.com:8042/over/there?name=ferret#nose");
|
||||
}
|
||||
|
||||
fn void! test_string_urn()
|
||||
fn void test_string_urn()
|
||||
{
|
||||
Url url = {.scheme="urn", .path="example:animal:ferret:nose"};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -191,7 +191,7 @@ fn void! test_string_urn()
|
||||
assert(str == "urn:example:animal:ferret:nose");
|
||||
}
|
||||
|
||||
fn void! test_string_jdbc()
|
||||
fn void test_string_jdbc()
|
||||
{
|
||||
Url url = {.scheme="jdbc:mysql", .host="localhost", .port=3306, .username="test_user", .password="ouupppssss", .path="/sakila", .query="profileSQL=true"};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -199,7 +199,7 @@ fn void! test_string_jdbc()
|
||||
assert(str == "jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true");
|
||||
}
|
||||
|
||||
fn void! test_string_ftp()
|
||||
fn void test_string_ftp()
|
||||
{
|
||||
Url url = {.scheme="ftp", .host="ftp.is.co.za", .path="/rfc/rfc1808.txt"};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -207,7 +207,7 @@ fn void! test_string_ftp()
|
||||
assert(str == "ftp://ftp.is.co.za/rfc/rfc1808.txt");
|
||||
}
|
||||
|
||||
fn void! test_string_http()
|
||||
fn void test_string_http()
|
||||
{
|
||||
Url url = {.scheme="http", .host="www.ietf.org", .path="/rfc/rfc2396.txt#header1"};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -215,7 +215,7 @@ fn void! test_string_http()
|
||||
assert(str == "http://www.ietf.org/rfc/rfc2396.txt#header1");
|
||||
}
|
||||
|
||||
fn void! test_string_ldap()
|
||||
fn void test_string_ldap()
|
||||
{
|
||||
Url url = {.scheme="ldap", .host="[2001:db8::7]", .path="/c=GB?objectClass=one&objectClass=two"};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -223,7 +223,7 @@ fn void! test_string_ldap()
|
||||
assert(str == "ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two");
|
||||
}
|
||||
|
||||
fn void! test_string_mailto()
|
||||
fn void test_string_mailto()
|
||||
{
|
||||
Url url = {.scheme="mailto", .path="John.Doe@example.com"};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -231,14 +231,14 @@ fn void! test_string_mailto()
|
||||
assert(str == "mailto:John.Doe@example.com");
|
||||
}
|
||||
|
||||
fn void! test_string_news()
|
||||
fn void test_string_news()
|
||||
{
|
||||
Url url = {.scheme="news", .path="comp.infosystems.www.servers.unix"};
|
||||
String str = string::new_format("%s", url);
|
||||
assert(str == "news:comp.infosystems.www.servers.unix");
|
||||
}
|
||||
|
||||
fn void! test_string_tel()
|
||||
fn void test_string_tel()
|
||||
{
|
||||
Url url = {.scheme="tel", .path="+1-816-555-1212"};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -246,7 +246,7 @@ fn void! test_string_tel()
|
||||
assert(str == "tel:+1-816-555-1212");
|
||||
}
|
||||
|
||||
fn void! test_string_telnet()
|
||||
fn void test_string_telnet()
|
||||
{
|
||||
Url url = {.scheme="telnet", .host="192.0.2.16", .port=80, .path="/"};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -254,7 +254,7 @@ fn void! test_string_telnet()
|
||||
assert(str == "telnet://192.0.2.16:80/");
|
||||
}
|
||||
|
||||
fn void! test_string_urn2()
|
||||
fn void test_string_urn2()
|
||||
{
|
||||
Url url = {.scheme="urn", .path="oasis:names:specification:docbook:dtd:xml:4.1.2"};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -262,7 +262,7 @@ fn void! test_string_urn2()
|
||||
assert(str == "urn:oasis:names:specification:docbook:dtd:xml:4.1.2");
|
||||
}
|
||||
|
||||
fn void! test_string_empty()
|
||||
fn void test_string_empty()
|
||||
{
|
||||
Url url = {};
|
||||
String str = string::new_format("%s", url);
|
||||
@@ -272,41 +272,41 @@ fn void! test_string_empty()
|
||||
|
||||
// query_values
|
||||
|
||||
fn void! test_query_values1()
|
||||
fn void test_query_values1()
|
||||
{
|
||||
Url url = url::parse("foo://example.com:8042/over/there?name=ferret=ok#nose")!;
|
||||
Url url = url::parse("foo://example.com:8042/over/there?name=ferret=ok#nose")!!;
|
||||
|
||||
UrlQueryValues vals = url.new_query_values();
|
||||
defer vals.free();
|
||||
|
||||
assert(vals.len() == 1);
|
||||
UrlQueryValueList l = vals["name"]!;
|
||||
UrlQueryValueList l = vals["name"]!!;
|
||||
|
||||
assert(l.len() == 1);
|
||||
assert(l[0] == "ferret=ok");
|
||||
}
|
||||
|
||||
fn void! test_query_values2()
|
||||
fn void test_query_values2()
|
||||
{
|
||||
Url url = url::parse("foo://example.com:8042/over/there?name=ferret&age=99&age=11#nose")!;
|
||||
Url url = url::parse("foo://example.com:8042/over/there?name=ferret&age=99&age=11#nose")!!;
|
||||
|
||||
UrlQueryValues vals = url.new_query_values();
|
||||
defer vals.free();
|
||||
assert(vals.len() == 2);
|
||||
|
||||
UrlQueryValueList l_name = vals["name"]!;
|
||||
UrlQueryValueList l_name = vals["name"]!!;
|
||||
assert(l_name.len() == 1);
|
||||
assert(l_name[0] == "ferret");
|
||||
|
||||
UrlQueryValueList l_age = vals["age"]!;
|
||||
UrlQueryValueList l_age = vals["age"]!!;
|
||||
assert(l_age.len() == 2);
|
||||
assert(l_age[0] == "99");
|
||||
assert(l_age[1] == "11");
|
||||
}
|
||||
|
||||
fn void! test_query_values_withempty()
|
||||
fn void test_query_values_withempty()
|
||||
{
|
||||
Url url = url::parse("foo://example.com:8042/over/there?name=ferret&&&age=99&age=11")!;
|
||||
Url url = url::parse("foo://example.com:8042/over/there?name=ferret&&&age=99&age=11")!!;
|
||||
|
||||
UrlQueryValues vals = url.new_query_values();
|
||||
defer vals.free();
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
module std::os::env @test;
|
||||
|
||||
fn void! set_get_unset()
|
||||
fn void set_get_unset()
|
||||
{
|
||||
const NAME = "C3_TEST_ENVVAR";
|
||||
const VALUE = "foobar";
|
||||
|
||||
env::set_var(NAME, VALUE);
|
||||
String v = env::get_var(NAME)!;
|
||||
String v = env::get_var(NAME)!!;
|
||||
assert(v == VALUE, "got %s; want %s", v, VALUE);
|
||||
|
||||
env::clear_var(NAME);
|
||||
|
||||
@@ -8,7 +8,7 @@ struct TestCase @local
|
||||
int want;
|
||||
}
|
||||
|
||||
fn void! quickselect()
|
||||
fn void quickselect()
|
||||
{
|
||||
TestCase[] tcases = {
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module string_test;
|
||||
|
||||
fn void! test_clear() @test
|
||||
fn void test_clear() @test
|
||||
{
|
||||
DString s = dstring::new_with_capacity(32);
|
||||
assert(s.len() == 0);
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
module string_to_float_tests;
|
||||
|
||||
fn void! test_float() @test
|
||||
fn void test_float() @test
|
||||
{
|
||||
assert(String.to_float("1.2")! == 1.2f);
|
||||
assert(String.to_float("10")! == 10f);
|
||||
assert(String.to_float(".7647834")! == 0.7647834f);
|
||||
assert(String.to_float("0.213232")! == 0.213232f);
|
||||
assert(String.to_float("000001.487348")! == 000001.487348f);
|
||||
assert(String.to_float("3.54500000")! == 3.54500000f);
|
||||
assert(String.to_float("4.0")! == 4.0f);
|
||||
assert(String.to_float("-23.545")! == -23.545f);
|
||||
assert(String.to_float("1.5555555555555")! == 1.5555555555555f);
|
||||
assert(String.to_float("1.5555555555556666")! == 1.5555555555556666f);
|
||||
assert(String.to_float("1.2")!! == 1.2f);
|
||||
assert(String.to_float("10")!! == 10f);
|
||||
assert(String.to_float(".7647834")!! == 0.7647834f);
|
||||
assert(String.to_float("0.213232")!! == 0.213232f);
|
||||
assert(String.to_float("000001.487348")!! == 000001.487348f);
|
||||
assert(String.to_float("3.54500000")!! == 3.54500000f);
|
||||
assert(String.to_float("4.0")!! == 4.0f);
|
||||
assert(String.to_float("-23.545")!! == -23.545f);
|
||||
assert(String.to_float("1.5555555555555")!! == 1.5555555555555f);
|
||||
assert(String.to_float("1.5555555555556666")!! == 1.5555555555556666f);
|
||||
}
|
||||
|
||||
fn void! test_double() @test
|
||||
fn void test_double() @test
|
||||
{
|
||||
assert(String.to_double("1.2")! == 1.2);
|
||||
assert(String.to_double("10")! == 10);
|
||||
assert(String.to_double(".7647834")! == 0.7647834);
|
||||
assert(String.to_double("0.213232")! == 0.213232);
|
||||
assert(String.to_double("000001.487348")! == 000001.487348);
|
||||
assert(String.to_double("3.54500000")! == 3.54500000);
|
||||
assert(String.to_double("4.0")! == 4.0);
|
||||
assert(String.to_double("-23.545")! == -23.545);
|
||||
assert(String.to_double("1.5555555555555")! == 1.5555555555555);
|
||||
assert(String.to_double("1.5555555555556666")! == 1.5555555555556666);
|
||||
assert(String.to_double("1.2")!! == 1.2);
|
||||
assert(String.to_double("10")!! == 10);
|
||||
assert(String.to_double(".7647834")!! == 0.7647834);
|
||||
assert(String.to_double("0.213232")!! == 0.213232);
|
||||
assert(String.to_double("000001.487348")!! == 000001.487348);
|
||||
assert(String.to_double("3.54500000")!! == 3.54500000);
|
||||
assert(String.to_double("4.0")!! == 4.0);
|
||||
assert(String.to_double("-23.545")!! == -23.545);
|
||||
assert(String.to_double("1.5555555555555")!! == 1.5555555555555);
|
||||
assert(String.to_double("1.5555555555556666")!! == 1.5555555555556666);
|
||||
}
|
||||
@@ -6,55 +6,55 @@ import std::os;
|
||||
const TEST_MAGNITUDE = 10;
|
||||
|
||||
|
||||
fn void! lock_control_test() @test
|
||||
fn void lock_control_test() @test
|
||||
{
|
||||
Mutex m;
|
||||
m.init()!;
|
||||
m.lock()!;
|
||||
m.init()!!;
|
||||
m.lock()!!;
|
||||
assert(@catch(m.lock()));
|
||||
}
|
||||
|
||||
fn void! unlock_control_test() @test
|
||||
fn void unlock_control_test() @test
|
||||
{
|
||||
Mutex m;
|
||||
m.init()!;
|
||||
m.init()!!;
|
||||
assert(@catch(m.unlock()));
|
||||
}
|
||||
|
||||
fn void! lock_with_double_unlock_test() @test
|
||||
fn void lock_with_double_unlock_test() @test
|
||||
{
|
||||
Mutex m;
|
||||
m.init()!;
|
||||
m.init()!!;
|
||||
|
||||
m.lock()!;
|
||||
m.unlock()!;
|
||||
m.lock()!!;
|
||||
m.unlock()!!;
|
||||
assert(@catch(m.unlock()));
|
||||
}
|
||||
|
||||
fn void! own_mutex(Mutex* m)
|
||||
{
|
||||
m.lock()!!;
|
||||
m.unlock()!!;
|
||||
m.lock()!;
|
||||
m.unlock()!;
|
||||
}
|
||||
|
||||
fn void! ensure_owner_checks() @test
|
||||
fn void ensure_owner_checks() @test
|
||||
{
|
||||
Mutex m;
|
||||
m.init()!;
|
||||
m.init()!!;
|
||||
|
||||
Thread[3 * TEST_MAGNITUDE] threads;
|
||||
|
||||
foreach(&t : threads)
|
||||
{
|
||||
t.create((ThreadFn)&own_mutex, &m)!;
|
||||
t.create((ThreadFn)&own_mutex, &m)!!;
|
||||
}
|
||||
|
||||
foreach(&t : threads)
|
||||
{
|
||||
t.join()!;
|
||||
t.join()!!;
|
||||
}
|
||||
|
||||
own_mutex(&m)!;
|
||||
own_mutex(&m)!!;
|
||||
}
|
||||
|
||||
struct ArgsWrapper1
|
||||
@@ -77,11 +77,11 @@ fn void shared_mutex_decrement(ArgsWrapper1* args)
|
||||
args.m.unlock()!!;
|
||||
}
|
||||
|
||||
fn void! shared_mutex() @test
|
||||
fn void shared_mutex() @test
|
||||
{
|
||||
Mutex m;
|
||||
m.init()!;
|
||||
m.lock()!;
|
||||
m.init()!!;
|
||||
m.lock()!!;
|
||||
|
||||
ulong v;
|
||||
|
||||
@@ -95,24 +95,24 @@ fn void! shared_mutex() @test
|
||||
Thread[6 * TEST_MAGNITUDE] threads;
|
||||
for (int i = 0; i < threads.len / 2; i++)
|
||||
{
|
||||
(&threads[i]).create((ThreadFn)&shared_mutex_increment, &args)!;
|
||||
(&threads[i]).create((ThreadFn)&shared_mutex_increment, &args)!!;
|
||||
}
|
||||
for (int i = (threads.len / 2); i < threads.len; i++)
|
||||
{
|
||||
(&threads[i]).create((ThreadFn)&shared_mutex_decrement, &args)!;
|
||||
(&threads[i]).create((ThreadFn)&shared_mutex_decrement, &args)!!;
|
||||
}
|
||||
|
||||
m.unlock()!;
|
||||
m.unlock()!!;
|
||||
foreach(&t : threads)
|
||||
{
|
||||
t.join()!;
|
||||
t.join()!!;
|
||||
}
|
||||
assert(v == 0);
|
||||
}
|
||||
|
||||
// Recursive mutex
|
||||
|
||||
fn void! acquire_recursively(RecursiveMutex* m)
|
||||
fn void acquire_recursively(RecursiveMutex* m)
|
||||
{
|
||||
// TODO: The recursive mutex functions can not directly be called via pointer
|
||||
|
||||
@@ -127,21 +127,21 @@ fn void! acquire_recursively(RecursiveMutex* m)
|
||||
}
|
||||
}
|
||||
|
||||
fn void! test_recursive_mutex() @test
|
||||
fn void test_recursive_mutex() @test
|
||||
{
|
||||
RecursiveMutex m;
|
||||
m.init()!;
|
||||
m.init()!!;
|
||||
defer m.destroy()!!;
|
||||
|
||||
Thread[3 * TEST_MAGNITUDE] threads;
|
||||
foreach(&t : threads)
|
||||
{
|
||||
t.create((ThreadFn)&acquire_recursively, &m)!;
|
||||
t.create((ThreadFn)&acquire_recursively, &m)!!;
|
||||
}
|
||||
|
||||
foreach(&t : threads)
|
||||
{
|
||||
t.join()!;
|
||||
t.join()!!;
|
||||
}
|
||||
|
||||
return acquire_recursively(&m);
|
||||
|
||||
@@ -5,27 +5,27 @@ import std::thread::pool;
|
||||
|
||||
def Pool = ThreadPool(<4>);
|
||||
|
||||
fn void! init_destroy() @test
|
||||
fn void init_destroy() @test
|
||||
{
|
||||
for (usz i = 0; i < 20; i++)
|
||||
{
|
||||
Pool pool;
|
||||
pool.init()!;
|
||||
pool.destroy()!;
|
||||
pool.init()!!;
|
||||
pool.destroy()!!;
|
||||
}
|
||||
}
|
||||
|
||||
fn void! push_destroy() @test
|
||||
fn void push_destroy() @test
|
||||
{
|
||||
for FOO: (usz i = 0; i < 20; i++)
|
||||
{
|
||||
x = 0;
|
||||
int y = 20;
|
||||
Pool pool;
|
||||
pool.init()!;
|
||||
pool.init()!!;
|
||||
defer pool.destroy()!!;
|
||||
work_done.lock()!!;
|
||||
pool.push(&do_work, &y)!;
|
||||
pool.push(&do_work, &y)!!;
|
||||
work_done.unlock()!!;
|
||||
for (int j = 0; j < 1000; j++)
|
||||
{
|
||||
@@ -42,16 +42,16 @@ fn void! push_destroy() @test
|
||||
}
|
||||
}
|
||||
|
||||
fn void! push_stop() @test
|
||||
fn void push_stop() @test
|
||||
{
|
||||
for (usz i = 0; i < 20; i++)
|
||||
{
|
||||
x = 0;
|
||||
int y = 20;
|
||||
Pool pool;
|
||||
pool.init()!;
|
||||
pool.init()!!;
|
||||
work_done.lock()!!;
|
||||
pool.push(&do_work, &y)!;
|
||||
pool.push(&do_work, &y)!!;
|
||||
work_done.unlock()!!;
|
||||
pool.stop_and_destroy()!!;
|
||||
assert(x == y, "%d: %d != %d", i, x, y);
|
||||
|
||||
@@ -3,26 +3,26 @@ import std::io;
|
||||
|
||||
int a;
|
||||
|
||||
fn void! testrun() @test
|
||||
fn void testrun() @test
|
||||
{
|
||||
Thread t;
|
||||
a = 0;
|
||||
t.create(fn int(void* arg) { a++; return 0; }, null)!;
|
||||
assert(t.join()! == 0);
|
||||
t.create(fn int(void* arg) { a++; return 0; }, null)!!;
|
||||
assert(t.join()!! == 0);
|
||||
assert(a == 1);
|
||||
|
||||
t.create(fn int(void* arg) { return 10; }, null)!;
|
||||
assert(t.join()! == 10);
|
||||
t.create(fn int(void* arg) { return 10; }, null)!!;
|
||||
assert(t.join()!! == 10);
|
||||
}
|
||||
|
||||
|
||||
Mutex m_global;
|
||||
|
||||
fn void! testrun_mutex() @test
|
||||
fn void testrun_mutex() @test
|
||||
{
|
||||
Thread[20] ts;
|
||||
a = 0;
|
||||
m_global.init()!;
|
||||
m_global.init()!!;
|
||||
foreach (&t : ts)
|
||||
{
|
||||
t.create(fn int(void* arg) {
|
||||
@@ -38,39 +38,39 @@ fn void! testrun_mutex() @test
|
||||
thread::sleep_ms(5);
|
||||
a++;
|
||||
return 0;
|
||||
}, null)!;
|
||||
}, null)!!;
|
||||
}
|
||||
foreach (&t : ts)
|
||||
{
|
||||
assert(t.join()! == 0);
|
||||
assert(t.join()!! == 0);
|
||||
}
|
||||
assert(a == ts.len);
|
||||
m_global.destroy()!;
|
||||
m_global.destroy()!!;
|
||||
}
|
||||
|
||||
fn void! testrun_mutex_try() @test
|
||||
fn void testrun_mutex_try() @test
|
||||
{
|
||||
Mutex m;
|
||||
m.init()!;
|
||||
m.lock()!;
|
||||
m.init()!!;
|
||||
m.lock()!!;
|
||||
assert(m.try_lock() == false);
|
||||
m.unlock()!;
|
||||
m.unlock()!!;
|
||||
assert(m.try_lock() == true);
|
||||
m.unlock()!;
|
||||
m.unlock()!!;
|
||||
}
|
||||
|
||||
fn void! testrun_mutex_timeout() @test
|
||||
fn void testrun_mutex_timeout() @test
|
||||
{
|
||||
TimedMutex m;
|
||||
m.init()!;
|
||||
m.lock()!;
|
||||
m.init()!!;
|
||||
m.lock()!!;
|
||||
if (try m.lock_timeout(20))
|
||||
{
|
||||
unreachable("lock_timeout should fail");
|
||||
}
|
||||
m.unlock()!;
|
||||
m.lock_timeout(20)!;
|
||||
m.unlock()!;
|
||||
m.unlock()!!;
|
||||
m.lock_timeout(20)!!;
|
||||
m.unlock()!!;
|
||||
}
|
||||
|
||||
int x_once = 100;
|
||||
@@ -80,7 +80,7 @@ fn void call_once()
|
||||
x_once += 100;
|
||||
}
|
||||
|
||||
fn void! testrun_once() @test
|
||||
fn void testrun_once() @test
|
||||
{
|
||||
OnceFlag once;
|
||||
once.call(&call_once);
|
||||
|
||||
@@ -2,28 +2,28 @@ module nanoduration_test @test;
|
||||
import std::io;
|
||||
import std::time;
|
||||
|
||||
fn void! to_format()
|
||||
fn void to_format()
|
||||
{
|
||||
char[32] buffer;
|
||||
char[] buf;
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123)!;
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123)!!;
|
||||
assert(buf == "123ns", "got %s; want 123ns", buf);
|
||||
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123_000)!;
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123_000)!!;
|
||||
assert(buf == "123µs", "got %s; want 123µs", buf);
|
||||
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123_000_000)!;
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123_000_000)!!;
|
||||
assert(buf == "123ms", "got %s; want 123ms", buf);
|
||||
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)13_000_000_000)!;
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)13_000_000_000)!!;
|
||||
assert(buf == "13s", "got %s; want 13s", buf);
|
||||
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123_000_000_000)!;
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)123_000_000_000)!!;
|
||||
assert(buf == "2m3s", "got %s; want 2m3s", buf);
|
||||
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)12345_000_000_000)!;
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)12345_000_000_000)!!;
|
||||
assert(buf == "3h25m45s", "got %s; want 3h25m45s", buf);
|
||||
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)12_100_000_000)!;
|
||||
buf = io::bprintf(buffer[..], "%s", (NanoDuration)12_100_000_000)!!;
|
||||
assert(buf == "12.1s", "got %s; want 12.1s", buf);
|
||||
}
|
||||
Reference in New Issue
Block a user