]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Simplify line splitting in the CLI tests
authorPeter Pentchev <roam@ringlet.net>
Sat, 18 Mar 2023 20:43:56 +0000 (22:43 +0200)
committerNick Terrell <nickrterrell@gmail.com>
Mon, 20 Mar 2023 18:17:43 +0000 (11:17 -0700)
tests/cli-tests/run.py

index 108f7101949320a268420b4f5154615d6a85cf83..9306f8a094d8b32fcf5e967b867db655d2e78ee4 100755 (executable)
@@ -114,20 +114,12 @@ def pop_line(data: bytes) -> typing.Tuple[typing.Optional[bytes], bytes]:
     if data == b'':
         return (None, data)
 
-    newline_idx = data.find(b"\n")
-    if newline_idx == -1:
-        end_idx = len(data)
-    else:
-        end_idx = newline_idx + 1
-
-    line = data[:end_idx]
-    data = data[end_idx:]
-
-    assert len(line) != 0
-    if not line.endswith(NEWLINE):
-        line += NEWLINE
+    parts = data.split(NEWLINE, maxsplit=1)
+    line = parts[0] + NEWLINE
+    if len(parts) == 1:
+        return line, b''
 
-    return (line, data)
+    return line, parts[1]
 
 
 def glob_line_matches(actual: bytes, expect: bytes) -> bool: