Use printn rather than println. Add string methods for copying.

This commit is contained in:
Christoffer Lerno
2023-02-04 15:38:06 +01:00
committed by Christoffer Lerno
parent 6b928c7a3d
commit dce171670f
39 changed files with 1627 additions and 677 deletions

View File

@@ -50,7 +50,7 @@ import libc;
private TestRunner* current_runner;
fn void test_panic(String message, String file, String function, uint line)
{
io::println("[error]");
io::printn("[error]");
io::printfn("\n Error: %s", message);
io::printfn(" - in %s %s:%s.\n", function, file, line);
libc::longjmp(&current_runner.buf, 1);
@@ -64,7 +64,7 @@ fn bool TestRunner.run(TestRunner* runner)
builtin::panic = &test_panic;
int tests_passed = 0;
int tests = runner.test_names.len;
io::println("----- TESTS -----");
io::printn("----- TESTS -----");
foreach(i, String name : runner.test_names)
{
io::printf("Testing %s ... ", name);
@@ -72,10 +72,10 @@ fn bool TestRunner.run(TestRunner* runner)
{
if (catch err = runner.test_fns[i]())
{
io::println("[failed]");
io::printn("[failed]");
continue;
}
io::println("[ok]");
io::printn("[ok]");
tests_passed++;
}
}

View File

@@ -239,6 +239,11 @@ fn usz! index_of(String s, String needle)
return SearchResult.MISSING!;
}
fn ZString String.zstrcopy(String s, Allocator* allocator = mem::current_allocator()) => copy_zstring(s, allocator) @inline;
fn ZString String.zstrtcopy(String s) => copy_zstring(s, mem::temp_allocator()) @inline;
fn String String.copyz(String s, Allocator* allocator = mem::current_allocator()) => copyz(s, allocator) @inline;
fn String String.tcopyz(String s) => copyz(s, mem::temp_allocator()) @inline;
fn ZString copy_zstring(String s, Allocator* allocator = mem::current_allocator())
{
usz len = s.len;
@@ -248,6 +253,7 @@ fn ZString copy_zstring(String s, Allocator* allocator = mem::current_allocator(
return (ZString)str;
}
fn String copyz(String s, Allocator* allocator = mem::current_allocator())
{
usz len = s.len;

View File

@@ -271,12 +271,12 @@ macro void VarString.append(VarString* str, value)
$case Char32:
str.append_char32(value);
$default:
$if (@convertible($Type, Char32)):
$if (@convertible(value, Char32)):
str.append_char32(value);
$elif (@convertible($Type, String)):
$elif (@convertible(value, String)):
str.append_chars(value);
$else:
$assert("Unsupported type for appending");
$assert(false, "Unsupported type for append use printf instead.");
$endif;
$endswitch;
}