also looking at this
Add Windows support and CI coverage
#24
6 files
+170
-266
| @@ -119,11 +119,7 @@ fn scanDirectory( | ||
| 119 | 119 | else |
| 120 | 120 | full_path; |
| 121 | 121 | |
| 122 | // Skip leading slash in relative path | |
| 123 | const clean_relative = if (relative_path.len > 0 and relative_path[0] == '/') | |
| 124 | relative_path[1..] | |
| 125 | else | |
| 126 | relative_path; | |
| 122 | const clean_relative = cleanRelativePath(relative_path); | |
| 127 | 123 | |
| 128 | 124 | try result.addFile(full_path, clean_relative, entry.name); |
| 129 | 125 | } |
| @@ -135,6 +131,15 @@ fn scanDirectory( | ||
| 135 | 131 | } |
| 136 | 132 | } |
| 137 | 133 | |
| 134 | /// Removes separators introduced by slicing the root prefix. Accept both | |
| 135 | /// spellings so paths remain stable when a project moves between POSIX and | |
| 136 | /// Windows hosts. | |
| 137 | fn cleanRelativePath(path: []const u8) []const u8 { | |
| 138 | var start: usize = 0; | |
| 139 | while (start < path.len and (path[start] == '/' or path[start] == '\\')) : (start += 1) {} | |
| 140 | return path[start..]; | |
| 141 | } | |
| 142 | ||
| 138 | 143 | /// Check if a filename matches the pattern |
| 139 | 144 | fn matchesPattern(filename: []const u8, pattern: []const u8) bool { |
| 140 | 145 | // Simple pattern matching - check if filename ends with pattern |
| @@ -160,3 +165,8 @@ test "matchesPattern with exact match" { | ||
| 160 | 165 | try std.testing.expect(matchesPattern("test.zig", "test.zig")); |
| 161 | 166 | try std.testing.expect(!matchesPattern("other.zig", "test.zig")); |
| 162 | 167 | } |
| 168 | ||
| 169 | test "relative paths discard POSIX and Windows separators" { | |
| 170 | try std.testing.expectEqualStrings("suite/sample.test.zig", cleanRelativePath("/suite/sample.test.zig")); | |
| 171 | try std.testing.expectEqualStrings("suite\\sample.test.zig", cleanRelativePath("\\suite\\sample.test.zig")); | |
| 172 | } | |