fix Object.free (#982)

* lib/std/collections: add HashMap.@each_entry()
* lib/std/json: fix Object.free() when object is a map
* lib/std/collections: fix allocator use in Object.{set,set_at,append}
* lib/std: add char.from_hex
* lib/std/collections: print arrays and objects compactly
* lib/std/io: fix Formatter.vprintf result
* lib/std/io/stream: rename module for ByteBuffer
* lib/std/io/stream: make Scanner a Stream reader
* lib/std/io: make std{in,err,out} return File* if no libc
This commit is contained in:
Pierre Curto
2023-09-12 13:49:52 +02:00
committed by GitHub
parent 37bb16cca1
commit d61482dffc
11 changed files with 141 additions and 52 deletions

View File

@@ -1,7 +1,7 @@
module bytebuffer_test @test;
module std::io::bytebuffer @test;
import std::io;
fn void! write_read_test()
fn void! write_read()
{
ByteBuffer buffer;
buffer.init(0)!;

View File

@@ -1,6 +1,5 @@
module scanner_test @test;
module std::io @test;
import std::collections::list;
import std::io;
def Results = List(<String>);
@@ -11,7 +10,7 @@ struct ScanTest
String left_over;
}
fn void! test_scanner()
fn void! scanner()
{
ScanTest[] tcases = {
{"aa,,bb", {"aa"}, "bb"},
@@ -48,4 +47,21 @@ fn void! test_scanner()
String left_over = (String)fl;
assert(left_over == tc.left_over, "%s -> %s", tc.in, left_over);
}
}
fn void! scanner_as_reader()
{
ByteReader br;
br.init("Lorem ipsum sit.");
Scanner sc;
char[8] buffer;
sc.init(&br, buffer[..]);
sc.scan(" ")!;
char[16] res;
usz n = sc.read(&res)!;
String str = (String)res[:n];
assert(str == "ipsum sit.", "got '%s'; want 'ipsum sit.'", str);
}