| ... | ... | @@ -1197,7 +1197,7 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons |
| 1197 | 1197 | /// - `"main.zig"` ⇒ `".zig"` |
| 1198 | 1198 | /// - `"src/main.zig"` ⇒ `".zig"` |
| 1199 | 1199 | /// - `".gitignore"` ⇒ `""` |
| 1200 | | /// - `"keep."` ⇒ `""` |
| 1200 | /// - `"keep."` ⇒ `"."` |
| 1201 | 1201 | /// - `"src.keep.me"` ⇒ `".me"` |
| 1202 | 1202 | /// - `"/src/keep.me"` ⇒ `".me"` |
| 1203 | 1203 | /// - `"/src/keep.me/"` ⇒ `".me"` |
| ... | ... | @@ -1205,13 +1205,9 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons |
| 1205 | 1205 | /// pointer address range of `path`, even if it is length zero. |
| 1206 | 1206 | pub fn extension(path: []const u8) []const u8 { |
| 1207 | 1207 | const filename = basename(path); |
| 1208 | | return if (std.mem.lastIndexOf(u8, filename, ".")) |index| |
| 1209 | | if (index == 0 or index == filename.len - 1) |
| 1210 | | path[path.len..] |
| 1211 | | else |
| 1212 | | filename[index..] |
| 1213 | | else |
| 1214 | | path[path.len..]; |
| 1208 | const index = mem.lastIndexOf(u8, filename, ".") orelse return path[path.len..]; |
| 1209 | if (index == 0) return path[path.len..]; |
| 1210 | return filename[index..]; |
| 1215 | 1211 | } |
| 1216 | 1212 | |
| 1217 | 1213 | fn testExtension(path: []const u8, expected: []const u8) void { |
| ... | ... | @@ -1221,39 +1217,39 @@ fn testExtension(path: []const u8, expected: []const u8) void { |
| 1221 | 1217 | test "extension" { |
| 1222 | 1218 | testExtension("", ""); |
| 1223 | 1219 | testExtension(".", ""); |
| 1224 | | testExtension("a.", ""); |
| 1225 | | testExtension("abc.", ""); |
| 1220 | testExtension("a.", "."); |
| 1221 | testExtension("abc.", "."); |
| 1226 | 1222 | testExtension(".a", ""); |
| 1227 | 1223 | testExtension(".file", ""); |
| 1228 | 1224 | testExtension(".gitignore", ""); |
| 1229 | 1225 | testExtension("file.ext", ".ext"); |
| 1230 | | testExtension("file.ext.", ""); |
| 1226 | testExtension("file.ext.", "."); |
| 1231 | 1227 | testExtension("very-long-file.bruh", ".bruh"); |
| 1232 | 1228 | testExtension("a.b.c", ".c"); |
| 1233 | 1229 | testExtension("a.b.c/", ".c"); |
| 1234 | 1230 | |
| 1235 | 1231 | testExtension("/", ""); |
| 1236 | 1232 | testExtension("/.", ""); |
| 1237 | | testExtension("/a.", ""); |
| 1238 | | testExtension("/abc.", ""); |
| 1233 | testExtension("/a.", "."); |
| 1234 | testExtension("/abc.", "."); |
| 1239 | 1235 | testExtension("/.a", ""); |
| 1240 | 1236 | testExtension("/.file", ""); |
| 1241 | 1237 | testExtension("/.gitignore", ""); |
| 1242 | 1238 | testExtension("/file.ext", ".ext"); |
| 1243 | | testExtension("/file.ext.", ""); |
| 1239 | testExtension("/file.ext.", "."); |
| 1244 | 1240 | testExtension("/very-long-file.bruh", ".bruh"); |
| 1245 | 1241 | testExtension("/a.b.c", ".c"); |
| 1246 | 1242 | testExtension("/a.b.c/", ".c"); |
| 1247 | 1243 | |
| 1248 | 1244 | testExtension("/foo/bar/bam/", ""); |
| 1249 | 1245 | testExtension("/foo/bar/bam/.", ""); |
| 1250 | | testExtension("/foo/bar/bam/a.", ""); |
| 1251 | | testExtension("/foo/bar/bam/abc.", ""); |
| 1246 | testExtension("/foo/bar/bam/a.", "."); |
| 1247 | testExtension("/foo/bar/bam/abc.", "."); |
| 1252 | 1248 | testExtension("/foo/bar/bam/.a", ""); |
| 1253 | 1249 | testExtension("/foo/bar/bam/.file", ""); |
| 1254 | 1250 | testExtension("/foo/bar/bam/.gitignore", ""); |
| 1255 | 1251 | testExtension("/foo/bar/bam/file.ext", ".ext"); |
| 1256 | | testExtension("/foo/bar/bam/file.ext.", ""); |
| 1252 | testExtension("/foo/bar/bam/file.ext.", "."); |
| 1257 | 1253 | testExtension("/foo/bar/bam/very-long-file.bruh", ".bruh"); |
| 1258 | 1254 | testExtension("/foo/bar/bam/a.b.c", ".c"); |
| 1259 | 1255 | testExtension("/foo/bar/bam/a.b.c/", ".c"); |