Skip to content

Commit b7e6f77

Browse files
committed
Fix isValidName
1 parent bfc771b commit b7e6f77

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/MultiIndex.zig

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dir: std.fs.Dir,
1818
indexes: std.StringHashMap(IndexRef),
1919

2020
fn isValidName(name: []const u8) bool {
21-
for (name, 0) |c, i| {
21+
for (name, 0..) |c, i| {
2222
if (i == 0) {
2323
switch (c) {
2424
'0'...'9', 'A'...'Z', 'a'...'z' => {},
@@ -34,8 +34,16 @@ fn isValidName(name: []const u8) bool {
3434
return true;
3535
}
3636

37-
const max_sub_dir_name_size = 10;
38-
const sub_dir_name_fmt = "{x:0>2}";
37+
test "isValidName" {
38+
try std.testing.expect(isValidName("a"));
39+
try std.testing.expect(isValidName("a1"));
40+
try std.testing.expect(isValidName("a1-b"));
41+
try std.testing.expect(isValidName("a1_b"));
42+
try std.testing.expect(!isValidName("_1b2"));
43+
try std.testing.expect(!isValidName("-1b2"));
44+
try std.testing.expect(!isValidName("a/a"));
45+
try std.testing.expect(!isValidName(".foo"));
46+
}
3947

4048
pub fn init(allocator: std.mem.Allocator, dir: std.fs.Dir) Self {
4149
return .{

0 commit comments

Comments
 (0)