51 lines
1.3 KiB
Dart
51 lines
1.3 KiB
Dart
import "dart:io";
|
|
|
|
import "package:clawd_code/src/tools/grep_tool.dart";
|
|
import "package:test/test.dart";
|
|
|
|
void main() {
|
|
late Directory tempDir;
|
|
late GrepTool tool;
|
|
|
|
setUp(() async {
|
|
tempDir = await Directory.systemTemp.createTemp("grep_tool_test_");
|
|
tool = GrepTool();
|
|
});
|
|
|
|
tearDown(() async {
|
|
if (await tempDir.exists()) {
|
|
await tempDir.delete(recursive: true);
|
|
}
|
|
});
|
|
|
|
group("GrepTool", () {
|
|
test("searches a direct file path", () async {
|
|
final file = File("${tempDir.path}/sample.txt");
|
|
await file.writeAsString("alpha\nbeta\nalpha again\n");
|
|
|
|
final result = await tool.execute({
|
|
"pattern": "alpha",
|
|
"path": file.path,
|
|
"output_mode": "content",
|
|
});
|
|
|
|
expect(result, contains("sample.txt:1:alpha"));
|
|
expect(result, contains("sample.txt:3:alpha again"));
|
|
});
|
|
|
|
test("searches a directory path", () async {
|
|
final nested = Directory("${tempDir.path}/nested");
|
|
await nested.create(recursive: true);
|
|
final file = File("${nested.path}/sample.txt");
|
|
await file.writeAsString("needle\n");
|
|
|
|
final result = await tool.execute({
|
|
"pattern": "needle",
|
|
"path": tempDir.path,
|
|
"output_mode": "files_with_matches",
|
|
});
|
|
|
|
expect(result, contains("nested/sample.txt"));
|
|
});
|
|
});
|
|
}
|