|
12 | 12 | apply_hunks, |
13 | 13 | materialize_group_files, |
14 | 14 | merge_chain_assignments, |
| 15 | + split_git_lines, |
15 | 16 | ) |
16 | 17 | from pr_split.exceptions import GitOperationError |
17 | 18 | from pr_split.schemas import Group, GroupAssignment |
@@ -450,3 +451,31 @@ def test_new_file_without_trailing_newline(self) -> None: |
450 | 451 | estimated_loc=2, |
451 | 452 | ) |
452 | 453 | assert materialize_group_files(parsed, group, "base")["n.txt"] == "x\ny" |
| 454 | + |
| 455 | + |
| 456 | +class TestSplitGitLines: |
| 457 | + @pytest.mark.parametrize( |
| 458 | + ("content", "expected"), |
| 459 | + [ |
| 460 | + pytest.param("", [], id="empty"), |
| 461 | + pytest.param("a\n", ["a\n"], id="one-line"), |
| 462 | + pytest.param("a\nb", ["a\n", "b"], id="no-trailing-newline"), |
| 463 | + pytest.param("a\x0cb\nc\n", ["a\x0cb\n", "c\n"], id="form-feed"), |
| 464 | + pytest.param("a\x0bb\nc\n", ["a\x0bb\n", "c\n"], id="vertical-tab"), |
| 465 | + pytest.param("a\u2028b\nc\n", ["a\u2028b\n", "c\n"], id="line-separator"), |
| 466 | + pytest.param("a\x85b\n", ["a\x85b\n"], id="nel"), |
| 467 | + pytest.param("a\r\nb\r\n", ["a\r\n", "b\r\n"], id="crlf"), |
| 468 | + pytest.param("\n\n", ["\n", "\n"], id="blank-lines"), |
| 469 | + ], |
| 470 | + ) |
| 471 | + def test_splits_on_newline_only(self, content: str, expected: list[str]) -> None: |
| 472 | + assert split_git_lines(content) == expected |
| 473 | + |
| 474 | + |
| 475 | +class TestApplyHunksWithSplitlinesSeparators: |
| 476 | + def test_form_feed_in_earlier_line_does_not_shift_hunk(self) -> None: |
| 477 | + base = "a\x0cb\n" + "".join(f"{c}\n" for c in "cdefghijkl") |
| 478 | + dev = base.replace("k\n", "K\n") |
| 479 | + diff = "--- a/f.txt\n+++ b/f.txt\n@@ -7,5 +7,5 @@\n h\n i\n j\n-k\n+K\n l\n" |
| 480 | + pf = PatchSet(diff)[0] |
| 481 | + assert apply_hunks(base, pf, [0]) == dev |
0 commit comments