(file_path: &str, patch: &CodePatch, existing_code: &str)
| 52 | } |
| 53 | |
| 54 | pub fn validate_patch(file_path: &str, patch: &CodePatch, existing_code: &str) -> Result<()> { |
| 55 | let updated = match &patch.representation { |
| 56 | PatchRepresentation::UnifiedDiff(diff) => apply_unified_diff(existing_code, diff)?, |
| 57 | PatchRepresentation::ASTTransform(ast_edit) => { |
| 58 | bail!( |
| 59 | "cannot validate abstract AST transform for '{}' without a concrete rewrite", |
| 60 | ast_edit.target_symbol |
| 61 | ); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | if updated == existing_code { |
| 66 | bail!("patch does not modify file content"); |
| 67 | } |
| 68 | |
| 69 | let mut parser = parser::CodeParser::new(); |
| 70 | let _ = parser.parse(file_path, &updated)?; |
| 71 | Ok(()) |
| 72 | } |
| 73 | |
| 74 | pub fn apply_patch(existing_code: &str, patch: &CodePatch) -> Result<String> { |
| 75 | match &patch.representation { |
nothing calls this directly
no test coverage detected