| 1 | |
| 2 | |
| 3 | package reversesshfs |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestFoldNameIgnorables(t *testing.T) { |
| 10 | |
| 11 | for _, r := range []rune{ |
| 12 | 0x200b, 0x200c, 0x200d, 0x200e, 0x200f, 0x202a, 0x202e, 0x2060, 0x2061, 0x2064, 0x206a, 0x206f, 0xfeff, |
| 13 | 0xad, 0x34f, 0x61c, 0x115f, 0x1160, 0x17b4, 0x17b5, 0x180b, 0x180e, 0x180f, 0x3164, 0xfe00, 0xfe0f, 0xffa0, |
| 14 | 0xfff0, 0xe0001, 0xe0020, 0xe0100, 0xe01ef, |
| 15 | } { |
| 16 | s := string(r) |
| 17 | for _, name := range []string{".g" + s + "it", ".gi" + s + "t", ".git" + s, s + ".git", ".GIT" + s} { |
| 18 | if !sameName(name, ".git") { |
| 19 | t.Errorf("%+q should match .git", name) |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | if !sameName(".gıt", ".git") || !sameName("ſrc", "src") { |
| 25 | t.Error("dotless i or long s") |
| 26 | } |
| 27 | for _, name := range []string{".gt", ".gitt", ".gi.t", ".ǵit", ".g it"} { |
| 28 | if sameName(name, ".git") { |
| 29 | t.Errorf("%+q should not match .git", name) |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func FuzzFoldIgnorables(f *testing.F) { |
| 35 | for _, s := range []string{".git", ".git", "Aㅤb", "é", "é"} { |
| 36 | f.Add(s, uint8(1)) |
| 37 | } |
| 38 | f.Fuzz(func(t *testing.T, s string, at uint8) { |
| 39 | |
| 40 | i := int(at) % (len(s) + 1) |
| 41 | for i > 0 && i < len(s) && s[i]&0xc0 == 0x80 { |
| 42 | i-- |
| 43 | } |
| 44 | if got, want := FoldName(s[:i]+"️ㅤ"+s[i:]), FoldName(s); got != want { |
| 45 | t.Errorf("FoldName(%q with ignorables at %d) = %q, want %q", s, i, got, want) |
| 46 | } |
| 47 | }) |
| 48 | } |