mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
First 0.7 update, removing all deprecated features.
This commit is contained in:
committed by
Christoffer Lerno
parent
cff6697818
commit
2a895ec7be
@@ -4,7 +4,7 @@ struct Foo
|
||||
{
|
||||
int a;
|
||||
}
|
||||
def IntList = List(<Foo>);
|
||||
def IntList = List{Foo};
|
||||
fn void subscript_overload() @test
|
||||
{
|
||||
IntList x;
|
||||
|
||||
@@ -2,8 +2,8 @@ import std::thread;
|
||||
import std::io;
|
||||
import std::atomic::types;
|
||||
|
||||
def AtomicUint = Atomic(<uint>);
|
||||
def AtomicFloat = Atomic(<float>);
|
||||
def AtomicUint = Atomic{uint};
|
||||
def AtomicFloat = Atomic{float};
|
||||
AtomicUint a;
|
||||
AtomicFloat fa;
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import std::collections::growablebitset;
|
||||
import std::collections::list;
|
||||
import std::io;
|
||||
|
||||
def List = List(<usz>);
|
||||
def List = List{usz};
|
||||
|
||||
def BitSet = BitSet(<2048>);
|
||||
def BitSet = BitSet{2048};
|
||||
|
||||
fn void set_get()
|
||||
{
|
||||
@@ -24,7 +24,6 @@ fn void set_get()
|
||||
assert(bs.cardinality() == 2);
|
||||
|
||||
List found;
|
||||
found.tinit();
|
||||
foreach (i, x : bs)
|
||||
{
|
||||
switch (i)
|
||||
@@ -46,7 +45,7 @@ fn void set_get()
|
||||
assert(bs.cardinality() == 0);
|
||||
}
|
||||
|
||||
def GrowableBitSet = GrowableBitSet(<char>);
|
||||
def GrowableBitSet = GrowableBitSet{char};
|
||||
fn void growable_set_get()
|
||||
{
|
||||
GrowableBitSet bs;
|
||||
@@ -68,7 +67,6 @@ fn void growable_set_get()
|
||||
assert(bs.len() == 2001, "Len should be 2001");
|
||||
|
||||
List found;
|
||||
found.tinit();
|
||||
foreach (i, x : bs)
|
||||
{
|
||||
switch (i)
|
||||
|
||||
@@ -2,7 +2,7 @@ module test;
|
||||
import std::io;
|
||||
import std::collections::map;
|
||||
|
||||
def IntMap = HashMap(<String, int>);
|
||||
def IntMap = HashMap{String, int};
|
||||
fn void copy_map() @test
|
||||
{
|
||||
TrackingAllocator alloc;
|
||||
@@ -43,9 +43,8 @@ fn void copy_keys() @test
|
||||
@pool()
|
||||
{
|
||||
IntMap x;
|
||||
x.tinit();
|
||||
x.set("hello", 0); // keys copied into temp hashmap
|
||||
y = x.copy_keys(allocator::heap()); // keys copied out
|
||||
y = x.keys(mem); // keys copied out
|
||||
// end of pool: hashmap and its copied-in keys dropped
|
||||
};
|
||||
assert(y == {"hello"});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
module elastic_array_test @test;
|
||||
import std::collections::elastic_array;
|
||||
|
||||
def IntList = ElasticArray(<int, 10>);
|
||||
def PtrList = ElasticArray(<void*, 10>);
|
||||
def IntList = ElasticArray{int, 10};
|
||||
def PtrList = ElasticArray{void*, 10};
|
||||
|
||||
fn void delete_contains_index()
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ enum FooEnum
|
||||
THREE,
|
||||
}
|
||||
|
||||
def FooEnumMap = EnumMap(<FooEnum, uint>);
|
||||
def FooEnumMap = EnumMap{FooEnum, uint};
|
||||
|
||||
fn void enums()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module linkedlist_test @test;
|
||||
import std::collections::linkedlist;
|
||||
|
||||
def IntList = LinkedList(<int>);
|
||||
def IntList = LinkedList{int};
|
||||
|
||||
fn void test_push_front()
|
||||
{
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
module list_test @test;
|
||||
import std::collections::list;
|
||||
|
||||
def IntList = List(<int>);
|
||||
def PtrList = List(<void*>);
|
||||
def IntList = List{int};
|
||||
def PtrList = List{void*};
|
||||
|
||||
struct Overalign
|
||||
{
|
||||
float[<4>] x @align(128);
|
||||
}
|
||||
|
||||
def OveralignList = List(<Overalign>);
|
||||
def OveralignList = List{Overalign};
|
||||
fn void overaligned_type()
|
||||
{
|
||||
OveralignList l;
|
||||
@@ -24,7 +24,6 @@ fn void overaligned_type()
|
||||
fn void delete_contains_index()
|
||||
{
|
||||
IntList test;
|
||||
defer test.free();
|
||||
|
||||
test.add_array({ 1, 2 });
|
||||
assert(test.contains(1));
|
||||
@@ -55,7 +54,6 @@ fn void delete_contains_index()
|
||||
fn void compact()
|
||||
{
|
||||
PtrList test;
|
||||
defer test.free();
|
||||
test.add_array({ null, &test });
|
||||
assert(test.compact_count() == 1);
|
||||
test.push(null);
|
||||
@@ -69,7 +67,6 @@ fn void compact()
|
||||
fn void reverse()
|
||||
{
|
||||
IntList test;
|
||||
defer test.free();
|
||||
|
||||
test.reverse();
|
||||
test.add_array({ 1, 2 });
|
||||
@@ -86,7 +83,6 @@ fn void reverse()
|
||||
fn void remove_if()
|
||||
{
|
||||
IntList test;
|
||||
defer test.free();
|
||||
usz removed;
|
||||
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
@@ -104,8 +100,8 @@ fn void remove_if()
|
||||
fn void init_with_array()
|
||||
{
|
||||
IntList foo;
|
||||
defer foo.free();
|
||||
foo.init_with_array(mem, { 1, 2, 3});
|
||||
defer foo.free();
|
||||
assert(foo.len() == 3);
|
||||
assert(foo[2] == 3);
|
||||
}
|
||||
@@ -121,7 +117,6 @@ fn void init_with_temp_array()
|
||||
fn void remove_using_test()
|
||||
{
|
||||
IntList test;
|
||||
defer test.free();
|
||||
usz removed;
|
||||
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
@@ -139,7 +134,6 @@ fn void remove_using_test()
|
||||
fn void retain_if()
|
||||
{
|
||||
IntList test;
|
||||
defer test.free();
|
||||
usz removed;
|
||||
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
@@ -157,7 +151,6 @@ fn void retain_if()
|
||||
fn void retain_using_test()
|
||||
{
|
||||
IntList test;
|
||||
defer test.free();
|
||||
usz removed;
|
||||
|
||||
test.add_array({ 1, 11, 2, 10, 20 });
|
||||
|
||||
@@ -4,15 +4,14 @@ import std::collections::map;
|
||||
import std::sort;
|
||||
import std::io;
|
||||
|
||||
def TestHashMap = HashMap(<String, usz>);
|
||||
def TestMap = Map(<String, usz>);
|
||||
def TestHashMap = HashMap{String, usz};
|
||||
|
||||
struct MapTest
|
||||
{
|
||||
String key;
|
||||
usz value;
|
||||
}
|
||||
def List = List(<MapTest>);
|
||||
def List = List{MapTest};
|
||||
|
||||
fn void map()
|
||||
{
|
||||
@@ -56,7 +55,7 @@ fn void map()
|
||||
}
|
||||
}
|
||||
|
||||
def FooMap = HashMap(<char, Foobar>);
|
||||
def FooMap = HashMap{char, Foobar};
|
||||
enum Foobar : inline char
|
||||
{
|
||||
FOO,
|
||||
@@ -103,13 +102,4 @@ fn void map_copy()
|
||||
|
||||
assert(hash_map_copy.len() == hash_map.len());
|
||||
|
||||
TestMap map = map::temp(<String, usz>)();
|
||||
|
||||
map.set("aa", 1);
|
||||
map.set("b", 2);
|
||||
map.set("bb", 1);
|
||||
|
||||
TestMap map_copy = map::temp_from_map(<String, usz>)(map);
|
||||
|
||||
assert(map_copy.len() == map.len());
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ fn void test_to_format_int()
|
||||
{
|
||||
Object* int_object = object::new_int(16, allocator::heap());
|
||||
defer int_object.free();
|
||||
String s = string::new_format("%s", int_object);
|
||||
String s = string::format(mem, "%s", int_object);
|
||||
defer free(s);
|
||||
assert(s == "16");
|
||||
}
|
||||
{
|
||||
Object* int_object = object::new_int(-16, allocator::heap());
|
||||
defer int_object.free();
|
||||
String s = string::new_format("%s", int_object);
|
||||
String s = string::format(mem, "%s", int_object);
|
||||
defer free(s);
|
||||
assert(s == "-16");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ module priorityqueue_test @test;
|
||||
import std::collections;
|
||||
import std::collections::priorityqueue;
|
||||
|
||||
def Queue = PriorityQueue(<int>);
|
||||
def Queue = PriorityQueue{int};
|
||||
|
||||
fn void priorityqueue()
|
||||
{
|
||||
@@ -32,7 +32,7 @@ fn void priorityqueue()
|
||||
assert(x == 3, "got %d; want %d", x, 3);
|
||||
}
|
||||
|
||||
def QueueMax = PriorityQueueMax(<int>);
|
||||
def QueueMax = PriorityQueueMax{int};
|
||||
|
||||
fn void priorityqueue_max()
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
module range_test @test;
|
||||
import std::collections::range;
|
||||
|
||||
def IntRange = Range(<int>);
|
||||
def IntExRange = ExclusiveRange(<int>);
|
||||
def IntRange = Range{int};
|
||||
def IntExRange = ExclusiveRange{int};
|
||||
|
||||
fn void test_range()
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@ module ringbuffer_test @test;
|
||||
import std::collections::ringbuffer;
|
||||
import std::io;
|
||||
|
||||
def Buffer = RingBuffer(<char, 4>);
|
||||
def Buffer = RingBuffer{char[4]};
|
||||
|
||||
fn void push_get()
|
||||
{
|
||||
|
||||
@@ -15,20 +15,20 @@ fn void test_qoi_all()
|
||||
QOIDesc test_desc;
|
||||
|
||||
// decode the test data
|
||||
char[] decoded = qoi::new_decode(TEST_QOI_DATA[..], &test_desc)!!;
|
||||
char[] decoded = qoi::decode(mem, TEST_QOI_DATA[..], &test_desc)!!;
|
||||
defer free(decoded);
|
||||
|
||||
assert(test_desc.width == 340 && test_desc.height == 169, "Expected resolution of 340x169");
|
||||
|
||||
// encode the decoded data
|
||||
char[] encoded = qoi::new_encode(decoded, &test_desc)!!;
|
||||
char[] encoded = qoi::encode(mem, decoded, &test_desc)!!;
|
||||
assert(encoded == TEST_QOI_DATA[..], "Encoder output should match the test data");
|
||||
defer free(encoded);
|
||||
// encode and write the decoded data to a file
|
||||
usz written = qoi::write("unittest.qoi", decoded, &test_desc)!!;
|
||||
|
||||
// read and decode the written data
|
||||
char[] read = qoi::new_read("unittest.qoi", &test_desc)!!;
|
||||
char[] read = qoi::read(mem, "unittest.qoi", &test_desc)!!;
|
||||
assert(read == decoded, "Read data should match the decoded data");
|
||||
|
||||
// cleanup
|
||||
|
||||
@@ -21,12 +21,12 @@ fn void find_subarray()
|
||||
fn void concat()
|
||||
{
|
||||
int[3] a = { 1, 2, 3 };
|
||||
free(array::concat_new(a, a));
|
||||
free(array::concat_new(a[..], a[..]));
|
||||
free(array::concat_new(a[:0], a[:0]));
|
||||
free(array::concat_new((int[2]) { 1, 2 }, a[:0]));
|
||||
free(array::concat_new(a[:0], (int[2]) { 1, 2 }));
|
||||
int[] c = array::concat_new(a[1..2], a);
|
||||
free(array::concat(mem, a, a));
|
||||
free(array::concat(mem, a[..], a[..]));
|
||||
free(array::concat(mem, a[:0], a[:0]));
|
||||
free(array::concat(mem, (int[2]) { 1, 2 }, a[:0]));
|
||||
free(array::concat(mem, a[:0], (int[2]) { 1, 2 }));
|
||||
int[] c = array::concat(mem, a[1..2], a);
|
||||
defer free(c);
|
||||
assert (c == (int[]){ 2, 3, 1, 2, 3 });
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ const TEST_STRING = "hello world";
|
||||
|
||||
fn void test_replace()
|
||||
{
|
||||
DString hello = dstring::new("Hello world where are you? Are you here too?");
|
||||
DString hello = dstring::new(mem, "Hello world where are you? Are you here too?");
|
||||
defer hello.free();
|
||||
hello.replace("u", "ooo");
|
||||
assert(hello.str_view() == "Hello world where are yoooo? Are yoooo here too?");
|
||||
@@ -51,7 +51,7 @@ fn void test_delete()
|
||||
|
||||
fn void test_append()
|
||||
{
|
||||
DString str = dstring::new(TEST_STRING);
|
||||
DString str = dstring::new(mem, TEST_STRING);
|
||||
defer str.free();
|
||||
String s;
|
||||
|
||||
@@ -105,7 +105,7 @@ fn void test_append()
|
||||
s = str.str_view();
|
||||
assert(s == "xxx", "got '%s'; want 'xxx'", s);
|
||||
|
||||
DString str2 = dstring::new("yyy");
|
||||
DString str2 = dstring::new(mem, "yyy");
|
||||
defer str2.free();
|
||||
DString str3 = str.concat(mem, str2);
|
||||
defer str3.free();
|
||||
@@ -120,7 +120,7 @@ fn void test_append()
|
||||
|
||||
fn void test_print()
|
||||
{
|
||||
DString str = dstring::new("");
|
||||
DString str = dstring::new(mem, "");
|
||||
defer str.free();
|
||||
String s;
|
||||
|
||||
@@ -136,11 +136,11 @@ fn void test_print()
|
||||
|
||||
fn void test_copy()
|
||||
{
|
||||
DString str = dstring::new(TEST_STRING);
|
||||
DString str = dstring::new(mem, TEST_STRING);
|
||||
defer str.free();
|
||||
String s;
|
||||
|
||||
DString str2 = str.copy();
|
||||
DString str2 = str.copy(mem);
|
||||
defer str2.free();
|
||||
s = str2.str_view();
|
||||
assert(s == TEST_STRING, "got '%s'; want '%s'", s, TEST_STRING);
|
||||
@@ -148,10 +148,10 @@ fn void test_copy()
|
||||
|
||||
fn void test_cmp()
|
||||
{
|
||||
DString str = dstring::new(TEST_STRING);
|
||||
DString str = dstring::new(mem, TEST_STRING);
|
||||
defer str.free();
|
||||
|
||||
DString str2 = dstring::new(TEST_STRING);
|
||||
DString str2 = dstring::new(mem, TEST_STRING);
|
||||
defer str2.free();
|
||||
|
||||
assert(str.equals(str2));
|
||||
@@ -164,7 +164,7 @@ fn void test_cmp()
|
||||
|
||||
fn void test_join()
|
||||
{
|
||||
DString str = dstring::new_join({"hello", "world"}, " ");
|
||||
DString str = dstring::join(mem, {"hello", "world"}, " ");
|
||||
defer str.free();
|
||||
|
||||
String s = str.str_view();
|
||||
@@ -173,7 +173,7 @@ fn void test_join()
|
||||
|
||||
fn void test_insert_at()
|
||||
{
|
||||
DString str = dstring::temp_new(" world");
|
||||
DString str = dstring::temp(" world");
|
||||
String s;
|
||||
|
||||
str.insert_at(0, "");
|
||||
@@ -208,7 +208,7 @@ fn void test_insert_at()
|
||||
|
||||
fn void test_insert_at_overlaps()
|
||||
{
|
||||
DString str = dstring::temp_new("abc");
|
||||
DString str = dstring::temp("abc");
|
||||
String s;
|
||||
String v;
|
||||
|
||||
@@ -253,7 +253,7 @@ fn void test_insert_at_overlaps()
|
||||
|
||||
fn void test_char_at()
|
||||
{
|
||||
DString str = dstring::new("hello");
|
||||
DString str = dstring::new(mem, "hello");
|
||||
defer str.free();
|
||||
|
||||
char c = str.char_at(1);
|
||||
@@ -265,7 +265,7 @@ fn void test_char_at()
|
||||
|
||||
fn void test_operators()
|
||||
{
|
||||
DString str = dstring::new("hello");
|
||||
DString str = dstring::new(mem, "hello");
|
||||
defer str.free();
|
||||
|
||||
str[0] = 'p';
|
||||
|
||||
@@ -14,7 +14,7 @@ fn void test_ref() @test
|
||||
Foo* f0 = null;
|
||||
int* a = (void*)(uptr)0x40;
|
||||
int* b = null;
|
||||
String s = string::new_format("%s %s %s %s %s", a, b, f0, f, *f);
|
||||
String s = string::format(mem, "%s %s %s %s %s", a, b, f0, f, *f);
|
||||
defer free(s);
|
||||
assert(s == "0x40 0x0 (null) Foo[8] Foo[8]");
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ struct Bar
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
List(<Foo>) foos;
|
||||
List{Foo} foos;
|
||||
}
|
||||
|
||||
fn void test_new_aligned_compiles() @test
|
||||
|
||||
@@ -17,7 +17,7 @@ fn void test_print_null()
|
||||
ZString z;
|
||||
int* y;
|
||||
ZString w = "hello";
|
||||
String s = string::new_format("%s %s %s", z, w, y);
|
||||
String s = string::format(mem, "%s %s %s", z, w, y);
|
||||
defer free(s);
|
||||
assert(s == "(null) hello 0x0");
|
||||
}
|
||||
@@ -96,7 +96,7 @@ fn void test_trim_right()
|
||||
fn void test_split()
|
||||
{
|
||||
String test = "abc|b||c|";
|
||||
String[] strings = test.split("|");
|
||||
String[] strings = test.split(mem, "|");
|
||||
assert(strings.len == 5);
|
||||
assert(strings[0] == "abc");
|
||||
assert(strings[1] == "b");
|
||||
@@ -104,7 +104,7 @@ fn void test_split()
|
||||
assert(strings[3] == "c");
|
||||
assert(strings[4] == "");
|
||||
free(strings);
|
||||
strings = test.split("|", 2);
|
||||
strings = test.split(mem, "|", 2);
|
||||
assert(strings.len == 2);
|
||||
assert(strings[0] == "abc");
|
||||
assert(strings[1] == "b||c|");
|
||||
@@ -114,13 +114,13 @@ fn void test_split()
|
||||
fn void test_split_skip_empty()
|
||||
{
|
||||
String test = "abc|b||c|";
|
||||
String[] strings = test.split("|", skip_empty: true);
|
||||
String[] strings = test.split(mem, "|", skip_empty: true);
|
||||
assert(strings.len == 3);
|
||||
assert(strings[0] == "abc");
|
||||
assert(strings[1] == "b");
|
||||
assert(strings[2] == "c");
|
||||
free(strings);
|
||||
strings = test.split("|", 2, skip_empty: true);
|
||||
strings = test.split(mem, "|", 2, skip_empty: true);
|
||||
assert(strings.len == 2);
|
||||
assert(strings[0] == "abc");
|
||||
assert(strings[1] == "b||c|");
|
||||
@@ -136,7 +136,7 @@ fn void test_split_to_buffer_skip_empty()
|
||||
assert(strings[0] == "abc");
|
||||
assert(strings[1] == "b");
|
||||
assert(strings[2] == "c");
|
||||
strings = test.split("|", 2, skip_empty: true);
|
||||
strings = test.split(mem, "|", 2, skip_empty: true);
|
||||
assert(strings.len == 2);
|
||||
assert(strings[0] == "abc");
|
||||
assert(strings[1] == "b||c|");
|
||||
@@ -156,7 +156,7 @@ fn void test_split_to_buffer()
|
||||
assert(strings[4] == "");
|
||||
String[4] c;
|
||||
assert(@catch(test.split_to_buffer("|", &c)) == SplitResult.BUFFER_EXCEEDED);
|
||||
strings = test.split("|", 2);
|
||||
strings = test.split(mem, "|", 2);
|
||||
assert(strings.len == 2);
|
||||
assert(strings[0] == "abc");
|
||||
assert(strings[1] == "b||c|");
|
||||
|
||||
@@ -98,10 +98,10 @@ fn void base32_api()
|
||||
{
|
||||
foreach (t : std_tests)
|
||||
{
|
||||
String got = base32::encode_temp(t.dec)!!;
|
||||
String got = base32::tencode(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::tdecode(t.enc)!!;
|
||||
assert(got_chars == t.dec, "got: %s, want: %s", got_chars, t.dec);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -59,7 +59,7 @@ fn void csv_row()
|
||||
};
|
||||
CsvReader r;
|
||||
r.init((ByteReader){}.init(t.input), t.sep);
|
||||
CsvRow row = r.read_temp_row()!!;
|
||||
CsvRow row = r.tread_row()!!;
|
||||
assert(row.list.len == t.want.len, "not enough records found");
|
||||
for (int i = 0; i < row.list.len; i++) {
|
||||
assert(row.list[i] == t.want[i],"columns do not match; "
|
||||
|
||||
@@ -24,11 +24,11 @@ fn void encode()
|
||||
foreach (t : tests)
|
||||
{
|
||||
n = hex::encode_bytes(t.dec, buf[..]);
|
||||
String want = ((String)t.enc).temp_ascii_to_lower();
|
||||
String want = ((String)t.enc).to_lower_tcopy();
|
||||
assert(want == buf[:n], "encode failed: got: %s, want: %s", buf[:n], want);
|
||||
@pool()
|
||||
{
|
||||
assert(want == hex::encode_temp(t.dec));
|
||||
assert(want == hex::tencode(t.dec));
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ fn void decode()
|
||||
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::tdecode(t.enc)!!);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ 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(mem, &reader)!!;
|
||||
defer o.free();
|
||||
assert(o.get_int("b")!! == 123);
|
||||
assert(o.get("c").get_len()!! == 5);
|
||||
@@ -22,17 +22,17 @@ fn void simple_test2()
|
||||
{
|
||||
ByteReader reader;
|
||||
reader.init(`{"jsonrpc":"2.0","id":null,"method":"initialize"}`);
|
||||
Object* o = json::parse(&reader)!!;
|
||||
Object* o = json::parse(mem, &reader)!!;
|
||||
defer o.free();
|
||||
}
|
||||
|
||||
|
||||
fn void test_string()
|
||||
{
|
||||
Object* o = json::parse_string(`{"jsonrpc":"2","id":null,"method":"initialize"}`)!!;
|
||||
Object* o = json::parse_string(mem, `{"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(mem, s)!!;
|
||||
defer o2.free();
|
||||
String s2 = string::tformat("%s", *o2);
|
||||
assert(s2 == s, "Unexpectedly got %s and not %s", s2, s);
|
||||
@@ -42,10 +42,10 @@ fn void test_temp_string()
|
||||
{
|
||||
@pool()
|
||||
{
|
||||
Object* o = json::temp_parse_string(`{"jsonrpc":"2","id":null,"method":"initialize"}`)!!;
|
||||
Object* o = json::tparse_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::tparse_string(s)!!;
|
||||
defer o2.free();
|
||||
String s2 = string::tformat("%s", *o2);
|
||||
assert(s2 == s, "Unexpectedly got %s and not %s", s2, s);
|
||||
|
||||
@@ -3,13 +3,12 @@ module std::io @test;
|
||||
fn void test_multireader()
|
||||
{
|
||||
MultiReader mr;
|
||||
mr.init(mem,
|
||||
mr.tinit(
|
||||
&&wrap_bytes("foo"),
|
||||
&&wrap_bytes(" "),
|
||||
&&wrap_bytes("bar"),
|
||||
&&wrap_bytes("!"),
|
||||
);
|
||||
defer mr.free();
|
||||
|
||||
ByteWriter w;
|
||||
io::copy_to(&mr, w.tinit())!!;
|
||||
|
||||
@@ -2,13 +2,13 @@ module std::io::path @test;
|
||||
|
||||
fn void test_dot()
|
||||
{
|
||||
Path p = path::new(".")!!;
|
||||
Path p = path::new(mem, ".")!!;
|
||||
defer p.free();
|
||||
assert(@catch(p.parent()));
|
||||
// It must be possible to form the absolute version.
|
||||
Path p2 = p.new_absolute()!!;
|
||||
Path p2 = p.absolute(mem)!!;
|
||||
p2.free();
|
||||
p2 = p.new_append("/hello/world")!!;
|
||||
p2 = p.append(mem, "/hello/world")!!;
|
||||
if (p2.env == POSIX)
|
||||
{
|
||||
assert(p2.str_view() == "hello/world");
|
||||
@@ -22,357 +22,357 @@ fn void test_dot()
|
||||
|
||||
fn void test_parent()
|
||||
{
|
||||
Path p = path::new("")!!;
|
||||
Path p = path::new(mem, "")!!;
|
||||
assert(@catch(p.parent()));
|
||||
p.free();
|
||||
p = path::new("/", path_env: PathEnv.POSIX)!!;
|
||||
p = path::new(mem, "/", path_env: PathEnv.POSIX)!!;
|
||||
assert(@catch(p.parent()));
|
||||
p.free();
|
||||
p = path::new("/a/b/c", path_env: PathEnv.POSIX)!!;
|
||||
p = path::new(mem, "/a/b/c", path_env: PathEnv.POSIX)!!;
|
||||
assert(p.parent().str_view()!! == "/a/b");
|
||||
p.free();
|
||||
p = path::new("/a/b/c", path_env: PathEnv.WIN32)!!;
|
||||
p = path::new(mem, "/a/b/c", path_env: PathEnv.WIN32)!!;
|
||||
assert(p.parent().str_view()!! == `\a\b`);
|
||||
p.free();
|
||||
}
|
||||
|
||||
fn void test_path_normalized() => mem::@scoped(allocator::temp())
|
||||
{
|
||||
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)));
|
||||
assert(@catch(path::new("1:a", path_env: PathEnv.WIN32)));
|
||||
// assert(@catch(path::new(`\\\a\b\c.txt`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(`\\server\a\b\..\..\..\c`, path_env: PathEnv.WIN32)));
|
||||
assert(path::new(mem, "", path_env: PathEnv.WIN32).str_view()!! == "");
|
||||
assert(@catch(path::new(mem, "1:\\a\\b\\c.txt", path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, ":", path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, "1:", path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, "1:a", path_env: PathEnv.WIN32)));
|
||||
// assert(@catch(path::new(mem, `\\\a\b\c.txt`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, `\\server\a\b\..\..\..\c`, path_env: PathEnv.WIN32)));
|
||||
|
||||
assert(@catch(path::new(`\\a`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(`/a/b/../../../c`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(`/a/b/../../../c`, path_env: PathEnv.POSIX)));
|
||||
assert(@catch(path::new(`/a/b/../../..`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(`/a/b/../../..`, path_env: PathEnv.POSIX)));
|
||||
assert(@catch(path::new(`/../a`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(`/../a`, path_env: PathEnv.POSIX)));
|
||||
assert(@catch(path::new(`/..`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(`/..`, path_env: PathEnv.POSIX)));
|
||||
assert(@catch(path::new(`C:/a/b/../../../c`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(`C:/../a`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(`C:/..`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, `\\a`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, `/a/b/../../../c`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, `/a/b/../../../c`, path_env: PathEnv.POSIX)));
|
||||
assert(@catch(path::new(mem, `/a/b/../../..`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, `/a/b/../../..`, path_env: PathEnv.POSIX)));
|
||||
assert(@catch(path::new(mem, `/../a`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, `/../a`, path_env: PathEnv.POSIX)));
|
||||
assert(@catch(path::new(mem, `/..`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, `/..`, path_env: PathEnv.POSIX)));
|
||||
assert(@catch(path::new(mem, `C:/a/b/../../../c`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, `C:/../a`, path_env: PathEnv.WIN32)));
|
||||
assert(@catch(path::new(mem, `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(mem, "/", path_env: PathEnv.POSIX).str_view()!! == "/");
|
||||
assert(path::new(mem, "/./", path_env: PathEnv.POSIX).str_view()!! == "/");
|
||||
assert(path::new(mem, "/foo/../", path_env: PathEnv.POSIX).str_view()!! == "/");
|
||||
assert(path::new(mem, "/foo/bar/../", path_env: PathEnv.POSIX).str_view()!! == "/foo");
|
||||
assert(path::new(mem, "/foo//bar", path_env: PathEnv.POSIX).str_view()!! == "/foo/bar");
|
||||
assert(path::new(mem, "/foo//bar/../", path_env: PathEnv.POSIX).str_view()!! == "/foo");
|
||||
assert(path::new(mem, "/foo/.bar", path_env: PathEnv.POSIX).str_view()!! == "/foo/.bar");
|
||||
assert(path::new(mem, `\foo\.bar`, path_env: PathEnv.WIN32).str_view()!! == `\foo\.bar`);
|
||||
assert(path::new(mem, "a\\b/c.txt", path_env: PathEnv.WIN32).str_view()!! == `a\b\c.txt`);
|
||||
assert(path::new(mem, "a\\b/c.txt", path_env: PathEnv.POSIX).str_view()!! == "a\\b/c.txt");
|
||||
assert(path::new(mem, "C:\\a\\b/c.txt", path_env: PathEnv.WIN32).str_view()!! == `C:\a\b\c.txt`);
|
||||
assert(path::new(mem, "C:\\a\\b/c.txt", path_env: PathEnv.POSIX).str_view()!! == "C:\\a\\b/c.txt");
|
||||
assert(path::new(mem, `\\server\a\b/c.txt`, path_env: PathEnv.WIN32).str_view()!! == `\\server\a\b\c.txt`);
|
||||
assert(path::new(mem, `\\server\a\b/c.txt`, path_env: PathEnv.POSIX).str_view()!! == `\\server\a\b/c.txt`);
|
||||
assert(path::new(mem, `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(mem, `~\a\b/c.txt`, path_env: PathEnv.WIN32).str_view()!! == `~\a\b\c.txt`);
|
||||
assert(path::new(mem, `~\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(mem, `a/b/../../../c`, path_env: PathEnv.WIN32).str_view()!! == `..\c`);
|
||||
assert(path::new(mem, `a/b/../../../c`, path_env: PathEnv.POSIX).str_view()!! == `../c`);
|
||||
assert(path::new(mem, `a/b/../../..`, path_env: PathEnv.WIN32).str_view()!! == `..`);
|
||||
assert(path::new(mem, `a/b/../../..`, path_env: PathEnv.POSIX).str_view()!! == `..`);
|
||||
assert(path::new(mem, `../a`, path_env: PathEnv.WIN32).str_view()!! == `..\a`);
|
||||
assert(path::new(mem, `../a`, path_env: PathEnv.POSIX).str_view()!! == `../a`);
|
||||
assert(path::new(mem, `..`, path_env: PathEnv.WIN32).str_view()!! == `..`);
|
||||
assert(path::new(mem, `..`, path_env: PathEnv.POSIX).str_view()!! == `..`);
|
||||
assert(path::new(mem, `a/b/../c`, path_env: PathEnv.WIN32).str_view()!! == `a\c`);
|
||||
assert(path::new(mem, `a/b/../c`, path_env: PathEnv.POSIX).str_view()!! == `a/c`);
|
||||
assert(path::new(mem, `a/b/../../c`, path_env: PathEnv.WIN32).str_view()!! == `c`);
|
||||
assert(path::new(mem, `a/b/../../c`, path_env: PathEnv.POSIX).str_view()!! == `c`);
|
||||
assert(path::new(mem, `a/b/..`, path_env: PathEnv.WIN32).str_view()!! == `a`);
|
||||
assert(path::new(mem, `a/b/..`, path_env: PathEnv.POSIX).str_view()!! == `a`);
|
||||
assert(path::new(mem, `a/b/../`, path_env: PathEnv.WIN32).str_view()!! == `a`);
|
||||
assert(path::new(mem, `a/b/../`, path_env: PathEnv.POSIX).str_view()!! == `a`);
|
||||
assert(path::new(mem, `a/b/../..`, path_env: PathEnv.WIN32).str_view()!! == ".");
|
||||
assert(path::new(mem, `a/b/../..`, path_env: PathEnv.POSIX).str_view()!! == ".");
|
||||
assert(path::new(mem, `a/b/../../`, path_env: PathEnv.WIN32).str_view()!! == ".");
|
||||
assert(path::new(mem, `a/b/../../`, path_env: PathEnv.POSIX).str_view()!! == ".");
|
||||
assert(path::new(mem, `a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()!! == `a\d`);
|
||||
assert(path::new(mem, `a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()!! == `a/d`);
|
||||
assert(path::new(mem, `a/b/../c/../d/`, path_env: PathEnv.WIN32).str_view()!! == `a\d`);
|
||||
assert(path::new(mem, `a/b/../c/../d/`, path_env: PathEnv.POSIX).str_view()!! == `a/d`);
|
||||
assert(path::new(mem, `a/b//d`, path_env: PathEnv.WIN32).str_view()!! == `a\b\d`);
|
||||
assert(path::new(mem, `a/b//d`, path_env: PathEnv.POSIX).str_view()!! == `a/b/d`);
|
||||
assert(path::new(mem, `a/b/././.`, path_env: PathEnv.WIN32).str_view()!! == `a\b`);
|
||||
assert(path::new(mem, `a/b/././.`, path_env: PathEnv.POSIX).str_view()!! == `a/b`);
|
||||
assert(path::new(mem, `a/b/./././`, path_env: PathEnv.WIN32).str_view()!! == `a\b`);
|
||||
assert(path::new(mem, `a/b/./././`, path_env: PathEnv.POSIX).str_view()!! == `a/b`);
|
||||
assert(path::new(mem, `./a/`, path_env: PathEnv.WIN32).str_view()!! == `a`);
|
||||
assert(path::new(mem, `./a/`, path_env: PathEnv.POSIX).str_view()!! == `a`);
|
||||
assert(path::new(mem, `./`, path_env: PathEnv.WIN32).str_view()!! == `.`);
|
||||
assert(path::new(mem, `./`, path_env: PathEnv.POSIX).str_view()!! == `.`);
|
||||
assert(path::new(mem, `.`, path_env: PathEnv.WIN32).str_view()!! == `.`);
|
||||
assert(path::new(mem, `.`, path_env: PathEnv.POSIX).str_view()!! == `.`);
|
||||
assert(path::new(mem, ``, path_env: PathEnv.WIN32).str_view()!! == ``);
|
||||
assert(path::new(mem, ``, path_env: PathEnv.POSIX).str_view()!! == ``);
|
||||
assert(path::new(mem, `/a`, path_env: PathEnv.WIN32).str_view()!! == `\a`);
|
||||
assert(path::new(mem, `/a`, path_env: PathEnv.POSIX).str_view()!! == `/a`);
|
||||
assert(path::new(mem, `/a/`, path_env: PathEnv.WIN32).str_view()!! == `\a`);
|
||||
assert(path::new(mem, `/a/`, path_env: PathEnv.POSIX).str_view()!! == `/a`);
|
||||
assert(path::new(mem, `/a/b/../c`, path_env: PathEnv.WIN32).str_view()!! == `\a\c`);
|
||||
assert(path::new(mem, `/a/b/../c`, path_env: PathEnv.POSIX).str_view()!! == `/a/c`);
|
||||
assert(path::new(mem, `/a/b/../../c`, path_env: PathEnv.WIN32).str_view()!! == `\c`);
|
||||
assert(path::new(mem, `/a/b/../../c`, path_env: PathEnv.POSIX).str_view()!! == `/c`);
|
||||
assert(path::new(mem, `/a/b/..`, path_env: PathEnv.WIN32).str_view()!! == `\a`);
|
||||
assert(path::new(mem, `/a/b/..`, path_env: PathEnv.POSIX).str_view()!! == `/a`);
|
||||
assert(path::new(mem, `/a/b/../..`, path_env: PathEnv.WIN32).str_view()!! == `\`);
|
||||
assert(path::new(mem, `/a/b/../..`, path_env: PathEnv.POSIX).str_view()!! == `/`);
|
||||
assert(path::new(mem, `/a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()!! == `\a\d`);
|
||||
assert(path::new(mem, `/a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()!! == `/a/d`);
|
||||
assert(path::new(mem, `/a/b//d`, path_env: PathEnv.WIN32).str_view()!! == `\a\b\d`);
|
||||
assert(path::new(mem, `/a/b//d`, path_env: PathEnv.POSIX).str_view()!! == `/a/b/d`);
|
||||
assert(path::new(mem, `/./a/`, path_env: PathEnv.WIN32).str_view()!! == `\a`);
|
||||
assert(path::new(mem, `/./a/`, path_env: PathEnv.POSIX).str_view()!! == `/a`);
|
||||
assert(path::new(mem, `/./`, path_env: PathEnv.WIN32).str_view()!! == `\`);
|
||||
assert(path::new(mem, `/./`, path_env: PathEnv.POSIX).str_view()!! == `/`);
|
||||
assert(path::new(mem, `/.`, path_env: PathEnv.WIN32).str_view()!! == `\`);
|
||||
assert(path::new(mem, `/.`, path_env: PathEnv.POSIX).str_view()!! == `/`);
|
||||
assert(path::new(mem, `/`, path_env: PathEnv.WIN32).str_view()!! == `\`);
|
||||
assert(path::new(mem, `/`, path_env: PathEnv.POSIX).str_view()!! == `/`);
|
||||
assert(path::new(mem, `C:/a`, path_env: PathEnv.WIN32).str_view()!! == `C:\a`);
|
||||
assert(path::new(mem, `C:/a`, path_env: PathEnv.POSIX).str_view()!! == `C:/a`);
|
||||
assert(path::new(mem, `C:/a/b/../c`, path_env: PathEnv.WIN32).str_view()!! == `C:\a\c`);
|
||||
assert(path::new(mem, `C:/a/b/../c`, path_env: PathEnv.POSIX).str_view()!! == `C:/a/c`);
|
||||
assert(path::new(mem, `C:/a/b/../../c`, path_env: PathEnv.WIN32).str_view()!! == `C:\c`);
|
||||
assert(path::new(mem, `C:/a/b/../../c`, path_env: PathEnv.POSIX).str_view()!! == `C:/c`);
|
||||
assert(path::new(mem, `C:/a/b/../../../c`, path_env: PathEnv.POSIX).str_view()!! == `c`);
|
||||
assert(path::new(mem, `C:/a/b/..`, path_env: PathEnv.WIN32).str_view()!! == `C:\a`);
|
||||
assert(path::new(mem, `C:/a/b/..`, path_env: PathEnv.POSIX).str_view()!! == `C:/a`);
|
||||
assert(path::new(mem, `C:/a/b/../..`, path_env: PathEnv.WIN32).str_view()!! == `C:\`);
|
||||
assert(path::new(mem, `C:/a/b/../..`, path_env: PathEnv.POSIX).str_view()!! == `C:`);
|
||||
assert(path::new(mem, `C:/a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()!! == `C:\a\d`);
|
||||
assert(path::new(mem, `C:/a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()!! == `C:/a/d`);
|
||||
assert(path::new(mem, `C:/a/b//d`, path_env: PathEnv.WIN32).str_view()!! == `C:\a\b\d`);
|
||||
assert(path::new(mem, `C:/a/b//d`, path_env: PathEnv.POSIX).str_view()!! == `C:/a/b/d`);
|
||||
assert(path::new(mem, `C:/a/b/././.`, path_env: PathEnv.WIN32).str_view()!! == `C:\a\b`);
|
||||
assert(path::new(mem, `C:/a/b/././.`, path_env: PathEnv.POSIX).str_view()!! == `C:/a/b`);
|
||||
assert(path::new(mem, `C:/./a`, path_env: PathEnv.WIN32).str_view()!! == `C:\a`);
|
||||
assert(path::new(mem, `C:/./a`, path_env: PathEnv.POSIX).str_view()!! == `C:/a`);
|
||||
assert(path::new(mem, `C:/./`, path_env: PathEnv.WIN32).str_view()!! == `C:\`);
|
||||
assert(path::new(mem, `C:/./`, path_env: PathEnv.POSIX).str_view()!! == `C:`);
|
||||
assert(path::new(mem, `C:/../a`, path_env: PathEnv.POSIX).str_view()!! == `a`);
|
||||
assert(path::new(mem, `C:/..`, path_env: PathEnv.POSIX).str_view()!! == `.`);
|
||||
assert(path::new(mem, `C:/`, path_env: PathEnv.WIN32).str_view()!! == `C:\`);
|
||||
assert(path::new(mem, `C:/`, path_env: PathEnv.POSIX).str_view()!! == `C:`);
|
||||
assert(path::new(mem, `C:a`, path_env: PathEnv.WIN32).str_view()!! == `C:a`);
|
||||
assert(path::new(mem, `C:a`, path_env: PathEnv.POSIX).str_view()!! == `C:a`);
|
||||
assert(path::new(mem, `C:a/`, path_env: PathEnv.WIN32).str_view()!! == `C:a`);
|
||||
assert(path::new(mem, `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(mem, `C:a/b/../c`, path_env: PathEnv.WIN32).str_view()!! == `C:a\c`);
|
||||
assert(path::new(mem, `C:a/b/../c`, path_env: PathEnv.POSIX).str_view()!! == `C:a/c`);
|
||||
assert(path::new(mem, `C:a/b/../../c`, path_env: PathEnv.WIN32).str_view()!! == `C:c`);
|
||||
assert(path::new(mem, `C:a/b/../../c`, path_env: PathEnv.POSIX).str_view()!! == `c`);
|
||||
assert(path::new(mem, `C:a/b/..`, path_env: PathEnv.WIN32).str_view()!! == `C:a`);
|
||||
assert(path::new(mem, `C:a/b/..`, path_env: PathEnv.POSIX).str_view()!! == `C:a`);
|
||||
assert(path::new(mem, `C:a/b/../..`, path_env: PathEnv.WIN32).str_view()!! == `C:`);
|
||||
assert(path::new(mem, `C:a/b/../..`, path_env: PathEnv.POSIX).str_view()!! == `.`);
|
||||
assert(path::new(mem, `C:a/b/../c/../d`, path_env: PathEnv.WIN32).str_view()!! == `C:a\d`);
|
||||
assert(path::new(mem, `C:a/b/../c/../d`, path_env: PathEnv.POSIX).str_view()!! == `C:a/d`);
|
||||
assert(path::new(mem, `C:a/b//d`, path_env: PathEnv.WIN32).str_view()!! == `C:a\b\d`);
|
||||
assert(path::new(mem, `C:a/b//d`, path_env: PathEnv.POSIX).str_view()!! == `C:a/b/d`);
|
||||
assert(path::new(mem, `C:a/b/././.`, path_env: PathEnv.WIN32).str_view()!! == `C:a\b`);
|
||||
assert(path::new(mem, `C:a/b/././.`, path_env: PathEnv.POSIX).str_view()!! == `C:a/b`);
|
||||
assert(path::new(mem, `C:a/b/../../../c`, path_env: PathEnv.WIN32).str_view()!! == `C:..\c`);
|
||||
assert(path::new(mem, `C:./a`, path_env: PathEnv.WIN32).str_view()!! == `C:a`);
|
||||
assert(path::new(mem, `C:./a`, path_env: PathEnv.POSIX).str_view()!! == `C:./a`);
|
||||
assert(path::new(mem, `C:./`, path_env: PathEnv.WIN32).str_view()!! == `C:`);
|
||||
assert(path::new(mem, `C:./`, path_env: PathEnv.POSIX).str_view()!! == `C:.`);
|
||||
assert(path::new(mem, `C:../a`, path_env: PathEnv.POSIX).str_view()!! == `C:../a`);
|
||||
assert(path::new(mem, `C:../a`, path_env: PathEnv.WIN32).str_view()!! == `C:..\a`);
|
||||
assert(path::new(mem, `C:..`, path_env: PathEnv.POSIX).str_view()!! == `C:..`);
|
||||
assert(path::new(mem, `C:..`, path_env: PathEnv.WIN32).str_view()!! == `C:..`);
|
||||
assert(path::new(mem, `C:`, path_env: PathEnv.WIN32).str_view()!! == `C:`);
|
||||
assert(path::new(mem, `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(mem, `\\server\foo/a`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a`);
|
||||
assert(path::new(mem, `\\server\foo/a`, path_env: PathEnv.POSIX).str_view()!! == `\\server\foo/a`);
|
||||
assert(path::new(mem, `\\server\foo\a\b\..\c`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a\c`);
|
||||
assert(path::new(mem, `\\server\foo\a\b\..\..\c`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\c`);
|
||||
assert(path::new(mem, `\\server\foo\a\b\..`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a`);
|
||||
assert(path::new(mem, `\\server\foo\a\..`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\`);
|
||||
assert(path::new(mem, `\\server\foo\a\b\..\c\..\d`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a\d`);
|
||||
assert(path::new(mem, `\\server\foo\a\b\\d`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a\b\d`);
|
||||
assert(path::new(mem, `\\server\foo\a\b\.\.\.`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a\b`);
|
||||
assert(path::new(mem, `\\server\foo\.\a`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\a`);
|
||||
assert(path::new(mem, `\\server\foo\.`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\`);
|
||||
assert(path::new(mem, `\\server\foo\`, path_env: PathEnv.WIN32).str_view()!! == `\\server\foo\`);
|
||||
|
||||
}
|
||||
|
||||
fn void test_extension() => mem::@scoped(allocator::temp())
|
||||
{
|
||||
assert(@catch(path::new(`C:`, path_env: PathEnv.WIN32).extension()));
|
||||
assert(@catch(path::new(`C:`, path_env: PathEnv.POSIX).extension()));
|
||||
assert(@catch(path::new(`file`, path_env: PathEnv.WIN32).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(@catch(path::new(mem, `C:`, path_env: PathEnv.WIN32).extension()));
|
||||
assert(@catch(path::new(mem, `C:`, path_env: PathEnv.POSIX).extension()));
|
||||
assert(@catch(path::new(mem, `file`, path_env: PathEnv.WIN32).extension()));
|
||||
assert(@catch(path::new(mem, `file`, path_env: PathEnv.POSIX).extension()));
|
||||
assert(@catch(path::new(mem, `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::for_windows(mem, "file.txt").extension()!! == "txt");
|
||||
assert(path::for_posix(mem, "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::for_windows(mem, "a/b/file.txt").extension()!! == "txt");
|
||||
assert(path::for_posix(mem, "a/b/file.txt").extension()!! == "txt");
|
||||
|
||||
assert(path::new_windows("a\\b\\file.txt").extension()!! == "txt");
|
||||
assert(path::for_windows(mem, "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::for_windows(mem, "a.b/file.txt").extension()!! == "txt");
|
||||
assert(path::for_posix(mem, "a.b/file.txt").extension()!! == "txt");
|
||||
assert(path::for_windows(mem, "a.b/file.txt").extension()!! == "txt");
|
||||
assert(path::for_posix(mem, "a.b/file.txt").extension()!! == "txt");
|
||||
|
||||
assert(path::new_windows("a.b\\file.txt").extension()!! == "txt");
|
||||
assert(path::for_windows(mem, "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::for_windows(mem, "domain.dot.com").extension()!! == "com");
|
||||
assert(path::for_posix(mem, "domain.dot.com").extension()!! == "com");
|
||||
|
||||
assert(path::new_windows("image.jpeg").extension()!! == "jpeg");
|
||||
assert(path::new_posix("image.jpeg").extension()!! == "jpeg");
|
||||
assert(path::for_windows(mem, "image.jpeg").extension()!! == "jpeg");
|
||||
assert(path::for_posix(mem, "image.jpeg").extension()!! == "jpeg");
|
||||
|
||||
assert(path::new_windows("../filename.ext").extension()!! == "ext");
|
||||
assert(path::new_posix("../filename.ext").extension()!! == "ext");
|
||||
assert(path::for_windows(mem, "../filename.ext").extension()!! == "ext");
|
||||
assert(path::for_posix(mem, "../filename.ext").extension()!! == "ext");
|
||||
|
||||
}
|
||||
|
||||
fn void test_has_extension() => mem::@scoped(allocator::temp())
|
||||
{
|
||||
assert(!path::new(`C:\temp\foo.bar\README`, path_env: PathEnv.WIN32)!!.has_extension(`bar\README`));
|
||||
assert(!path::new(mem, `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::for_windows(mem, "file.txt")!!.has_extension("txt"));
|
||||
assert(path::for_posix(mem, "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::for_windows(mem, "a/b/file.txt")!!.has_extension("txt"));
|
||||
assert(path::for_posix(mem, "a/b/file.txt")!!.has_extension("txt"));
|
||||
|
||||
assert(path::new_windows("a\\b\\file.txt")!!.has_extension("txt"));
|
||||
assert(path::for_windows(mem, "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::for_windows(mem, "a.b/file.txt")!!.has_extension("txt"));
|
||||
assert(path::for_posix(mem, "a.b/file.txt")!!.has_extension("txt"));
|
||||
assert(path::for_windows(mem, "a.b/file.txt")!!.has_extension("txt"));
|
||||
assert(path::for_posix(mem, "a.b/file.txt")!!.has_extension("txt"));
|
||||
|
||||
assert(path::new_windows("a.b\\file.txt")!!.has_extension("txt"));
|
||||
assert(path::for_windows(mem, "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::for_windows(mem, "domain.dot.com")!!.has_extension("com"));
|
||||
assert(path::for_posix(mem, "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::for_windows(mem, "image.jpeg")!!.has_extension("jpeg"));
|
||||
assert(path::for_posix(mem, "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::for_windows(mem, "../filename.ext")!!.has_extension("ext"));
|
||||
assert(path::for_posix(mem, "../filename.ext")!!.has_extension("ext"));
|
||||
|
||||
}
|
||||
|
||||
fn void test_basename() => mem::@scoped(allocator::temp())
|
||||
{
|
||||
assert(path::new_windows("file.txt").basename()!! == "file.txt");
|
||||
assert(path::new_posix("file.txt").basename()!! == "file.txt");
|
||||
assert(path::for_windows(mem, "file.txt").basename()!! == "file.txt");
|
||||
assert(path::for_posix(mem, "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::for_windows(mem, "a/b/file.txt").basename()!! == "file.txt");
|
||||
assert(path::for_posix(mem, "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::for_windows(mem, "a.b/file.txt").basename()!! == "file.txt");
|
||||
assert(path::for_posix(mem, "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::for_windows(mem, "a.b/file.txt").basename()!! == "file.txt");
|
||||
assert(path::for_posix(mem, "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::for_windows(mem, "../filename.ext").basename()!! == "filename.ext");
|
||||
assert(path::for_posix(mem, "../filename.ext").basename()!! == "filename.ext");
|
||||
|
||||
assert(path::new_windows("C:").basename()!! == "");
|
||||
assert(path::new_posix("C:").basename()!! == "C:");
|
||||
assert(path::for_windows(mem, "C:").basename()!! == "");
|
||||
assert(path::for_posix(mem, "C:").basename()!! == "C:");
|
||||
|
||||
assert(path::new_windows("../..").basename()!! == "..");
|
||||
assert(path::new_posix("../..").basename()!! == "..");
|
||||
assert(path::for_windows(mem, "../..").basename()!! == "..");
|
||||
assert(path::for_posix(mem, "../..").basename()!! == "..");
|
||||
|
||||
assert(path::new_windows(`\\server\abc`).basename()!! == "");
|
||||
assert(path::new_posix(`\\server\abc`).basename()!! == `\\server\abc`);
|
||||
assert(path::for_windows(mem, `\\server\abc`).basename()!! == "");
|
||||
assert(path::for_posix(mem, `\\server\abc`).basename()!! == `\\server\abc`);
|
||||
}
|
||||
|
||||
fn void test_dirname() => mem::@scoped(allocator::temp())
|
||||
{
|
||||
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::for_posix(mem, "").dirname()!! == ".");
|
||||
assert(path::for_posix(mem, "/file").dirname()!! == "/");
|
||||
assert(path::for_posix(mem, "///").dirname()!! == "/");
|
||||
assert(path::for_windows(mem, "d:").dirname()!! == "d:");
|
||||
assert(path::for_windows(mem, "d:file").dirname()!! == "d:");
|
||||
assert(path::for_windows(mem, `d:\file`).dirname()!! == `d:\`);
|
||||
|
||||
assert(path::new_windows("file.txt").dirname()!! == ".");
|
||||
assert(path::new_posix("file.txt").dirname()!! == ".");
|
||||
assert(path::for_windows(mem, "file.txt").dirname()!! == ".");
|
||||
assert(path::for_posix(mem, "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::for_windows(mem, "a/b/file.txt").dirname()!! == `a\b`);
|
||||
assert(path::for_posix(mem, "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::for_windows(mem, "a.b/file.txt").dirname()!! == "a.b");
|
||||
assert(path::for_posix(mem, "a.b/file.txt").dirname()!! == "a.b");
|
||||
|
||||
assert(path::new_windows("../filename.ext").dirname()!! == "..");
|
||||
assert(path::new_posix("../filename.ext").dirname()!! == "..");
|
||||
assert(path::for_windows(mem, "../filename.ext").dirname()!! == "..");
|
||||
assert(path::for_posix(mem, "../filename.ext").dirname()!! == "..");
|
||||
|
||||
assert(path::new_windows("C:").dirname()!! == "C:");
|
||||
assert(path::new_posix("C:").dirname()!! == ".");
|
||||
assert(path::for_windows(mem, "C:").dirname()!! == "C:");
|
||||
assert(path::for_posix(mem, "C:").dirname()!! == ".");
|
||||
|
||||
assert(path::new_windows("C:/").dirname()!! == "C:\\");
|
||||
assert(path::new_posix("C:/").dirname()!! == ".");
|
||||
assert(path::for_windows(mem, "C:/").dirname()!! == "C:\\");
|
||||
assert(path::for_posix(mem, "C:/").dirname()!! == ".");
|
||||
|
||||
assert(path::new_windows("C:/a").dirname()!! == "C:\\");
|
||||
assert(path::new_posix("C:/a").dirname()!! == "C:");
|
||||
assert(path::for_windows(mem, "C:/a").dirname()!! == "C:\\");
|
||||
assert(path::for_posix(mem, "C:/a").dirname()!! == "C:");
|
||||
|
||||
assert(path::new_windows("../..").dirname()!! == "..");
|
||||
assert(path::new_posix("../..").dirname()!! == "..");
|
||||
assert(path::for_windows(mem, "../..").dirname()!! == "..");
|
||||
assert(path::for_posix(mem, "../..").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::for_windows(mem, `\\server\share\dir\file`).dirname()!! == `\\server\share\dir`);
|
||||
assert(path::for_windows(mem, `\\server\share\file`).dirname()!! == `\\server\share`);
|
||||
assert(path::for_windows(mem, `\\server\share\`).dirname()!! == `\\server\share`);
|
||||
assert(path::for_windows(mem, `\\server\share`).dirname()!! == `\\server\share`);
|
||||
assert(path::for_posix(mem, `\\server\`).dirname()!! == `.`);
|
||||
}
|
||||
|
||||
fn void test_path_volume() => mem::@scoped(allocator::temp())
|
||||
{
|
||||
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::for_windows(mem, `C:\abs`).volume_name()!! == `C:`);
|
||||
assert(path::for_windows(mem, `C:abs`).volume_name()!! == `C:`);
|
||||
assert(path::for_posix(mem, `C:/abs`).volume_name()!! == ``);
|
||||
assert(path::for_posix(mem, `C:abs`).volume_name()!! == ``);
|
||||
assert(path::for_windows(mem, `\\server\foo`).volume_name()!! == `\\server\foo`);
|
||||
assert(path::for_windows(mem, `\\server\foo\abc`).volume_name()!! == `\\server\foo`);
|
||||
}
|
||||
|
||||
fn void test_path_is_absolute() => mem::@scoped(allocator::temp())
|
||||
{
|
||||
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::for_posix(mem, "").is_absolute()!!);
|
||||
assert(path::for_posix(mem, "/").is_absolute()!!);
|
||||
assert(path::for_posix(mem, "/a/b").is_absolute()!!);
|
||||
assert(!path::for_posix(mem, "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::for_windows(mem, `C:`).is_absolute()!!);
|
||||
assert(path::for_windows(mem, `C:\abs`).is_absolute()!!);
|
||||
assert(!path::for_windows(mem, `C:abs`).is_absolute()!!);
|
||||
assert(path::for_windows(mem, `\\server\foo`).is_absolute()!!);
|
||||
assert(path::for_windows(mem, `\\server\foo\abc`).is_absolute()!!);
|
||||
}
|
||||
|
||||
fn void test_path_absolute() => mem::@scoped(allocator::temp())
|
||||
{
|
||||
$if env::WIN32:
|
||||
assert(path::new_windows(`C:\abs`).new_absolute()!!.str_view() == `C:\abs`);
|
||||
assert(path::for_windows(mem, `C:\abs`).absolute(mem, )!!.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::for_posix(mem, "/").absolute(mem, )!!.str_view() == "/");
|
||||
assert(path::for_posix(mem, ".").absolute(mem, )!!.str_view() == path::tcwd()!!.str_view());
|
||||
$endif
|
||||
}
|
||||
@@ -3,19 +3,19 @@ module std::io @test;
|
||||
fn void printf_int()
|
||||
{
|
||||
String s;
|
||||
s = string::new_format("[%-10d]", 78);
|
||||
s = string::format(mem, "[%-10d]", 78);
|
||||
assert(s == "[78 ]");
|
||||
free(s);
|
||||
s = string::new_format("[%10d]", 78);
|
||||
s = string::format(mem, "[%10d]", 78);
|
||||
assert(s == "[ 78]");
|
||||
free(s);
|
||||
s = string::new_format("[%010d]", 78);
|
||||
s = string::format(mem, "[%010d]", 78);
|
||||
assert(s == "[0000000078]");
|
||||
free(s);
|
||||
s = string::new_format("[%+10d]", 78);
|
||||
s = string::format(mem, "[%+10d]", 78);
|
||||
assert(s == "[ +78]");
|
||||
free(s);
|
||||
s = string::new_format("[%-+10d]", 78);
|
||||
s = string::format(mem, "[%-+10d]", 78);
|
||||
assert(s == "[+78 ]");
|
||||
free(s);
|
||||
}
|
||||
@@ -23,69 +23,69 @@ fn void printf_int()
|
||||
fn void printf_a()
|
||||
{
|
||||
String s;
|
||||
s = string::new_format("%08.2a", 234.125);
|
||||
s = string::format(mem, "%08.2a", 234.125);
|
||||
assert(s == "0x1.d4p+7", "got '%s'; want '0x1.d4p+7'", s);
|
||||
free(s);
|
||||
s = string::new_format("%a", 234.125);
|
||||
s = string::format(mem, "%a", 234.125);
|
||||
assert(s == "0x1.d44p+7", "got '%s'; want '0x1.d44p+7'", s);
|
||||
free(s);
|
||||
s = string::new_format("%A", 234.125);
|
||||
s = string::format(mem, "%A", 234.125);
|
||||
assert(s == "0X1.D44P+7", "got '%s'; want '0X1.D44P+7'", s);
|
||||
free(s);
|
||||
s = string::new_format("%20a", 234.125);
|
||||
s = string::format(mem, "%20a", 234.125);
|
||||
assert(s == " 0x1.d44p+7", "got '%s'; want ' 0x1.d44p+7'", s);
|
||||
free(s);
|
||||
s = string::new_format("%-20a", 234.125);
|
||||
s = string::format(mem, "%-20a", 234.125);
|
||||
assert(s == "0x1.d44p+7 ", "got '%s'; want '0x1.d44p+7 '", s);
|
||||
free(s);
|
||||
s = string::new_format("%-20s", "hello world");
|
||||
s = string::format(mem, "%-20s", "hello world");
|
||||
assert(s == "hello world ", "got '%s'; want 'hello world '", s);
|
||||
free(s);
|
||||
s = string::new_format("%20s", "hello world");
|
||||
s = string::format(mem, "%20s", "hello world");
|
||||
assert(s == " hello world", "got '%s'; want ' hello world'", s);
|
||||
free(s);
|
||||
|
||||
String str = "hello!";
|
||||
s = string::new_format("%-20s", str);
|
||||
s = string::format(mem, "%-20s", str);
|
||||
assert(s == "hello! ", "got '%s'; want 'hello! '", s);
|
||||
free(s);
|
||||
s = string::new_format("%20s", str);
|
||||
s = string::format(mem, "%20s", str);
|
||||
assert(s == " hello!", "got '%s'; want ' hello!'", s);
|
||||
free(s);
|
||||
|
||||
int[2] a = { 12, 23 };
|
||||
s = string::new_format("%-20s", a);
|
||||
s = string::format(mem, "%-20s", a);
|
||||
assert(s == "[12, 23] ", "got '%s'; want '[12, 23] '", s);
|
||||
free(s);
|
||||
s = string::new_format("%20s", a);
|
||||
s = string::format(mem, "%20s", a);
|
||||
assert(s == " [12, 23]", "got '%s'; want ' [12, 23]'", s);
|
||||
free(s);
|
||||
|
||||
s = string::new_format("%-20s", a[..]);
|
||||
s = string::format(mem, "%-20s", a[..]);
|
||||
assert(s == "[12, 23] ", "got '%s'; want '[12, 23] '", s);
|
||||
free(s);
|
||||
s = string::new_format("%20s", a[..]);
|
||||
s = string::format(mem, "%20s", a[..]);
|
||||
assert(s == " [12, 23]", "got '%s'; want ' [12, 23]'", s);
|
||||
free(s);
|
||||
|
||||
float[2] f = { 12.0, 23.0 };
|
||||
s = string::new_format("%-24s", f);
|
||||
s = string::format(mem, "%-24s", f);
|
||||
assert(s == "[12.000000, 23.000000] ", "got '%s'; want '[12.000000, 23.000000] '", s);
|
||||
free(s);
|
||||
s = string::new_format("%24s", f);
|
||||
s = string::format(mem, "%24s", f);
|
||||
assert(s == " [12.000000, 23.000000]", "got '%s'; want ' [12.000000, 23.000000]'", s);
|
||||
free(s);
|
||||
|
||||
int[<2>] vec = { 12, 23 };
|
||||
s = string::new_format("%-20s", vec);
|
||||
s = string::format(mem, "%-20s", vec);
|
||||
assert(s == "[<12, 23>] ", "got '%s'; want '[<12, 23>] '", s);
|
||||
free(s);
|
||||
s = string::new_format("%20s", vec);
|
||||
s = string::format(mem, "%20s", vec);
|
||||
assert(s == " [<12, 23>]", "got '%s'; want ' [<12, 23>]'", s);
|
||||
free(s);
|
||||
|
||||
String ss = "hello world";
|
||||
s = string::new_format("%.4s %.5s", ss, ss);
|
||||
s = string::format(mem, "%.4s %.5s", ss, ss);
|
||||
assert(s == "hell hello", "got '%s'; want 'hell hello'", s);
|
||||
free(s);
|
||||
}
|
||||
@@ -100,17 +100,17 @@ fn void printf_enum()
|
||||
{
|
||||
String s;
|
||||
|
||||
s = string::new_format("%s", PrintfTest.ENUMA);
|
||||
s = string::format(mem, "%s", PrintfTest.ENUMA);
|
||||
assert(s == "ENUMA", "got '%s'; want 'ENUMA'", s);
|
||||
free(s);
|
||||
s = string::new_format("%s", PrintfTest.ENUMB);
|
||||
s = string::format(mem, "%s", PrintfTest.ENUMB);
|
||||
assert(s == "ENUMB", "got '%s'; want 'ENUMB'", s);
|
||||
free(s);
|
||||
|
||||
s = string::new_format("%d", PrintfTest.ENUMA);
|
||||
s = string::format(mem, "%d", PrintfTest.ENUMA);
|
||||
assert(s == "0", "got '%s'; want '0'", s);
|
||||
free(s);
|
||||
s = string::new_format("%d", PrintfTest.ENUMB);
|
||||
s = string::format(mem, "%d", PrintfTest.ENUMB);
|
||||
assert(s == "1", "got '%s'; want '1'", s);
|
||||
free(s);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
module std::io @test;
|
||||
import std::collections::list;
|
||||
|
||||
def Results = List(<String>);
|
||||
def Results = List{String};
|
||||
|
||||
struct ScanTest
|
||||
{
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
module math_tests @test;
|
||||
import math_tests::complex;
|
||||
|
||||
def ComplexDouble = ComplexType(<double>) @local;
|
||||
def ComplexInt = ComplexType(<int>) @local;
|
||||
def ComplexDouble = ComplexType{double} @local;
|
||||
def ComplexInt = ComplexType{int} @local;
|
||||
|
||||
module math_tests::complex(<ElementType>) @test;
|
||||
module math_tests::complex{ElementType} @test;
|
||||
import std::math;
|
||||
|
||||
def ComplexType = Complex(<ElementType>);
|
||||
def ComplexType = Complex{ElementType};
|
||||
|
||||
fn void complex_mul_imaginary()
|
||||
{
|
||||
ComplexType i = complex::IMAGINARY(<ElementType>);
|
||||
ComplexType i = complex::IMAGINARY{ElementType};
|
||||
assert(i.mul(i).equals((ComplexType){-1, 0}));
|
||||
assert(i.mul(i).mul(i).equals((ComplexType){0, -1}));
|
||||
}
|
||||
@@ -47,7 +47,7 @@ fn void complex_conjugate()
|
||||
fn void complex_inverse() @if(types::is_float(ElementType))
|
||||
{
|
||||
ComplexType a = {3, 4};
|
||||
assert(a.inverse().mul(a).equals(complex::IDENTITY(<ElementType>)));
|
||||
assert(a.inverse().mul(a).equals(complex::IDENTITY{ElementType}));
|
||||
}
|
||||
|
||||
fn void complex_div() @if(types::is_float(ElementType))
|
||||
|
||||
@@ -50,8 +50,8 @@ fn void test_mat4()
|
||||
-0.988936, -2.970838, -20.765262, 1.000000
|
||||
};
|
||||
|
||||
Matrix4 look_at = matrix::look_at(<double>)({4.0, 5.0, 20.0}, {1.0, 3.0, 0.0}, {0.0, 1.0, 0.0});
|
||||
Matrix4f look_at_f = matrix::look_at(<float>)({4.0, 5.0, 20.0}, {1.0, 3.0, 0.0}, {0.0, 1.0, 0.0});
|
||||
Matrix4 look_at = matrix::look_at{double}({4.0, 5.0, 20.0}, {1.0, 3.0, 0.0}, {0.0, 1.0, 0.0});
|
||||
Matrix4f look_at_f = matrix::look_at{float}({4.0, 5.0, 20.0}, {1.0, 3.0, 0.0}, {0.0, 1.0, 0.0});
|
||||
|
||||
assert(math::round_to_decimals((double[<16>])look_at.m, 4) == math::round_to_decimals((double[<16>])result.m, 4));
|
||||
assert(math::round_to_decimals((float[<16>])look_at_f.m, 4) == math::round_to_decimals((float[<16>])result_f.m, 4));
|
||||
|
||||
@@ -11,14 +11,14 @@ fn String add(String s, Allocator a, int x)
|
||||
};
|
||||
ulong* y = mem::temp_alloc(ulong);
|
||||
*y = 0xAAAA_AAAA_AAAA_AAAA;
|
||||
return tmp.concat("a", allocator: a);
|
||||
return tmp.concat(a, "a");
|
||||
}
|
||||
|
||||
fn String breakit(String s, Allocator a)
|
||||
{
|
||||
@pool(a)
|
||||
{
|
||||
return inner2("foo".concat(s, allocator::temp()), a);
|
||||
return inner2("foo".concat(tmem(), s), a);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ fn String inner4(String s, Allocator a)
|
||||
{
|
||||
@pool(a)
|
||||
{
|
||||
String y = s.concat("xy**********", allocator::temp()).copy(a);
|
||||
String y = s.concat(tmem(), "xy**********").copy(a);
|
||||
return y;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,21 +12,21 @@ fn void test_ipv4()
|
||||
fn void test_ipv4_to_string()
|
||||
{
|
||||
InetAddress a = net::ipv4_from_str("127.0.0.1")!!;
|
||||
assert(a.to_new_string(allocator::temp()) == "127.0.0.1");
|
||||
assert(a.to_tstring() == "127.0.0.1");
|
||||
}
|
||||
|
||||
fn void test_ipv6_to_string()
|
||||
{
|
||||
InetAddress a = net::ipv6_from_str("2001:db8::2:1")!!;
|
||||
free(a.to_new_string());
|
||||
free(a.to_string(mem));
|
||||
|
||||
assert(a.to_new_string(allocator::temp()) == "2001:0db8:0000:0000:0000:0000:0002:0001");
|
||||
assert(net::ipv6_from_str("2001:db8::1").to_new_string(allocator::temp())!! == "2001:0db8:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("::1").to_new_string(allocator::temp())!! == "0000:0000:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("2001::1").to_new_string(allocator::temp())!! == "2001:0000:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("2001:db8:1234::").to_new_string(allocator::temp())!! == "2001:0db8:1234:0000:0000:0000:0000:0000");
|
||||
assert(net::ipv6_from_str("2001::").to_new_string(allocator::temp())!! == "2001:0000:0000:0000:0000:0000:0000:0000");
|
||||
assert(net::ipv6_from_str("::").to_new_string(allocator::temp())!! == "0000:0000:0000:0000:0000:0000:0000:0000");
|
||||
assert(a.to_tstring() == "2001:0db8:0000:0000:0000:0000:0002:0001");
|
||||
assert(net::ipv6_from_str("2001:db8::1").to_tstring()!! == "2001:0db8:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("::1").to_tstring()!! == "0000:0000:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("2001::1").to_tstring()!! == "2001:0000:0000:0000:0000:0000:0000:0001");
|
||||
assert(net::ipv6_from_str("2001:db8:1234::").to_tstring()!! == "2001:0db8:1234:0000:0000:0000:0000:0000");
|
||||
assert(net::ipv6_from_str("2001::").to_tstring()!! == "2001:0000:0000:0000:0000:0000:0000:0000");
|
||||
assert(net::ipv6_from_str("::").to_tstring()!! == "0000:0000:0000:0000:0000:0000:0000:0000");
|
||||
}
|
||||
|
||||
fn void test_ipv4_parse()
|
||||
|
||||
@@ -7,7 +7,7 @@ import std::net::url;
|
||||
|
||||
fn void test_parse_foo()
|
||||
{
|
||||
Url url = url::new_parse("foo://example.com:8042/over/there?name=ferret#nose")!!;
|
||||
Url url = url::parse(mem, "foo://example.com:8042/over/there?name=ferret#nose")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "foo", "got '%s'", url.scheme);
|
||||
@@ -22,7 +22,7 @@ fn void test_parse_foo()
|
||||
|
||||
fn void test_parse_urn()
|
||||
{
|
||||
Url url = url::new_parse("urn:example:animal:ferret:nose")!!;
|
||||
Url url = url::parse(mem, "urn:example:animal:ferret:nose")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "urn");
|
||||
@@ -37,7 +37,7 @@ fn void test_parse_urn()
|
||||
|
||||
fn void test_parse_jdbc()
|
||||
{
|
||||
Url url = url::new_parse("jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true")!!;
|
||||
Url url = url::parse(mem, "jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "jdbc:mysql");
|
||||
@@ -52,7 +52,7 @@ fn void test_parse_jdbc()
|
||||
|
||||
fn void test_parse_ftp()
|
||||
{
|
||||
Url url = url::new_parse("ftp://ftp.is.co.za/rfc/rfc1808.txt")!!;
|
||||
Url url = url::parse(mem, "ftp://ftp.is.co.za/rfc/rfc1808.txt")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "ftp");
|
||||
@@ -67,7 +67,7 @@ fn void test_parse_ftp()
|
||||
|
||||
fn void test_parse_http()
|
||||
{
|
||||
Url url = url::new_parse("http://www.ietf.org/rfc/rfc2396.txt#header1")!!;
|
||||
Url url = url::parse(mem, "http://www.ietf.org/rfc/rfc2396.txt#header1")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "http");
|
||||
@@ -82,7 +82,7 @@ fn void test_parse_http()
|
||||
|
||||
fn void test_parse_ldap()
|
||||
{
|
||||
Url url = url::new_parse("ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two")!!;
|
||||
Url url = url::parse(mem, "ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "ldap");
|
||||
@@ -97,7 +97,7 @@ fn void test_parse_ldap()
|
||||
|
||||
fn void test_parse_mailto()
|
||||
{
|
||||
Url url = url::new_parse("mailto:John.Doe@example.com")!!;
|
||||
Url url = url::parse(mem, "mailto:John.Doe@example.com")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "mailto");
|
||||
@@ -112,7 +112,7 @@ fn void test_parse_mailto()
|
||||
|
||||
fn void test_new_parses()
|
||||
{
|
||||
Url url = url::new_parse("news:comp.infosystems.www.servers.unix")!!;
|
||||
Url url = url::parse(mem, "news:comp.infosystems.www.servers.unix")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "news");
|
||||
@@ -127,7 +127,7 @@ fn void test_new_parses()
|
||||
|
||||
fn void test_parse_tel()
|
||||
{
|
||||
Url url = url::new_parse("tel:+1-816-555-1212")!!;
|
||||
Url url = url::parse(mem, "tel:+1-816-555-1212")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "tel");
|
||||
@@ -142,7 +142,7 @@ fn void test_parse_tel()
|
||||
|
||||
fn void test_parse_telnet()
|
||||
{
|
||||
Url url = url::new_parse("telnet://192.0.2.16:80/")!!;
|
||||
Url url = url::parse(mem, "telnet://192.0.2.16:80/")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "telnet");
|
||||
@@ -157,7 +157,7 @@ fn void test_parse_telnet()
|
||||
|
||||
fn void test_parse_urn2()
|
||||
{
|
||||
Url url = url::new_parse("urn:oasis:names:specification:docbook:dtd:xml:4.1.2")!!;
|
||||
Url url = url::parse(mem, "urn:oasis:names:specification:docbook:dtd:xml:4.1.2")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "urn");
|
||||
@@ -172,14 +172,14 @@ fn void test_parse_urn2()
|
||||
|
||||
fn void test_parse_empty()
|
||||
{
|
||||
assert(@catch(url::new_parse(" ")) == UrlParsingResult.EMPTY);
|
||||
assert(@catch(url::parse(mem, " ")) == UrlParsingResult.EMPTY);
|
||||
}
|
||||
|
||||
// Parser tests with escape sequences
|
||||
|
||||
fn void test_parse_path_with_escape_sequence()
|
||||
{
|
||||
Url url = url::new_parse("foo://example.com:8042/file/name%20one%26two?name=ferret#nose")!!;
|
||||
Url url = url::parse(mem, "foo://example.com:8042/file/name%20one%26two?name=ferret#nose")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "foo", "got '%s'", url.scheme);
|
||||
@@ -194,7 +194,7 @@ fn void test_parse_path_with_escape_sequence()
|
||||
|
||||
fn void test_parse_username_and_password_with_escape_sequence()
|
||||
{
|
||||
Url url = url::new_parse("jdbc:mysql://test%20user:ouu%40pppssss@localhost:3306/sakila?profileSQL=true")!!;
|
||||
Url url = url::parse(mem, "jdbc:mysql://test%20user:ouu%40pppssss@localhost:3306/sakila?profileSQL=true")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "jdbc:mysql");
|
||||
@@ -209,7 +209,7 @@ fn void test_parse_username_and_password_with_escape_sequence()
|
||||
|
||||
fn void test_parse_fragment_with_escape_sequence()
|
||||
{
|
||||
Url url = url::new_parse("http://www.ietf.org/rfc/rfc2396.txt#header%201%262")!!;
|
||||
Url url = url::parse(mem, "http://www.ietf.org/rfc/rfc2396.txt#header%201%262")!!;
|
||||
defer url.free();
|
||||
|
||||
assert(url.scheme == "http");
|
||||
@@ -227,8 +227,8 @@ fn void test_parse_fragment_with_escape_sequence()
|
||||
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);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
|
||||
assert(str == "foo://example.com:8042/over/there?name=ferret#nose");
|
||||
}
|
||||
@@ -236,8 +236,8 @@ fn void test_string_foo()
|
||||
fn void test_string_urn()
|
||||
{
|
||||
Url url = {.scheme="urn", .path="example:animal:ferret:nose"};
|
||||
String str = string::new_format("%s", url);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
|
||||
assert(str == "urn:example:animal:ferret:nose");
|
||||
}
|
||||
@@ -245,8 +245,8 @@ fn void test_string_urn()
|
||||
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);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
|
||||
assert(str == "jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true");
|
||||
}
|
||||
@@ -254,8 +254,8 @@ fn void test_string_jdbc()
|
||||
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);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
|
||||
assert(str == "ftp://ftp.is.co.za/rfc/rfc1808.txt");
|
||||
}
|
||||
@@ -263,8 +263,8 @@ fn void test_string_ftp()
|
||||
fn void test_string_http()
|
||||
{
|
||||
Url url = {.scheme="http", .host="www.ietf.org", .path="/rfc/rfc2396.txt", .fragment="header1"};
|
||||
String str = string::new_format("%s", url);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
|
||||
assert(str == "http://www.ietf.org/rfc/rfc2396.txt#header1", "got: '%s'", str);
|
||||
}
|
||||
@@ -272,8 +272,8 @@ fn void test_string_http()
|
||||
fn void test_string_ldap()
|
||||
{
|
||||
Url url = {.scheme="ldap", .host="[2001:db8::7]", .path="/c=GB", .query="objectClass=one&objectClass=two"};
|
||||
String str = string::new_format("%s", url);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
|
||||
assert(str == "ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two", "got: '%s'", str);
|
||||
}
|
||||
@@ -281,8 +281,8 @@ fn void test_string_ldap()
|
||||
fn void test_string_mailto()
|
||||
{
|
||||
Url url = {.scheme="mailto", .path="John.Doe@example.com"};
|
||||
String str = string::new_format("%s", url);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
|
||||
assert(str == "mailto:John.Doe@example.com");
|
||||
}
|
||||
@@ -290,16 +290,16 @@ fn void test_string_mailto()
|
||||
fn void test_string_news()
|
||||
{
|
||||
Url url = {.scheme="news", .path="comp.infosystems.www.servers.unix"};
|
||||
String str = string::new_format("%s", url);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
assert(str == "news:comp.infosystems.www.servers.unix");
|
||||
}
|
||||
|
||||
fn void test_string_tel()
|
||||
{
|
||||
Url url = {.scheme="tel", .path="+1-816-555-1212"};
|
||||
String str = string::new_format("%s", url);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
|
||||
assert(str == "tel:+1-816-555-1212");
|
||||
}
|
||||
@@ -307,8 +307,8 @@ fn void test_string_tel()
|
||||
fn void test_string_telnet()
|
||||
{
|
||||
Url url = {.scheme="telnet", .host="192.0.2.16", .port=80, .path="/"};
|
||||
String str = string::new_format("%s", url);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
|
||||
assert(str == "telnet://192.0.2.16:80/");
|
||||
}
|
||||
@@ -316,8 +316,8 @@ fn void test_string_telnet()
|
||||
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);
|
||||
defer str.free();
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
|
||||
assert(str == "urn:oasis:names:specification:docbook:dtd:xml:4.1.2");
|
||||
}
|
||||
@@ -325,20 +325,19 @@ fn void test_string_urn2()
|
||||
fn void test_string_empty()
|
||||
{
|
||||
Url url = {};
|
||||
String str = string::new_format("%s", url);
|
||||
defer str.free();
|
||||
|
||||
assert(str == "");
|
||||
String str = string::format(mem, "%s", url);
|
||||
defer free(str);
|
||||
test::eq(str, "");
|
||||
}
|
||||
|
||||
// query_values
|
||||
|
||||
fn void test_query_values1()
|
||||
{
|
||||
Url url = url::new_parse("foo://example.com:8042/over/there?name=ferret=ok#nose")!!;
|
||||
Url url = url::parse(mem, "foo://example.com:8042/over/there?name=ferret=ok#nose")!!;
|
||||
defer url.free();
|
||||
|
||||
UrlQueryValues vals = url::temp_parse_query(url.query);
|
||||
UrlQueryValues vals = url::parse_query_to_temp(url.query);
|
||||
defer vals.free();
|
||||
|
||||
assert(vals.len() == 1);
|
||||
@@ -350,10 +349,10 @@ fn void test_query_values1()
|
||||
|
||||
fn void test_query_values2()
|
||||
{
|
||||
Url url = url::new_parse("foo://example.com:8042/over/there?name=ferret&age=99&age=11#nose")!!;
|
||||
Url url = url::parse(mem, "foo://example.com:8042/over/there?name=ferret&age=99&age=11#nose")!!;
|
||||
defer url.free();
|
||||
|
||||
UrlQueryValues vals = url::new_parse_query(url.query);
|
||||
UrlQueryValues vals = url::parse_query(mem, url.query);
|
||||
defer vals.free();
|
||||
assert(vals.len() == 2);
|
||||
|
||||
@@ -369,10 +368,10 @@ fn void test_query_values2()
|
||||
|
||||
fn void test_escaped_query_values()
|
||||
{
|
||||
Url url = url::new_parse("foo://example.com:8042/over/there?k%3Bey=%3Ckey%3A+0x90%3E&age=99&age=11#nose")!!;
|
||||
Url url = url::parse(mem, "foo://example.com:8042/over/there?k%3Bey=%3Ckey%3A+0x90%3E&age=99&age=11#nose")!!;
|
||||
defer url.free();
|
||||
|
||||
UrlQueryValues vals = url::new_parse_query(url.query);
|
||||
UrlQueryValues vals = url::parse_query(mem, url.query);
|
||||
defer vals.free();
|
||||
assert(vals.len() == 2);
|
||||
|
||||
@@ -383,10 +382,10 @@ fn void test_escaped_query_values()
|
||||
|
||||
fn void test_query_values_withempty()
|
||||
{
|
||||
Url url = url::new_parse("foo://example.com:8042/over/there?name=ferret&&&age=99&age=11")!!;
|
||||
Url url = url::parse(mem, "foo://example.com:8042/over/there?name=ferret&&&age=99&age=11")!!;
|
||||
defer url.free();
|
||||
|
||||
UrlQueryValues vals = url::new_parse_query(url.query);
|
||||
UrlQueryValues vals = url::parse_query(mem, url.query);
|
||||
defer vals.free();
|
||||
assert(vals.len() == 2);
|
||||
}
|
||||
@@ -402,8 +401,9 @@ fn void test_url_idempotence()
|
||||
query_builder.add("profileSQL", "true");
|
||||
query_builder.add("k;ey", "<key: 0x90>");
|
||||
|
||||
String query = query_builder.to_string();
|
||||
defer query.free();
|
||||
String query = string::format(mem, "%s", query_builder);
|
||||
io::printn(query);
|
||||
defer free(query);
|
||||
|
||||
Url url = {
|
||||
.scheme = "jdbc:mysql",
|
||||
@@ -416,17 +416,17 @@ fn void test_url_idempotence()
|
||||
.fragment = "no se",
|
||||
};
|
||||
|
||||
String url_string = url.to_string();
|
||||
defer url_string.free();
|
||||
String url_string = string::format(mem, "%s", url);
|
||||
defer free(url_string);
|
||||
|
||||
String want = "jdbc:mysql://test%20user:ouu%40pppssss@localhost:3306"
|
||||
"/sakila?profileSQL=true&k%3Bey=%3Ckey%3A+0x90%3E#no%20se";
|
||||
assert(url_string == want, "got: %s, want: %s", url_string, want);
|
||||
|
||||
Url parsed = url::new_parse(url_string)!!;
|
||||
Url parsed = url::parse(mem, url_string)!!;
|
||||
defer parsed.free();
|
||||
|
||||
UrlQueryValues vals = url::new_parse_query(parsed.query);
|
||||
UrlQueryValues vals = url::parse_query(mem, parsed.query);
|
||||
defer vals.free();
|
||||
assert(vals.len() == 2);
|
||||
|
||||
@@ -439,8 +439,8 @@ fn void test_url_idempotence()
|
||||
assert(key.len() == 1);
|
||||
assert(key[0] == "true");
|
||||
|
||||
String parsed_query = vals.to_string();
|
||||
defer parsed_query.free();
|
||||
String parsed_query = string::format(mem, "%s", vals);
|
||||
defer free(parsed_query);
|
||||
|
||||
assert(parsed.scheme == url.scheme);
|
||||
assert(parsed.host == url.host);
|
||||
@@ -451,8 +451,8 @@ fn void test_url_idempotence()
|
||||
assert(parsed.query == parsed_query);
|
||||
assert(parsed.fragment == url.fragment);
|
||||
|
||||
String parsed_string = parsed.to_string();
|
||||
defer parsed_string.free();
|
||||
String parsed_string = string::format(mem, "%s", parsed);
|
||||
defer free(parsed_string);
|
||||
|
||||
assert(url_string == parsed_string);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ fn void test_decoding_with_error() => @pool()
|
||||
{
|
||||
foreach (test: decode_with_error_tests)
|
||||
{
|
||||
String! actual = url::temp_decode(test.in, test.mode);
|
||||
String! actual = url::tdecode(test.in, test.mode);
|
||||
if (catch excuse = actual)
|
||||
{
|
||||
assert(excuse == test.err, "unescape(%s, %s); "
|
||||
@@ -64,11 +64,11 @@ fn void test_percent_encode_and_decode() => @pool()
|
||||
{
|
||||
foreach (test: encode_tests)
|
||||
{
|
||||
String actual = url::temp_encode(test.in, test.mode);
|
||||
String actual = url::tencode(test.in, test.mode);
|
||||
assert(actual == test.out, "escape(%s, %s); "
|
||||
"got: %s, want: %s", test.in, test.mode, actual, test.out);
|
||||
|
||||
actual = url::temp_decode(test.out, test.mode)!!;
|
||||
actual = url::tdecode(test.out, test.mode)!!;
|
||||
assert(actual == test.in, "unescape(%s, %s); "
|
||||
"got: %s, want: %s", test.out, test.mode, actual, test.in);
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ module std::os::env @test;
|
||||
const VALUE = "foobar";
|
||||
|
||||
env::set_var(NAME, VALUE);
|
||||
String v = env::get_var(NAME)!!;
|
||||
String v = env::get_var(mem, NAME)!!;
|
||||
assert(v == VALUE, "got %s; want %s", v, VALUE);
|
||||
free(v);
|
||||
env::clear_var(NAME);
|
||||
if (try env::get_var(NAME))
|
||||
if (try env::get_var(mem, NAME))
|
||||
{
|
||||
unreachable("environment variable should no longer exist");
|
||||
}
|
||||
|
||||
@@ -1,100 +1,100 @@
|
||||
module sort_test @test;
|
||||
import std::math;
|
||||
import std::sort;
|
||||
import sort::check;
|
||||
import std::collections::list;
|
||||
import std::math;
|
||||
import std::sort;
|
||||
import sort::check;
|
||||
import std::collections::list;
|
||||
|
||||
fn void countingsort()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
fn void countingsort()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
|
||||
fn void countingsort_with_ref()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
fn void countingsort_with_ref()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, &sort::key_int_ref);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, &sort::key_int_ref);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
|
||||
fn void countingsort_with_value()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
fn void countingsort_with_value()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
|
||||
fn void countingsort_with_lambda()
|
||||
{
|
||||
int[][] tcases = {
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
fn void countingsort_with_lambda()
|
||||
{
|
||||
int[][] tcases =
|
||||
{
|
||||
{},
|
||||
{[0..128] = 10, [129..192] = 3},
|
||||
{[0..128] = 3, [129..192] = 2, [193..200] = 1},
|
||||
{[0..128] = 1, [129..192] = 2, [193..200] = 3},
|
||||
{[0..128] = 2, [129..192] = 1, [193..200] = 3},
|
||||
};
|
||||
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, fn uint(int a) => ((uint)(a + int.min)));
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
foreach (tc : tcases)
|
||||
{
|
||||
sort::countingsort(tc, fn uint(int a) => ((uint)(a + int.min)));
|
||||
assert(check::int_ascending_sort(tc));
|
||||
}
|
||||
}
|
||||
|
||||
def CountingSortTestList = List(<int>);
|
||||
def CountingSortTestList = List{int};
|
||||
|
||||
fn void countingsort_list()
|
||||
{
|
||||
CountingSortTestList list;
|
||||
list.tinit();
|
||||
list.add_array({ 2, 1, 3});
|
||||
sort::countingsort(list, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(list.array_view()));
|
||||
}
|
||||
fn void countingsort_list()
|
||||
{
|
||||
CountingSortTestList list;
|
||||
list.add_array({ 2, 1, 3});
|
||||
sort::countingsort(list, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(list.array_view()));
|
||||
}
|
||||
|
||||
fn void countingsort_random_large_list()
|
||||
{
|
||||
Lcg128Random random;
|
||||
random::seed_entropy(&random);
|
||||
fn void countingsort_random_large_list()
|
||||
{
|
||||
Lcg128Random random;
|
||||
random::seed_entropy(&random);
|
||||
|
||||
CountingSortTestList list;
|
||||
for (usz i = 0; i < 2048; i++) {
|
||||
list.push(random.next_int());
|
||||
}
|
||||
|
||||
sort::countingsort(list, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(list.array_view()));
|
||||
list.free();
|
||||
CountingSortTestList list;
|
||||
for (usz i = 0; i < 2048; i++)
|
||||
{
|
||||
list.push(random.next_int());
|
||||
}
|
||||
|
||||
sort::countingsort(list, &sort::key_int_value);
|
||||
assert(check::int_ascending_sort(list.array_view()));
|
||||
list.free();
|
||||
}
|
||||
@@ -78,12 +78,11 @@ fn void insertionsort_with_lambda()
|
||||
}
|
||||
}
|
||||
|
||||
def InsertionSortTestList = List(<int>);
|
||||
def InsertionSortTestList = List{int};
|
||||
|
||||
fn void insertionsort_list()
|
||||
{
|
||||
InsertionSortTestList list;
|
||||
list.tinit();
|
||||
list.add_array({ 2, 1, 3});
|
||||
sort::insertionsort(list, &sort::cmp_int_value);
|
||||
assert(check::int_ascending_sort(list.array_view()));
|
||||
|
||||
@@ -78,12 +78,11 @@ fn void quicksort_with_lambda()
|
||||
}
|
||||
}
|
||||
|
||||
def List = List(<int>);
|
||||
def List = List{int};
|
||||
|
||||
fn void quicksort_list()
|
||||
{
|
||||
List list;
|
||||
list.tinit();
|
||||
list.add_array({ 2, 1, 3});
|
||||
sort::quicksort(list, &sort::cmp_int_value);
|
||||
assert(check::int_sort(list.array_view()));
|
||||
|
||||
@@ -66,13 +66,13 @@ fn void sorted()
|
||||
tc.input, got, tc.want);
|
||||
|
||||
// with list
|
||||
List(<int>) list;
|
||||
List{int} list;
|
||||
list.tinit();
|
||||
list.add_array(tc.input);
|
||||
|
||||
got = is_sorted(list);
|
||||
assert(got == tc.want, "list: %s, got: %s, want: %s",
|
||||
list.to_tstring(), got, tc.want);
|
||||
list, got, tc.want);
|
||||
|
||||
// with lambda
|
||||
got = is_sorted(tc.input, fn int(int a, int b) => a - b);
|
||||
|
||||
@@ -2,7 +2,7 @@ module string_test;
|
||||
|
||||
fn void test_clear() @test
|
||||
{
|
||||
DString s = dstring::new_with_capacity(32);
|
||||
DString s = dstring::new_with_capacity(mem, 32);
|
||||
defer s.free();
|
||||
assert(s.len() == 0);
|
||||
assert(s.capacity() == 32);
|
||||
|
||||
@@ -9,7 +9,7 @@ fn void init_destroy_buffered() @test
|
||||
{
|
||||
for (usz i = 0; i < 20; i++)
|
||||
{
|
||||
BufferedChannel(<int>) c;
|
||||
BufferedChannel{int} c;
|
||||
c.init(mem, 1)!!;
|
||||
defer c.destroy()!!;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ fn void init_destroy_unbuffered() @test
|
||||
{
|
||||
for (usz i = 0; i < 20; i++)
|
||||
{
|
||||
UnbufferedChannel(<int>) c;
|
||||
UnbufferedChannel{int} c;
|
||||
c.init(mem)!!;
|
||||
defer c.destroy()!!;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ fn void init_destroy_unbuffered() @test
|
||||
|
||||
fn void push_to_buffered_channel_no_lock() @test
|
||||
{
|
||||
BufferedChannel(<int>) c;
|
||||
BufferedChannel{int} c;
|
||||
c.init(mem, 1)!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -36,7 +36,7 @@ fn void push_to_buffered_channel_no_lock() @test
|
||||
|
||||
fn void push_pop_buffered_no_locks() @test
|
||||
{
|
||||
BufferedChannel(<int>) c;
|
||||
BufferedChannel{int} c;
|
||||
c.init(mem, 1)!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -47,7 +47,7 @@ fn void push_pop_buffered_no_locks() @test
|
||||
|
||||
fn void push_pop_unbuffered_with_locks() @test
|
||||
{
|
||||
UnbufferedChannel(<int>) c;
|
||||
UnbufferedChannel{int} c;
|
||||
c.init(mem)!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -56,7 +56,7 @@ fn void push_pop_unbuffered_with_locks() @test
|
||||
|
||||
thread.create(fn int(void* arg)
|
||||
{
|
||||
UnbufferedChannel(<int>) c = (UnbufferedChannel(<int>))arg;
|
||||
UnbufferedChannel{int} c = (UnbufferedChannel{int})arg;
|
||||
c.push(123)!!;
|
||||
c.push(321)!!;
|
||||
return 0;
|
||||
@@ -70,8 +70,8 @@ fn void push_pop_unbuffered_with_locks() @test
|
||||
|
||||
fn void sending_to_closed_unbuffered_chan_is_forbidden() @test
|
||||
{
|
||||
UnbufferedChannel(<int>) c;
|
||||
c.init(mem)!!;
|
||||
UnbufferedChannel{int} c;
|
||||
c.init(mem, )!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
c.close()!!;
|
||||
@@ -86,7 +86,7 @@ fn void sending_to_closed_unbuffered_chan_is_forbidden() @test
|
||||
|
||||
fn void sending_to_closed_buffered_chan_is_forbidden() @test
|
||||
{
|
||||
BufferedChannel(<int>) c;
|
||||
BufferedChannel{int} c;
|
||||
c.init(mem, 1)!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -102,8 +102,8 @@ fn void sending_to_closed_buffered_chan_is_forbidden() @test
|
||||
|
||||
fn void reading_from_empty_closed_unbuffered_chan_is_forbidden() @test
|
||||
{
|
||||
UnbufferedChannel(<int>) c;
|
||||
c.init(mem)!!;
|
||||
UnbufferedChannel{int} c;
|
||||
c.init(mem, )!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
c.close()!!;
|
||||
@@ -118,7 +118,7 @@ fn void reading_from_empty_closed_unbuffered_chan_is_forbidden() @test
|
||||
|
||||
fn void reading_from_empty_closed_buffered_chan_is_forbidden() @test
|
||||
{
|
||||
BufferedChannel(<int>) c;
|
||||
BufferedChannel{int} c;
|
||||
c.init(mem, 1)!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -134,7 +134,7 @@ fn void reading_from_empty_closed_buffered_chan_is_forbidden() @test
|
||||
|
||||
fn void reading_from_non_empty_closed_buffered_chan_is_ok() @test
|
||||
{
|
||||
BufferedChannel(<int>) c;
|
||||
BufferedChannel{int} c;
|
||||
c.init(mem, 3)!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -163,7 +163,7 @@ fn void reading_from_non_empty_closed_buffered_chan_is_ok() @test
|
||||
|
||||
fn void reading_from_empty_buffered_chan_aborted_by_close() @test
|
||||
{
|
||||
BufferedChannel(<int>) c;
|
||||
BufferedChannel{int} c;
|
||||
c.init(mem, 3)!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -172,7 +172,7 @@ fn void reading_from_empty_buffered_chan_aborted_by_close() @test
|
||||
|
||||
thread.create(fn int(void* arg)
|
||||
{
|
||||
BufferedChannel(<int>) c = (BufferedChannel(<int>))arg;
|
||||
BufferedChannel{int} c = (BufferedChannel{int})arg;
|
||||
c.close()!!;
|
||||
return 0;
|
||||
}, (void*)c)!!;
|
||||
@@ -189,8 +189,8 @@ fn void reading_from_empty_buffered_chan_aborted_by_close() @test
|
||||
|
||||
fn void reading_from_unbuffered_chan_aborted_by_close() @test
|
||||
{
|
||||
UnbufferedChannel(<int>) c;
|
||||
c.init(mem)!!;
|
||||
UnbufferedChannel{int} c;
|
||||
c.init(mem, )!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
Thread thread;
|
||||
@@ -198,7 +198,7 @@ fn void reading_from_unbuffered_chan_aborted_by_close() @test
|
||||
|
||||
thread.create(fn int(void* arg)
|
||||
{
|
||||
UnbufferedChannel(<int>) c = (UnbufferedChannel(<int>))arg;
|
||||
UnbufferedChannel{int} c = (UnbufferedChannel{int})arg;
|
||||
c.close()!!;
|
||||
return 0;
|
||||
}, (void*)c)!!;
|
||||
@@ -215,7 +215,7 @@ fn void reading_from_unbuffered_chan_aborted_by_close() @test
|
||||
|
||||
fn void sending_to_full_buffered_chan_aborted_by_close() @test
|
||||
{
|
||||
BufferedChannel(<int>) c;
|
||||
BufferedChannel{int} c;
|
||||
c.init(mem, 1)!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -226,7 +226,7 @@ fn void sending_to_full_buffered_chan_aborted_by_close() @test
|
||||
|
||||
thread.create(fn int(void* arg)
|
||||
{
|
||||
BufferedChannel(<int>) c = (BufferedChannel(<int>))arg;
|
||||
BufferedChannel{int} c = (BufferedChannel{int})arg;
|
||||
c.close()!!;
|
||||
return 0;
|
||||
}, (void*)c)!!;
|
||||
@@ -243,7 +243,7 @@ fn void sending_to_full_buffered_chan_aborted_by_close() @test
|
||||
|
||||
fn void sending_to_unbuffered_chan_aborted_by_close() @test
|
||||
{
|
||||
UnbufferedChannel(<int>) c;
|
||||
UnbufferedChannel{int} c;
|
||||
c.init(mem, )!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -252,7 +252,7 @@ fn void sending_to_unbuffered_chan_aborted_by_close() @test
|
||||
|
||||
thread.create(fn int(void* arg)
|
||||
{
|
||||
UnbufferedChannel(<int>) c = (UnbufferedChannel(<int>))arg;
|
||||
UnbufferedChannel{int} c = (UnbufferedChannel{int})arg;
|
||||
c.close()!!;
|
||||
return 0;
|
||||
}, (void*)c)!!;
|
||||
@@ -269,7 +269,7 @@ fn void sending_to_unbuffered_chan_aborted_by_close() @test
|
||||
|
||||
fn void multiple_actions_unbuffered() @test
|
||||
{
|
||||
UnbufferedChannel(<int>) c;
|
||||
UnbufferedChannel{int} c;
|
||||
c.init(mem, )!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -278,7 +278,7 @@ fn void multiple_actions_unbuffered() @test
|
||||
|
||||
thread.create(fn int(void* arg)
|
||||
{
|
||||
UnbufferedChannel(<int>) c = (UnbufferedChannel(<int>))arg;
|
||||
UnbufferedChannel{int} c = (UnbufferedChannel{int})arg;
|
||||
for (int i = 0; i <= 100; i++)
|
||||
{
|
||||
c.push(i)!!;
|
||||
@@ -303,7 +303,7 @@ fn void multiple_actions_unbuffered() @test
|
||||
|
||||
fn void multiple_actions_buffered() @test
|
||||
{
|
||||
BufferedChannel(<int>) c;
|
||||
BufferedChannel{int} c;
|
||||
c.init(mem, 10)!!;
|
||||
defer c.destroy()!!;
|
||||
|
||||
@@ -312,7 +312,7 @@ fn void multiple_actions_buffered() @test
|
||||
|
||||
thread.create(fn int(void* arg)
|
||||
{
|
||||
BufferedChannel(<int>) c = (BufferedChannel(<int>))arg;
|
||||
BufferedChannel{int} c = (BufferedChannel{int})arg;
|
||||
for (int i = 0; i <= 100; i++)
|
||||
{
|
||||
c.push(i)!!;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module thread_pool_test;
|
||||
import std::io, std::thread, std::time;
|
||||
|
||||
def Pool = ThreadPool(<4>);
|
||||
def Pool = ThreadPool{4};
|
||||
|
||||
fn void init_destroy() @test
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@ module timeformat_test @test;
|
||||
|
||||
import std::time::datetime, std::collections::list, std::collections::triple;
|
||||
|
||||
def FormatTzTestSpec = Triple(<TzDateTime, DateTimeFormat, String>);
|
||||
def FormatTestSpec = Triple(<DateTime, DateTimeFormat, String>);
|
||||
def FormatTzTestSpec = Triple{TzDateTime, DateTimeFormat, String};
|
||||
def FormatTestSpec = Triple{DateTime, DateTimeFormat, String};
|
||||
|
||||
fn void test_with_tz()
|
||||
{
|
||||
@@ -27,7 +27,7 @@ fn void test_with_tz()
|
||||
|
||||
foreach (test : tests)
|
||||
{
|
||||
String candidate = test.first.new_format(test.second);
|
||||
String candidate = test.first.format(mem, test.second);
|
||||
defer free(candidate);
|
||||
assert(candidate == test.third, "got: '%s', expected: '%s'", candidate, test.third);
|
||||
}
|
||||
@@ -44,7 +44,7 @@ fn void test_without_tz()
|
||||
|
||||
foreach (test : tests)
|
||||
{
|
||||
String candidate = test.first.new_format(test.second);
|
||||
String candidate = test.first.format(mem, test.second);
|
||||
defer free(candidate);
|
||||
assert(candidate == test.third, "got: '%s', expected: '%s'", candidate, test.third);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user