(t *testing.T)
| 1586 | } |
| 1587 | |
| 1588 | func TestBrowse(t *testing.T) { |
| 1589 | t.Parallel() |
| 1590 | |
| 1591 | pathSep := string(os.PathSeparator) |
| 1592 | |
| 1593 | ffs := fs.NewFilesystem(fs.FilesystemTypeFake, rand.String(32)+"?nostfolder=true") |
| 1594 | |
| 1595 | _ = ffs.Mkdir("dir", 0o755) |
| 1596 | _ = fs.WriteFile(ffs, "file", []byte("hello"), 0o644) |
| 1597 | _ = ffs.Mkdir("MiXEDCase", 0o755) |
| 1598 | |
| 1599 | // We expect completion to return the full path to the completed |
| 1600 | // directory, with an ending slash. |
| 1601 | dirPath := "dir" + pathSep |
| 1602 | mixedCaseDirPath := "MiXEDCase" + pathSep |
| 1603 | |
| 1604 | cases := []struct { |
| 1605 | current string |
| 1606 | returns []string |
| 1607 | }{ |
| 1608 | // The directory without slash is completed to one with slash. |
| 1609 | {"dir", []string{"dir" + pathSep}}, |
| 1610 | // With slash it's completed to its contents. |
| 1611 | // Dirs are given pathSeps. |
| 1612 | // Files are not returned. |
| 1613 | {"", []string{mixedCaseDirPath, dirPath}}, |
| 1614 | // Globbing is automatic based on prefix. |
| 1615 | {"d", []string{dirPath}}, |
| 1616 | {"di", []string{dirPath}}, |
| 1617 | {"dir", []string{dirPath}}, |
| 1618 | {"f", nil}, |
| 1619 | {"q", nil}, |
| 1620 | // Globbing is case-insensitive |
| 1621 | {"mixed", []string{mixedCaseDirPath}}, |
| 1622 | } |
| 1623 | |
| 1624 | for _, tc := range cases { |
| 1625 | ret := browseFiles(ffs, tc.current) |
| 1626 | if !slices.Equal(ret, tc.returns) { |
| 1627 | t.Errorf("browseFiles(%q) => %q, expected %q", tc.current, ret, tc.returns) |
| 1628 | } |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | func TestPrefixMatch(t *testing.T) { |
| 1633 | t.Parallel() |
nothing calls this directly
no test coverage detected