@@ -3,6 +3,7 @@ from gojo.bytes import buffer
3
3
from gojo.builtins import Bytes, Result, WrappedError
4
4
from gojo.bufio import Reader, Scanner, scan_words, scan_bytes, Writer
5
5
from gojo.io import read_all
6
+ from gojo.strings import StringBuilder
6
7
from goodies import FileWrapper
7
8
8
9
@@ -157,6 +158,28 @@ fn test_several_writes() raises:
157
158
test.assert_equal(text[4999 ], " 9" )
158
159
159
160
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
+
160
183
fn test_write_byte () raises :
161
184
var test = MojoTest(" Testing bufio.Writer.write_byte" )
162
185
@@ -215,6 +238,7 @@ fn main() raises:
215
238
test_discard()
216
239
test_write()
217
240
test_several_writes()
241
+ test_big_write()
218
242
test_write_byte()
219
243
test_write_string()
220
244
test_read_from()
0 commit comments