diff options
| author | Ryan Liptak <squeek502@hotmail.com> | 2025-12-18 16:25:57 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-12-23 22:15:10 -0800 |
| commit | 1edae601a1d35caa78eddc4b18f7d613c4af70f9 (patch) | |
| tree | e4df3a2cb9e052e173c907c614377b40b2e3cee1 /lib/std | |
| parent | 3466056478d2ad988b117a89d7cbe3cc1557425a (diff) | |
| download | zig-1edae601a1d35caa78eddc4b18f7d613c4af70f9.tar.gz zig-1edae601a1d35caa78eddc4b18f7d613c4af70f9.zip | |
Test Dir.Reader.min_buffer_len via "max file name component lengths" test
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/fs/test.zig | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index 4e0fba82ed..40ba20c9a8 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -1368,13 +1368,29 @@ test "makepath ignores '.'" { } fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !void { - // setup, create a dir and a nested file both with maxed filenames, and walk the dir + // create a file, a dir, and a nested file all with maxed filenames { + try iterable_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" }); + var maxed_dir = try iterable_dir.makeOpenPath(io, maxed_filename, .{}); defer maxed_dir.close(io); try maxed_dir.writeFile(io, .{ .sub_path = maxed_filename, .data = "" }); + } + // Low level API with minimum buffer length + { + var reader_buf: [Dir.Reader.min_buffer_len]u8 align(@alignOf(usize)) = undefined; + var reader: Dir.Reader = .init(iterable_dir, &reader_buf); + var count: usize = 0; + while (try reader.next(io)) |entry| { + try expectEqualStrings(maxed_filename, entry.name); + count += 1; + } + try expectEqual(@as(usize, 2), count); + } + // High level walk API + { var walker = try iterable_dir.walk(testing.allocator); defer walker.deinit(); @@ -1383,7 +1399,7 @@ fn testFilenameLimits(io: Io, iterable_dir: Dir, maxed_filename: []const u8) !vo try expectEqualStrings(maxed_filename, entry.basename); count += 1; } - try expectEqual(@as(usize, 2), count); + try expectEqual(@as(usize, 3), count); } // ensure that we can delete the tree |
