From 03819fa341df2560f69b659f704f7a5b433ffc8e Mon Sep 17 00:00:00 2001 From: laststylebender Date: Mon, 13 Jan 2025 18:06:46 +0530 Subject: [PATCH 1/6] - add test cases to verify few cases in fs-replace --- crates/forge_tool/src/fs/fs_replace.rs | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/crates/forge_tool/src/fs/fs_replace.rs b/crates/forge_tool/src/fs/fs_replace.rs index 92dcec2f3..36b155326 100644 --- a/crates/forge_tool/src/fs/fs_replace.rs +++ b/crates/forge_tool/src/fs/fs_replace.rs @@ -563,4 +563,41 @@ mod test { assert_eq!(result.content, "fn main() { let x = 42; let y = x * 2; }\n"); } + + #[tokio::test] + async fn test_replace_curly_brace_with_double_curly_brace() { + let temp_dir = TempDir::new().unwrap(); + let file_path = temp_dir.path().join("test.md"); + // Create test file with content + let file_content = "fn test(){\n let x = 42;\n {\n // test block-1 }\n }\n"; + write_test_file(&file_path, file_content).await.unwrap(); + + // want to replace '}' with '}}'. + let diff = format!("{}\n}}{}\n}}}}\n{}", SEARCH, DIVIDER, REPLACE); + let res = FSReplace + .call(FSReplaceInput { path: file_path.to_string_lossy().to_string(), diff }) + .await + .unwrap(); + let expected = "fn test(){\n let x = 42;\n {\n // test block-1 }}\n\n }\n"; + assert_eq!(res.content, expected); + } + + #[tokio::test] + async fn test_empty_search_block() { + let temp_dir = TempDir::new().unwrap(); + let file_path = temp_dir.path().join("test.md"); + // Create test file with content + let file_content = r#"fn test(){\n let x = 42;\n {\n // test block-1 }}\n"#; + write_test_file(&file_path, file_content).await.unwrap(); + + // want to replace '' with 'empty-space-replaced'. + let diff = format!("{}\n{}\nempty-space-replaced{}", SEARCH, DIVIDER, REPLACE); + + let res = FSReplace + .call(FSReplaceInput { path: file_path.to_string_lossy().to_string(), diff }) + .await + .unwrap(); + let expected = r#"empty-space-replacedfn test(){\n let x = 42;\n {\n // test block-1 }}\n"#; + assert_eq!(res.content, expected); + } } From 34031cdd93a595dbfbc2194745f05dfb951a3a62 Mon Sep 17 00:00:00 2001 From: laststylebender Date: Tue, 14 Jan 2025 11:25:31 +0530 Subject: [PATCH 2/6] - when search block is empty instead of adding replace block at the beginning of file, add the end of file. --- crates/forge_tool/src/fs/fs_replace.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/forge_tool/src/fs/fs_replace.rs b/crates/forge_tool/src/fs/fs_replace.rs index 36b155326..b609a1c39 100644 --- a/crates/forge_tool/src/fs/fs_replace.rs +++ b/crates/forge_tool/src/fs/fs_replace.rs @@ -155,6 +155,12 @@ async fn apply_changes>(path: P, blocks: Vec) -> Result Date: Tue, 14 Jan 2025 05:56:50 +0000 Subject: [PATCH 3/6] [autofix.ci] apply automated fixes --- crates/forge_tool/src/fs/fs_replace.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/forge_tool/src/fs/fs_replace.rs b/crates/forge_tool/src/fs/fs_replace.rs index b609a1c39..0356adfb6 100644 --- a/crates/forge_tool/src/fs/fs_replace.rs +++ b/crates/forge_tool/src/fs/fs_replace.rs @@ -593,7 +593,8 @@ mod test { let temp_dir = TempDir::new().unwrap(); let file_path = temp_dir.path().join("test.md"); // Create test file with content - let file_content = r#"fn test(){\n let x = 42;\n {\n // test block-1 }\n}\n"#; + let file_content = + r#"fn test(){\n let x = 42;\n {\n // test block-1 }\n}\n"#; write_test_file(&file_path, file_content).await.unwrap(); // want to replace '' with 'empty-space-replaced'. From 6d5163924caa00494b8f5a4ea9e4c941c25a9dfd Mon Sep 17 00:00:00 2001 From: laststylebender Date: Tue, 14 Jan 2025 11:33:08 +0530 Subject: [PATCH 4/6] - add another case for white spaced search block. --- crates/forge_tool/src/fs/fs_replace.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/forge_tool/src/fs/fs_replace.rs b/crates/forge_tool/src/fs/fs_replace.rs index 0356adfb6..e394f368f 100644 --- a/crates/forge_tool/src/fs/fs_replace.rs +++ b/crates/forge_tool/src/fs/fs_replace.rs @@ -608,4 +608,24 @@ mod test { let expected = r#"fn test(){\n let x = 42;\n {\n // test block-1 }\n}\nempty-space-replaced"#; assert_eq!(res.content, expected); } + + #[tokio::test] + async fn test_match_empty_white_space() { + let temp_dir = TempDir::new().unwrap(); + let file_path = temp_dir.path().join("test.md"); + // Create test file with content + let file_content = r#"fn test(){\n let x = 42;\n {\n // test block-1 }\n}\n"#; + write_test_file(&file_path, file_content).await.unwrap(); + + // want to replace '' with '--'. + let diff = format!("{}\n {}\n--{}", SEARCH, DIVIDER, REPLACE); + + let res = FSReplace + .call(FSReplaceInput { path: file_path.to_string_lossy().to_string(), diff }) + .await + .unwrap(); + + let expected = r#"fn--test(){\n let x = 42;\n {\n // test block-1 }\n}\n"#; + assert_eq!(res.content, expected); + } } From 18e15b41c2666e942df90c1fe5929b92894eebd1 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 06:04:12 +0000 Subject: [PATCH 5/6] [autofix.ci] apply automated fixes --- crates/forge_tool/src/fs/fs_replace.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/forge_tool/src/fs/fs_replace.rs b/crates/forge_tool/src/fs/fs_replace.rs index e394f368f..3ab9a22db 100644 --- a/crates/forge_tool/src/fs/fs_replace.rs +++ b/crates/forge_tool/src/fs/fs_replace.rs @@ -614,7 +614,8 @@ mod test { let temp_dir = TempDir::new().unwrap(); let file_path = temp_dir.path().join("test.md"); // Create test file with content - let file_content = r#"fn test(){\n let x = 42;\n {\n // test block-1 }\n}\n"#; + let file_content = + r#"fn test(){\n let x = 42;\n {\n // test block-1 }\n}\n"#; write_test_file(&file_path, file_content).await.unwrap(); // want to replace '' with '--'. From 9666d733bfd5d5cffd4455b97164b7bb39b35104 Mon Sep 17 00:00:00 2001 From: laststylebender Date: Tue, 14 Jan 2025 11:34:11 +0530 Subject: [PATCH 6/6] - update the comment --- crates/forge_tool/src/fs/fs_replace.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge_tool/src/fs/fs_replace.rs b/crates/forge_tool/src/fs/fs_replace.rs index 3ab9a22db..8c6c36ef0 100644 --- a/crates/forge_tool/src/fs/fs_replace.rs +++ b/crates/forge_tool/src/fs/fs_replace.rs @@ -618,7 +618,7 @@ mod test { r#"fn test(){\n let x = 42;\n {\n // test block-1 }\n}\n"#; write_test_file(&file_path, file_content).await.unwrap(); - // want to replace '' with '--'. + // want to replace ' ' with '--'. let diff = format!("{}\n {}\n--{}", SEARCH, DIVIDER, REPLACE); let res = FSReplace