mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
* lib/std/io/stream: add LimitReader Signed-off-by: Pierre Curto <pierre.curto@gmail.com> * lib/std: more method conversions to use new receiver notation Signed-off-by: Pierre Curto <pierre.curto@gmail.com> --------- Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
20 lines
441 B
C
20 lines
441 B
C
module std::io @test;
|
|
|
|
|
|
fn void! limitreader()
|
|
{
|
|
const DATA = "Hello World!";
|
|
ByteReader src;
|
|
src.init(DATA);
|
|
const LIMIT = 5;
|
|
LimitReader lmr;
|
|
lmr.init(src.as_stream(), LIMIT);
|
|
|
|
char[DATA.len] bytes;
|
|
usz n = lmr.read(bytes[..])!;
|
|
|
|
assert(n == LIMIT, "got %d; want %d", n, LIMIT);
|
|
String got = (String)bytes[:n];
|
|
String want = DATA[:LIMIT];
|
|
assert(got == want, "got %d; want %d", got, want);
|
|
} |