Browse Source

tests: add unit test for StreamReader.readlines()

rdb 5 years ago
parent
commit
56c33fb8b6
1 changed files with 36 additions and 0 deletions
  1. 36 0
      tests/prc/test_stream_reader.py

+ 36 - 0
tests/prc/test_stream_reader.py

@@ -157,6 +157,42 @@ def test_streamreader_readline():
     assert reader.readline() == b'\x00\x00'
 
 
+def test_streamreader_readlines():
+    # Empty stream
+    stream = StringStream(b'')
+    reader = StreamReader(stream, False)
+    assert reader.readlines() == []
+
+    # Single line without newline
+    stream = StringStream(b'A')
+    reader = StreamReader(stream, False)
+    assert reader.readlines() == [b'A']
+    assert reader.readlines() == []
+
+    # Single newline
+    stream = StringStream(b'\n')
+    reader = StreamReader(stream, False)
+    assert reader.readlines() == [b'\n']
+    assert reader.readlines() == []
+
+    # Line with text followed by empty line
+    stream = StringStream(b'A\n\n')
+    reader = StreamReader(stream, False)
+    assert reader.readlines() == [b'A\n', b'\n']
+    assert reader.readlines() == []
+
+    # Multiple lines
+    stream = StringStream(b'A\nB\nC')
+    reader = StreamReader(stream, False)
+    assert reader.readlines() == [b'A\n', b'B\n', b'C']
+    assert reader.readlines() == []
+
+    # Preserve null byte
+    stream = StringStream(b'\x00\x00')
+    reader = StreamReader(stream, False)
+    assert reader.readlines() == [b'\x00\x00']
+
+
 def test_streamreader_extract_bytes():
     # Empty bytes
     stream = StringStream(b'')