mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
lib/std/io/stream: add LimitReader (#858)
* 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>
This commit is contained in:
20
test/unit/stdlib/io/limitreader.c3
Normal file
20
test/unit/stdlib/io/limitreader.c3
Normal file
@@ -0,0 +1,20 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user