Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit a7c1441

Browse files
committed
add big write test for bufio
1 parent 5ed54ac commit a7c1441

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_bufio.mojo

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from gojo.bytes import buffer
33
from gojo.builtins import Bytes, Result, WrappedError
44
from gojo.bufio import Reader, Scanner, scan_words, scan_bytes, Writer
55
from gojo.io import read_all
6+
from gojo.strings import StringBuilder
67
from goodies import FileWrapper
78

89

@@ -157,6 +158,28 @@ fn test_several_writes() raises:
157158
test.assert_equal(text[4999], "9")
158159

159160

161+
fn test_big_write() raises:
162+
var test = MojoTest("Testing a big bufio.Writer.write")
163+
164+
# Create a new Bytes Buffer Writer and use it to create the buffered Writer
165+
var buf = buffer.new_buffer()
166+
var writer = Writer(buf)
167+
168+
# Build a string larger than the size of the Bufio struct's internal buffer.
169+
var builder = StringBuilder(5000)
170+
var result = Result(0)
171+
for i in range(500):
172+
result = builder.write_string("0123456789")
173+
174+
# When writing, it should bypass the Bufio struct's buffer and write directly to the underlying bytes buffer writer. So, no need to flush.
175+
var text = str(builder)
176+
_ = writer.write(text)
177+
test.assert_equal(result.value, 10)
178+
test.assert_equal(len(writer.writer), 5000)
179+
test.assert_equal(text[0], "0")
180+
test.assert_equal(text[4999], "9")
181+
182+
160183
fn test_write_byte() raises:
161184
var test = MojoTest("Testing bufio.Writer.write_byte")
162185

@@ -215,6 +238,7 @@ fn main() raises:
215238
test_discard()
216239
test_write()
217240
test_several_writes()
241+
test_big_write()
218242
test_write_byte()
219243
test_write_string()
220244
test_read_from()

0 commit comments

Comments
 (0)