@@ -847,22 +847,30 @@ fn long_line_flushed() {
847
847
}
848
848
849
849
/// Test that, given a very long partial line *after* successfully
850
- /// flushing a complete line, the very long partial line is buffered
851
- /// unconditionally, and no additional writes take place. This assures
850
+ /// flushing a complete line, no additional writes take place. This assures
852
851
/// the property that `write` should make at-most-one attempt to write
853
852
/// new data.
854
853
#[ test]
855
854
fn line_long_tail_not_flushed ( ) {
856
855
let writer = ProgrammableSink :: default ( ) ;
857
856
let mut writer = LineWriter :: with_capacity ( 5 , writer) ;
858
857
859
- // Assert that Line 1\n is flushed, and 01234 is buffered
860
- assert_eq ! ( writer. write( b"Line 1\n 0123456789" ) . unwrap( ) , 12 ) ;
858
+ // Assert that Line 1\n is flushed and the long tail isn't.
859
+ let bytes = b"Line 1\n 0123456789" ;
860
+ writer. write ( bytes) . unwrap ( ) ;
861
861
assert_eq ! ( & writer. get_ref( ) . buffer, b"Line 1\n " ) ;
862
+ }
863
+
864
+ // Test that appending to a full buffer emits a single write, flushing the buffer.
865
+ #[ test]
866
+ fn line_full_buffer_flushed ( ) {
867
+ let writer = ProgrammableSink :: default ( ) ;
868
+ let mut writer = LineWriter :: with_capacity ( 5 , writer) ;
869
+ assert_eq ! ( writer. write( b"01234" ) . unwrap( ) , 5 ) ;
862
870
863
871
// Because the buffer is full, this subsequent write will flush it
864
872
assert_eq ! ( writer. write( b"5" ) . unwrap( ) , 1 ) ;
865
- assert_eq ! ( & writer. get_ref( ) . buffer, b"Line 1 \n 01234 " ) ;
873
+ assert_eq ! ( & writer. get_ref( ) . buffer, b"01234 " ) ;
866
874
}
867
875
868
876
/// Test that, if an attempt to pre-flush buffered data returns Ok(0),
0 commit comments