mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
* 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
29 lines
583 B
C
29 lines
583 B
C
module std::io::bytebuffer @test;
|
|
import std::io;
|
|
|
|
fn void! write_read()
|
|
{
|
|
ByteBuffer buffer;
|
|
buffer.init(0)!;
|
|
|
|
buffer.write("hello")!;
|
|
|
|
char[8] bytes;
|
|
usz n = buffer.read(bytes[..])!;
|
|
assert(n == 5);
|
|
assert((String)bytes[:n] == "hello");
|
|
|
|
buffer.write("hello world")!;
|
|
n = buffer.read(bytes[..])!;
|
|
assert(n == bytes.len);
|
|
assert((String)bytes[:n] == "hello wo");
|
|
assert(buffer.read_idx == 1);
|
|
|
|
char c = buffer.read_byte()!;
|
|
assert(c == 'r');
|
|
buffer.pushback_byte()!;
|
|
|
|
n = buffer.read(bytes[..])!;
|
|
assert((String)bytes[:n] == "rld");
|
|
assert(buffer.read_idx == 1);
|
|
} |