tools/file: add with_lineno option to read_file

When true, prefix each returned line with absolute 1-based line numbers
(N|…) for edit_lineno-friendly reads; works with offset/limit.
This commit is contained in:
2026-07-18 17:52:25 +08:00
parent b1a8c23582
commit de79dec96f
2 changed files with 38 additions and 2 deletions
+12
View File
@@ -35,6 +35,18 @@ def test_read_offset_limit(workspace: object) -> None:
assert call_sync(read_file, "lines.txt", offset=1, limit=2) == "b\nc\n"
def test_read_with_lineno(workspace: object) -> None:
del workspace
_ = call_sync(write_file, "num.txt", "a\nb\nc\n")
out = call_sync(read_file, "num.txt", with_lineno=True)
assert " 1|a\n" in out
assert " 2|b\n" in out
assert " 3|c\n" in out
# offset is 0-based; line numbers stay absolute 1-based file lines
mid = call_sync(read_file, "num.txt", offset=1, limit=1, with_lineno=True)
assert mid == " 2|b\n"
def test_listdir_missing(workspace: object) -> None:
del workspace
assert "error" in call_sync(listdir, "nope")