@@ -266,23 +266,78 @@ test("unicode filenames", async () => { |
266 | 266 | expect(before).toBeTruthy() |
267 | 267 |
|
268 | 268 | const unicodeFiles = [ |
269 | | - `${tmp.path}/文件.txt`, |
270 | | - `${tmp.path}/🚀rocket.txt`, |
271 | | - `${tmp.path}/café.txt`, |
272 | | - `${tmp.path}/файл.txt`, |
| 269 | + { path: `${tmp.path}/文件.txt`, content: "chinese content" }, |
| 270 | + { path: `${tmp.path}/🚀rocket.txt`, content: "emoji content" }, |
| 271 | + { path: `${tmp.path}/café.txt`, content: "accented content" }, |
| 272 | + { path: `${tmp.path}/файл.txt`, content: "cyrillic content" }, |
273 | 273 | ] |
274 | 274 |
|
275 | 275 | for (const file of unicodeFiles) { |
276 | | - await Bun.write(file, "unicode content") |
| 276 | + await Bun.write(file.path, file.content) |
277 | 277 | } |
278 | 278 |
|
279 | 279 | const patch = await Snapshot.patch(before!) |
280 | | - // Note: git escapes unicode characters by default, so we just check that files are detected |
281 | | - // The actual filenames will be escaped like "caf\303\251.txt" but functionality works |
282 | 280 | expect(patch.files.length).toBe(4) |
283 | 281 |
|
284 | | - // Skip revert test due to git filename escaping issues |
285 | | - // The functionality works but git uses escaped filenames internally |
| 282 | + for (const file of unicodeFiles) { |
| 283 | + expect(patch.files).toContain(file.path) |
| 284 | + } |
| 285 | + |
| 286 | + await Snapshot.revert([patch]) |
| 287 | + |
| 288 | + for (const file of unicodeFiles) { |
| 289 | + expect(await Bun.file(file.path).exists()).toBe(false) |
| 290 | + } |
| 291 | + }, |
| 292 | + }) |
| 293 | +}) |
| 294 | + |
| 295 | +test("unicode filenames modification and restore", async () => { |
| 296 | + await using tmp = await bootstrap() |
| 297 | + await Instance.provide({ |
| 298 | + directory: tmp.path, |
| 299 | + fn: async () => { |
| 300 | + const chineseFile = `${tmp.path}/文件.txt` |
| 301 | + const cyrillicFile = `${tmp.path}/файл.txt` |
| 302 | + |
| 303 | + await Bun.write(chineseFile, "original chinese") |
| 304 | + await Bun.write(cyrillicFile, "original cyrillic") |
| 305 | + |
| 306 | + const before = await Snapshot.track() |
| 307 | + expect(before).toBeTruthy() |
| 308 | + |
| 309 | + await Bun.write(chineseFile, "modified chinese") |
| 310 | + await Bun.write(cyrillicFile, "modified cyrillic") |
| 311 | + |
| 312 | + const patch = await Snapshot.patch(before!) |
| 313 | + expect(patch.files).toContain(chineseFile) |
| 314 | + expect(patch.files).toContain(cyrillicFile) |
| 315 | + |
| 316 | + await Snapshot.revert([patch]) |
| 317 | + |
| 318 | + expect(await Bun.file(chineseFile).text()).toBe("original chinese") |
| 319 | + expect(await Bun.file(cyrillicFile).text()).toBe("original cyrillic") |
| 320 | + }, |
| 321 | + }) |
| 322 | +}) |
| 323 | + |
| 324 | +test("unicode filenames in subdirectories", async () => { |
| 325 | + await using tmp = await bootstrap() |
| 326 | + await Instance.provide({ |
| 327 | + directory: tmp.path, |
| 328 | + fn: async () => { |
| 329 | + const before = await Snapshot.track() |
| 330 | + expect(before).toBeTruthy() |
| 331 | + |
| 332 | + await $`mkdir -p "${tmp.path}/目录/подкаталог"`.quiet() |
| 333 | + const deepFile = `${tmp.path}/目录/подкаталог/文件.txt` |
| 334 | + await Bun.write(deepFile, "deep unicode content") |
| 335 | + |
| 336 | + const patch = await Snapshot.patch(before!) |
| 337 | + expect(patch.files).toContain(deepFile) |
| 338 | + |
| 339 | + await Snapshot.revert([patch]) |
| 340 | + expect(await Bun.file(deepFile).exists()).toBe(false) |
286 | 341 | }, |
287 | 342 | }) |
288 | 343 | }) |
|