@@ -401,10 +401,12 @@ pub(crate) fn mk_path_abs<P: AsRef<Path>>(path: P) -> Result<PathBuf, std::io::E
401401#[ cfg( test) ]
402402mod test {
403403 #![ allow( clippy:: unwrap_used) ]
404- use std:: path:: PathBuf ;
404+ use std:: { fs, path:: PathBuf } ;
405+
406+ use tempfile:: { NamedTempFile , TempDir } ;
405407
406408 use super :: FileObj ;
407- use crate :: cli:: LinesChangedOnly ;
409+ use crate :: { clang_tools :: ReviewComments , cli:: LinesChangedOnly } ;
408410
409411 // *********************** tests for FileObj::get_ranges()
410412
@@ -463,4 +465,35 @@ mod test {
463465 println ! ( "Canonical path: {}" , canonical_path. display( ) ) ;
464466 assert ! ( !canonical_path. to_string_lossy( ) . starts_with( r"\\?\" ) ) ;
465467 }
468+
469+ #[ test]
470+ fn pure_removal_suggestion ( ) {
471+ let repo_root = TempDir :: new ( ) . unwrap ( ) ;
472+ let file_name = PathBuf :: from ( "test_file.cpp" ) ;
473+
474+ // Write original file with 3 lines
475+ let original_content = "line1\n line2\n line3\n " ;
476+ fs:: write ( repo_root. path ( ) . join ( & file_name) , original_content) . unwrap ( ) ;
477+
478+ // Patched file has line2 removed
479+ let patched_content = "line1\n line3\n " ;
480+ let patched_file = NamedTempFile :: new ( ) . unwrap ( ) ;
481+ fs:: write ( patched_file. path ( ) , patched_content) . unwrap ( ) ;
482+
483+ // line2 is 1-indexed line 2; diff_chunks must contain it
484+ let mut file_obj = FileObj :: from ( file_name, vec ! [ 2 ] , vec ! [ 2 ..=2 ] ) ;
485+ file_obj. patched_path = Some ( patched_file. path ( ) . to_path_buf ( ) ) ;
486+
487+ let mut review_comments = ReviewComments :: default ( ) ;
488+ file_obj
489+ . make_suggestions_from_patch ( & mut review_comments, false , repo_root. path ( ) )
490+ . unwrap ( ) ;
491+
492+ assert_eq ! ( review_comments. comments. len( ) , 1 ) ;
493+ let suggestion = & review_comments. comments [ 0 ] . suggestion ;
494+ assert ! (
495+ suggestion. contains( "Please remove the line(s)\n - 2" ) ,
496+ "unexpected suggestion: {suggestion}"
497+ ) ;
498+ }
466499}
0 commit comments