diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/.gitattributes b/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/.gitattributes new file mode 100644 index 0000000000..fa1385d99a --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/.gitattributes @@ -0,0 +1 @@ +* -text diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/expected/sample.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/expected/sample.txt new file mode 100644 index 0000000000..87a02e2e58 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/expected/sample.txt @@ -0,0 +1,2 @@ +uno +two diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/input/sample.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/input/sample.txt new file mode 100644 index 0000000000..4e349b596c --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/input/sample.txt @@ -0,0 +1,2 @@ +one +two diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/patch.txt new file mode 100644 index 0000000000..f6ce3b0a4b --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/023_preserves_crlf_for_update_hunks/patch.txt @@ -0,0 +1,7 @@ +*** Begin Patch +*** Update File: sample.txt +@@ +-one ++uno + two +*** End Patch diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/024_preserves_crlf_for_add_file_hunks/.gitattributes b/codex-rs/apply-patch/tests/fixtures/scenarios/024_preserves_crlf_for_add_file_hunks/.gitattributes new file mode 100644 index 0000000000..fa1385d99a --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/024_preserves_crlf_for_add_file_hunks/.gitattributes @@ -0,0 +1 @@ +* -text diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/024_preserves_crlf_for_add_file_hunks/expected/created.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/024_preserves_crlf_for_add_file_hunks/expected/created.txt new file mode 100644 index 0000000000..23eb407b64 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/024_preserves_crlf_for_add_file_hunks/expected/created.txt @@ -0,0 +1,2 @@ +hello +world diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/024_preserves_crlf_for_add_file_hunks/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/024_preserves_crlf_for_add_file_hunks/patch.txt new file mode 100644 index 0000000000..f3c9f7f8c2 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/024_preserves_crlf_for_add_file_hunks/patch.txt @@ -0,0 +1,5 @@ +*** Begin Patch +*** Add File: created.txt ++hello ++world +*** End Patch diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/.gitattributes b/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/.gitattributes new file mode 100644 index 0000000000..fa1385d99a --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/.gitattributes @@ -0,0 +1 @@ +* -text diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/expected/lines.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/expected/lines.txt new file mode 100644 index 0000000000..bc7f1d41b2 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/expected/lines.txt @@ -0,0 +1,2 @@ +first +third diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/input/lines.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/input/lines.txt new file mode 100644 index 0000000000..2e11fe5aa8 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/input/lines.txt @@ -0,0 +1,3 @@ +first +second +third diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/patch.txt new file mode 100644 index 0000000000..b4b0b74a64 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/025_preserves_crlf_for_deletion_only_hunk/patch.txt @@ -0,0 +1,7 @@ +*** Begin Patch +*** Update File: lines.txt +@@ + first +-second + third +*** End Patch diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/.gitattributes b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/.gitattributes new file mode 100644 index 0000000000..fa1385d99a --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/.gitattributes @@ -0,0 +1 @@ +* -text diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/expected/old/other.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/expected/old/other.txt new file mode 100644 index 0000000000..4f5ee50185 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/expected/old/other.txt @@ -0,0 +1 @@ +keep diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/expected/renamed/dir/name.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/expected/renamed/dir/name.txt new file mode 100644 index 0000000000..86688d945e --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/expected/renamed/dir/name.txt @@ -0,0 +1,2 @@ +new +line diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/input/old/name.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/input/old/name.txt new file mode 100644 index 0000000000..8bd7378255 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/input/old/name.txt @@ -0,0 +1,2 @@ +old +line diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/input/old/other.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/input/old/other.txt new file mode 100644 index 0000000000..4f5ee50185 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/input/old/other.txt @@ -0,0 +1 @@ +keep diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/patch.txt new file mode 100644 index 0000000000..de1bb6c1b0 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/026_preserves_crlf_for_move_update_hunk/patch.txt @@ -0,0 +1,8 @@ +*** Begin Patch +*** Update File: old/name.txt +*** Move to: renamed/dir/name.txt +@@ +-old ++new + line +*** End Patch diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/.gitattributes b/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/.gitattributes new file mode 100644 index 0000000000..fa1385d99a --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/.gitattributes @@ -0,0 +1 @@ +* -text diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/expected/multi.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/expected/multi.txt new file mode 100644 index 0000000000..381acb9027 --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/expected/multi.txt @@ -0,0 +1,4 @@ +one +dos +three +cuatro diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/input/multi.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/input/multi.txt new file mode 100644 index 0000000000..7fbf4d847b --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/input/multi.txt @@ -0,0 +1,4 @@ +one +two +three +four diff --git a/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/patch.txt b/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/patch.txt new file mode 100644 index 0000000000..8d51e90d7e --- /dev/null +++ b/codex-rs/apply-patch/tests/fixtures/scenarios/027_preserves_crlf_for_multiple_chunks/patch.txt @@ -0,0 +1,9 @@ +*** Begin Patch +*** Update File: multi.txt +@@ +-two ++dos +@@ +-four ++cuatro +*** End Patch diff --git a/codex-rs/apply-patch/tests/suite/scenarios.rs b/codex-rs/apply-patch/tests/suite/scenarios.rs index 5f8285b931..3beb7d652d 100644 --- a/codex-rs/apply-patch/tests/suite/scenarios.rs +++ b/codex-rs/apply-patch/tests/suite/scenarios.rs @@ -124,38 +124,3 @@ fn copy_dir_recursive(src: &Path, dst: &Path) -> anyhow::Result<()> { } Ok(()) } - -#[test] -fn test_apply_patch_preserves_crlf_for_update_hunks() -> anyhow::Result<()> { - let tmp = tempdir()?; - let file_path = tmp.path().join("sample.txt"); - fs::write(&file_path, b"one\r\ntwo\r\n")?; - - let patch = "*** Begin Patch\r\n*** Update File: sample.txt\r\n@@\r\n-one\r\n+uno\r\n two\r\n*** End Patch\r\n"; - - Command::new(codex_utils_cargo_bin::cargo_bin("apply_patch")?) - .arg(patch) - .current_dir(tmp.path()) - .output()?; - - assert_eq!(fs::read(&file_path)?, b"uno\r\ntwo\r\n"); - Ok(()) -} - -#[test] -fn test_apply_patch_preserves_crlf_for_add_file_hunks() -> anyhow::Result<()> { - let tmp = tempdir()?; - let patch = - "*** Begin Patch\r\n*** Add File: created.txt\r\n+hello\r\n+world\r\n*** End Patch\r\n"; - - Command::new(codex_utils_cargo_bin::cargo_bin("apply_patch")?) - .arg(patch) - .current_dir(tmp.path()) - .output()?; - - assert_eq!( - fs::read(tmp.path().join("created.txt"))?, - b"hello\r\nworld\r\n" - ); - Ok(()) -}