mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix WriteBuffer.write_bytes off-by-one (#1625)
* fix WriteBuffer.write_bytes off-by-one * test for WriteBuffer.write_bytes off-by-one
This commit is contained in:
@@ -66,4 +66,29 @@ fn void! writebuffer()
|
||||
assert(n == DATA.len, "got %d; want %d", n, DATA.len);
|
||||
String got = out.str_view();
|
||||
assert(got == DATA, "got %s; want %s", got, DATA);
|
||||
}
|
||||
}
|
||||
|
||||
fn void! writebuffer_write_byte()
|
||||
{
|
||||
ByteWriter out;
|
||||
out.temp_init();
|
||||
char[2] buf;
|
||||
WriteBuffer write_buf;
|
||||
write_buf.init(&out, buf[..]);
|
||||
|
||||
write_buf.write_byte('a')!;
|
||||
assert(write_buf.str_view() == "a");
|
||||
assert(out.str_view() == "");
|
||||
|
||||
write_buf.write_byte('b')!;
|
||||
assert(write_buf.str_view() == "ab");
|
||||
assert(out.str_view() == "");
|
||||
|
||||
write_buf.write_byte('c')!;
|
||||
assert(write_buf.str_view() == "c");
|
||||
assert(out.str_view() == "ab");
|
||||
|
||||
write_buf.flush()!;
|
||||
assert(write_buf.str_view() == "");
|
||||
assert(out.str_view() == "abc");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user