60 lines
1.7 KiB
Dart
60 lines
1.7 KiB
Dart
import "dart:io";
|
|
import "package:test/test.dart";
|
|
import "package:clawd_code/src/tools/file_read_tool.dart";
|
|
|
|
|
|
void main() {
|
|
late FileReadTool tool;
|
|
late Directory tempDir;
|
|
|
|
setUp(() async {
|
|
tool = FileReadTool();
|
|
tempDir = await Directory.systemTemp.createTemp("file_read_test_");
|
|
});
|
|
|
|
tearDown(() async {
|
|
await tempDir.delete(recursive: true);
|
|
});
|
|
|
|
group("FileReadTool", () {
|
|
test("reads a known file with line numbers", () async {
|
|
final f = File("${tempDir.path}/sample.txt");
|
|
await f.writeAsString("hello\nworld\n");
|
|
|
|
final result = await tool.execute({"file_path": f.path});
|
|
expect(result, contains("hello"));
|
|
expect(result, contains("world"));
|
|
// line numbers present
|
|
expect(result, contains("1"));
|
|
});
|
|
|
|
test("returns error for missing file", () async {
|
|
final result = await tool.execute({"file_path": "/does/not/exist.txt"});
|
|
expect(result.toLowerCase(), contains("error"));
|
|
});
|
|
|
|
test("respects offset and limit", () async {
|
|
final f = File("${tempDir.path}/multiline.txt");
|
|
await f.writeAsString("line1\nline2\nline3\nline4\nline5\n");
|
|
|
|
final result = await tool.execute({
|
|
"file_path": f.path,
|
|
"offset": 1,
|
|
"limit": 2,
|
|
});
|
|
|
|
expect(result, contains("line2"));
|
|
expect(result, contains("line3"));
|
|
expect(result, isNot(contains("line1")));
|
|
expect(result, isNot(contains("line4")));
|
|
});
|
|
|
|
test("empty file returns empty marker", () async {
|
|
final f = File("${tempDir.path}/empty.txt");
|
|
await f.writeAsString("");
|
|
|
|
final result = await tool.execute({"file_path": f.path});
|
|
expect(result, contains("1\t"));
|
|
});
|
|
});
|
|
}
|