diff --git a/tests/core/io/test_core_io.odin b/tests/core/io/test_core_io.odin index 56fc9a0cb..ad7caf22c 100644 --- a/tests/core/io/test_core_io.odin +++ b/tests/core/io/test_core_io.odin @@ -1,5 +1,6 @@ package test_core_io +import "core:bufio" import "core:bytes" import "core:io" import "core:log" @@ -612,3 +613,122 @@ test_os2_file_stream :: proc(t: ^testing.T) { log.debugf("%#v", results) } + +@test +test_bufio_buffered_writer :: proc(t: ^testing.T) { + // Using a strings.Builder as the backing stream. + + sb := strings.builder_make() + defer strings.builder_destroy(&sb) + + buf: [32]u8 + expected_buf: [64]u8 + for i in 0..\n!=\nbuffer <%q>", sb.buf[:], expected_buf[:]) + + log.debugf("%#v", results) +} + +@test +test_bufio_buffered_reader :: proc(t: ^testing.T) { + // Using a bytes.Reader as the backing stream. + + buf: [32]u8 + for i in 0.. != len_buf<%v>, %v", bytes_written, len(buf), write_err) { + return + } + + flush_err := io.flush(stream) + if !testing.expectf(t, flush_err == nil, + "failed to Flush initial buffer: %v", write_err) { + return + } + + // bufio.Read_Writer isn't capable of seeking, so we have to reset the os2 + // stream back to the start here. + pos, seek_err := io.seek(stream, 0, .Start) + if !testing.expectf(t, pos == 0 && seek_err == nil, + "Pre-test Seek reset failed: pos<%v>, %v", pos, seek_err) { + return + } + + reader: bufio.Reader + writer: bufio.Writer + read_writer: bufio.Read_Writer + + bufio.reader_init(&reader, stream) + defer bufio.reader_destroy(&reader) + bufio.writer_init(&writer, stream) + defer bufio.writer_destroy(&writer) + + bufio.read_writer_init(&read_writer, &reader, &writer) + + // os2 file stream proc close and destroy are the same. + results, _ := _test_stream(t, bufio.read_writer_to_stream(&read_writer), buf[:], do_destroy = false) + + log.debugf("%#v", results) +}