| 138 | |
| 139 | #[tokio::test] |
| 140 | async fn test_grep_find_pattern() { |
| 141 | let temp = tempfile::tempdir().unwrap(); |
| 142 | std::fs::write( |
| 143 | temp.path().join("a.txt"), |
| 144 | "hello world\nfoo bar\nhello again", |
| 145 | ) |
| 146 | .unwrap(); |
| 147 | std::fs::write(temp.path().join("b.txt"), "no match here").unwrap(); |
| 148 | |
| 149 | let tool = GrepTool; |
| 150 | let ctx = ToolContext::new(temp.path().to_path_buf()); |
| 151 | |
| 152 | let result = tool |
| 153 | .execute(&serde_json::json!({"pattern": "hello"}), &ctx) |
| 154 | .await |
| 155 | .unwrap(); |
| 156 | |
| 157 | assert!(result.success); |
| 158 | assert!(result.content.contains("hello world")); |
| 159 | assert!(result.content.contains("hello again")); |
| 160 | assert!(result.content.contains("2 match(es)")); |
| 161 | } |
| 162 | |
| 163 | #[tokio::test] |
| 164 | async fn test_grep_no_match() { |