| 1 | //go:build darwin |
| 2 | |
| 3 | package repair |
| 4 | |
| 5 | import ( |
| 6 | "os" |
| 7 | "path/filepath" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestPlatformRepairPathCaseInsensitiveMatchesDirectoryLookup(t *testing.T) { |
| 12 | root := t.TempDir() |
| 13 | exact := filepath.Join(root, "CaseProbe") |
| 14 | if err := os.WriteFile(exact, []byte("probe"), 0o600); err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | _, lookupErr := os.Stat(filepath.Join(root, "caseprobe")) |
| 18 | want := lookupErr == nil |
| 19 | if got := platformRepairPathCaseInsensitive(exact); got != want { |
| 20 | t.Fatalf("case-insensitive detection = %v, directory lookup = %v", got, want) |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | func TestCanonicalRepairPathConvergesUnicodeAliases(t *testing.T) { |
| 25 | root := t.TempDir() |
| 26 | nfcDir := filepath.Join(root, "Caf\u00e9") |
| 27 | nfdDir := filepath.Join(root, "Cafe\u0301") |
| 28 | if err := os.Mkdir(nfcDir, 0o700); err != nil { |
| 29 | t.Fatal(err) |
| 30 | } |
| 31 | if _, err := os.Stat(nfdDir); err != nil { |
| 32 | t.Skipf("filesystem keeps NFC and NFD names distinct: %v", err) |
| 33 | } |
| 34 | nfcTarget := filepath.Join(nfcDir, "state.json") |
| 35 | nfdTarget := filepath.Join(nfdDir, "state.json") |
| 36 | if got, want := canonicalRepairPath(nfdTarget), canonicalRepairPath(nfcTarget); got != want { |
| 37 | t.Fatalf("Unicode aliases use different repair keys:\nNFD: %q\nNFC: %q", got, want) |
| 38 | } |
| 39 | } |
| 40 |