Removing use of $assignable and deprecate it. Fix regression for stacktraces on MacOS. Added readline_to_stream. Regression: Chaining an optional together with contracts could in some cases lose the optional.

This commit is contained in:
Christoffer Lerno
2025-07-21 03:20:40 +02:00
parent 382a65abcd
commit 869bcf8b2b
18 changed files with 116 additions and 69 deletions

View File

@@ -2,14 +2,14 @@ module castable @test;
fn void assignable()
{
assert($assignable(12.0, int) == false);
assert($assignable(12, int));
assert(!$assignable("12", int));
assert($assignable("12", String));
assert($assignable("12", char*));
assert($assignable("12", char[*]));
assert($assignable("12", char[2]));
assert($assignable("12", char[3]));
assert(@assignable_to(12.0, int) == false);
assert(@assignable_to(12, int));
assert(!@assignable_to("12", int));
assert(@assignable_to("12", String));
assert(@assignable_to("12", char*));
//assert($assignable("12", char[*]));
assert(@assignable_to("12", char[2]));
assert(@assignable_to("12", char[3]));
}
fn void castable()

View File

@@ -6,7 +6,7 @@ alias IntMap = HashMap{String, int};
fn void copy_map() @test
{
TrackingAllocator alloc;
alloc.init(allocator::heap());
alloc.init(mem);
defer alloc.free();
assert(alloc.allocated() == 0);
mem::@scoped(&alloc)

View File

@@ -3,14 +3,14 @@ import std::collections::object;
fn void test_general()
{
Object* root = object::new_obj(allocator::heap());
Object* root = object::new_obj(mem);
defer root.free();
root.set("foo", 1);
root.set("bar", "baz");
assert(root.get_int("foo")!! == 1);
assert(root.get_string("bar")!! == "baz");
Object* goo = root.set("goo", object::new_obj(allocator::heap()));
Object* goo = root.set("goo", object::new_obj(mem));
goo.push("hello");
goo.push(132);
assert(root.get("goo").get_int_at(1)!! == 132);
@@ -27,14 +27,14 @@ fn void test_general()
fn void test_to_format_int()
{
{
Object* int_object = object::new_int(16, allocator::heap());
Object* int_object = object::new_int(16, mem);
defer int_object.free();
String s = string::format(mem, "%s", int_object);
defer free(s);
assert(s == "16");
}
{
Object* int_object = object::new_int(-16, allocator::heap());
Object* int_object = object::new_int(-16, mem);
defer int_object.free();
String s = string::format(mem, "%s", int_object);
defer free(s);

View File

@@ -17,9 +17,9 @@ struct Bar
fn void test_new_aligned_compiles() @test
{
Bar* bar2 = allocator::new_aligned(allocator::heap(), Bar)!!;
allocator::free_aligned(allocator::heap(), bar2);
Bar* bar2 = allocator::new_aligned(mem, Bar)!!;
allocator::free_aligned(mem, bar2);
Bar* bar = allocator::new_aligned(allocator::heap(), Bar, {.x = 1, .y = 2, .foos = {}})!!;
allocator::free_aligned(allocator::heap(), bar);
Bar* bar = allocator::new_aligned(mem, Bar, {.x = 1, .y = 2, .foos = {}})!!;
allocator::free_aligned(mem, bar);
}

View File

@@ -36,7 +36,7 @@ fn void test_parent()
p.free();
}
fn void test_path_normalized() => mem::@scoped(allocator::temp())
fn void test_path_normalized() => mem::@scoped(tmem)
{
assert(path::new(mem, "", path_env: PathEnv.WIN32).str_view()!! == "");
assert(@catch(path::new(mem, "1:\\a\\b\\c.txt", path_env: PathEnv.WIN32)));
@@ -212,7 +212,7 @@ fn void test_path_normalized() => mem::@scoped(allocator::temp())
}
fn void test_extension() => mem::@scoped(allocator::temp())
fn void test_extension() => mem::@scoped(tmem)
{
assert(@catch(path::new(mem, `C:`, path_env: PathEnv.WIN32).extension()));
assert(@catch(path::new(mem, `C:`, path_env: PathEnv.POSIX).extension()));
@@ -246,7 +246,7 @@ fn void test_extension() => mem::@scoped(allocator::temp())
}
fn void test_has_extension() => mem::@scoped(allocator::temp())
fn void test_has_extension() => mem::@scoped(tmem)
{
assert(!path::new(mem, `C:\temp\foo.bar\README`, path_env: PathEnv.WIN32)!!.has_extension(`bar\README`));
@@ -276,7 +276,7 @@ fn void test_has_extension() => mem::@scoped(allocator::temp())
}
fn void test_basename() => mem::@scoped(allocator::temp())
fn void test_basename() => mem::@scoped(tmem)
{
assert(path::for_windows(mem, "file.txt").basename()!! == "file.txt");
assert(path::for_posix(mem, "file.txt").basename()!! == "file.txt");
@@ -303,7 +303,7 @@ fn void test_basename() => mem::@scoped(allocator::temp())
assert(path::for_posix(mem, `\\server\abc`).basename()!! == `\\server\abc`);
}
fn void test_dirname() => mem::@scoped(allocator::temp())
fn void test_dirname() => mem::@scoped(tmem)
{
assert(path::for_posix(mem, "").dirname()!! == ".");
assert(path::for_posix(mem, "/file").dirname()!! == "/");
@@ -343,7 +343,7 @@ fn void test_dirname() => mem::@scoped(allocator::temp())
assert(path::for_posix(mem, `\\server\`).dirname()!! == `.`);
}
fn void test_path_volume() => mem::@scoped(allocator::temp())
fn void test_path_volume() => mem::@scoped(tmem)
{
assert(path::for_windows(mem, `C:\abs`).volume_name()!! == `C:`);
assert(path::for_windows(mem, `C:abs`).volume_name()!! == `C:`);
@@ -353,7 +353,7 @@ fn void test_path_volume() => mem::@scoped(allocator::temp())
assert(path::for_windows(mem, `\\server\foo\abc`).volume_name()!! == `\\server\foo`);
}
fn void test_path_is_absolute() => mem::@scoped(allocator::temp())
fn void test_path_is_absolute() => mem::@scoped(tmem)
{
assert(!path::for_posix(mem, "").is_absolute()!!);
assert(path::for_posix(mem, "/").is_absolute()!!);
@@ -367,7 +367,7 @@ fn void test_path_is_absolute() => mem::@scoped(allocator::temp())
assert(path::for_windows(mem, `\\server\foo\abc`).is_absolute()!!);
}
fn void test_path_absolute() => mem::@scoped(allocator::temp())
fn void test_path_absolute() => mem::@scoped(tmem)
{
$if env::WIN32:
assert(path::for_windows(mem, `C:\abs`).absolute(mem, )!!.str_view() == `C:\abs`);

View File

@@ -75,7 +75,7 @@ fn void write_short_bytearray_test()
fn void read_tiny_bytearray_test()
{
ByteReader reader = io::wrap_bytes(&&x'07aabbcc00112233');
char[] read = io::read_tiny_bytearray(&reader, allocator: allocator::heap())!!;
char[] read = io::read_tiny_bytearray(&reader, allocator: mem)!!;
assert(read == &&x'aabbcc00112233');
free(read);
}
@@ -83,7 +83,7 @@ fn void read_tiny_bytearray_test()
fn void read_short_bytearray_test()
{
ByteReader reader = io::wrap_bytes(&&x'0007aabbcc00112233');
char[] read = io::read_short_bytearray(&reader, allocator: allocator::heap())!!;
char[] read = io::read_short_bytearray(&reader, allocator: mem)!!;
assert(read == &&x'aabbcc00112233');
free(read);
}

View File

@@ -11,7 +11,7 @@ fn void init_with_array()
BigInt bi @noinit;
assert(bi.init_with_array({}).equals(ZERO));
assert(bi.init_with_array({0, 0, 0, 1}).equals(bigint::from_int(1)));
assert("100000000" == bi.init_with_array({1, 0}).to_string_with_radix(16, allocator::temp()));
assert("100000000" == bi.init_with_array({1, 0}).to_string_with_radix(16, tmem));
}
fn void test_parse16()
@@ -22,10 +22,10 @@ fn void test_parse16()
fn void test_zero()
{
assert(bigint::from_int(0).to_string(allocator::temp()) == "0");
assert(bigint::from_int(0).to_string(tmem) == "0");
BigInt bi;
bi.init_string_radix("00", 16)!!;
assert(bi.to_string(allocator::temp()) == "0");
assert(bi.to_string(tmem) == "0");
}
fn void test_plus()

View File

@@ -59,10 +59,10 @@ fn String inner4(String s, Allocator a)
fn void test_temp_allocator() @test
{
assert("foofoofoofoofoofooabcaaaaaa" == add("abc", allocator::temp(), 5), "was %s", add("abc", allocator::temp(), 5));
assert("foofoofoofoofoofooabcaaaaaa" == add("abc", tmem, 5), "was %s", add("abc", tmem, 5));
}
fn void test_temp_allocator2() @test
{
assert("fooxyz0123456789xy**********" == breakit("xyz0123456789", allocator::temp()));
assert("fooxyz0123456789xy**********" == breakit("xyz0123456789", tmem));
}