mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
add std::io::stream::ByteBuffer; fix std::io::Path::walk (#895)
* lib/std/io/stream: add some inlines Signed-off-by: Pierre Curto <pierre.curto@gmail.com> * lib/std/io/stream add ByteBuffer Signed-off-by: Pierre Curto <pierre.curto@gmail.com> * lib/std/io/path: fix free of paths in walk Signed-off-by: Pierre Curto <pierre.curto@gmail.com> * lib/std/bits: remove unnecessary receiver type Signed-off-by: Pierre Curto <pierre.curto@gmail.com> --------- Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
29
test/unit/stdlib/io/bytebuffer.c3
Normal file
29
test/unit/stdlib/io/bytebuffer.c3
Normal file
@@ -0,0 +1,29 @@
|
||||
module bytebuffer_test @test;
|
||||
import std::io;
|
||||
|
||||
fn void! write_read_test()
|
||||
{
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user