func (s *memLocationTest) TestURI() {
	file, nerr := s.fileSystem.NewFile("", "/some/file/test.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.NoError(file.Touch(), "unexpected error touching file")
	location := file.Location()
	_, eerr := location.Exists()
	s.NoError(eerr, "unexpected error checking for existence")
	expected := "mem:///some/file/"
	s.Equal(expected, location.URI(), "%s does not match %s", location.URI(), expected)
	s.NoError(file.Delete(), "delete failed unexpectedly")
}
TestURI ensures that URI's for locations come out in the correct format
package mem
import (
	"path"
	"regexp"
	"testing"
	"github.com/stretchr/testify/suite"
	"github.com/c2fo/vfs/v6"
)
type memLocationTest struct {
	suite.Suite
	testFile   vfs.File
	fileSystem *FileSystem
}
func (s *memLocationTest) SetupTest() {
	fs := NewFileSystem()
	file, nerr := fs.NewFile("", "/test_files/test.txt")
	s.NoError(nerr, "file creation was not successful so it does not exist")
	s.testFile = file.(*File)
	s.fileSystem = fs
	s.NoError(s.testFile.Touch(), "unexpected error touching file")
}
func (s *memLocationTest) TestFSName() {
	s.Equal(s.testFile.Location().FileSystem().Name(), "In-Memory Filesystem")
	s.Equal(s.testFile.Location().FileSystem().Scheme(), "mem")
}
func (s *memLocationTest) TestList() {
	expected := []string{"test.txt"}
	actual, _ := s.testFile.Location().List()
	s.Equal(expected, actual)
}
func (s *memLocationTest) TestList_NonExistentDirectory() {
	location, err := s.testFile.Location().NewLocation("not/a/directory/")
	s.Nil(err, "error isn't expected")
	exists, err := location.Exists()
	s.Nil(err, "error isn't expected")
	s.True(exists, "location should return true for Exists")
	contents, err := location.List()
	s.Nil(err, "error isn't expected")
	s.Equal(0, len(contents), "list should return empty slice for non-existent directory")
	prefixContents, err := location.ListByPrefix("anything")
	s.Nil(err, "error isn't expected")
	s.Equal(0, len(prefixContents), "ListByPrefix should return empty slice for non-existent directory")
	regex := regexp.MustCompile("-+")
	regexContents, err := location.ListByRegex(regex)
	s.Nil(err, "error isn't expected")
	s.Equal(0, len(regexContents), "ListByRegex should return empty slice for non-existent directory")
}
func (s *memLocationTest) TestListByPrefix() {
	f1, nerr := s.fileSystem.NewFile("", "/foo.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.NoError(f1.Touch(), "unexpected error touching file")
	f2, nerr := s.fileSystem.NewFile("", "/home/test_files/subdir/file1.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.NoError(f2.Touch(), "unexpected error touching file")
	f3, nerr := s.fileSystem.NewFile("", "/home/test_files/subdir/file2.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.NoError(f3.Touch(), "unexpected error touching file")
	f4, nerr := s.fileSystem.NewFile("", "/home/directories/test/mat.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.NoError(f4.Touch(), "unexpected error touching file")
	f5, nerr := s.fileSystem.NewFile("", "/test/files/car.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.NoError(f5.Touch(), "unexpected error touching file")
	loc, lerr := s.fileSystem.NewLocation("", "/home/test_files/subdir/")
	s.NoError(lerr, "unexpected error creating a location")
	nameSlice, lerr := loc.ListByPrefix("f")
	s.NoError(lerr, "unexpected error obtaining list by prefix")
	expectedSlice := []string{"file1.txt", "file2.txt"}
	s.Equal(expectedSlice, nameSlice)
	emptySlice, err := s.testFile.Location().ListByPrefix("m")
	s.NoError(err, "unexpected error retrieving files by prefix")
	s.Equal(make([]string, 0), emptySlice)  
}
func (s *memLocationTest) TestListByRegex() {
	newFile, nerr := s.fileSystem.NewFile("", "/test_files/test.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.NoError(newFile.Touch(), "unexpected error touching file")
	expected := []string{"test.txt"}
	regex := regexp.MustCompile("[est]+")
	actual, err := newFile.Location().ListByRegex(regex)
	s.NoError(err, "unexpected error listing by regEx")
	s.Equal(expected, actual)
	err = newFile.Location().ChangeDir("../")
	s.NoError(err, "unexpected error changing directories")
	regex2 := regexp.MustCompile("test.txt")
	actual2, err := newFile.Location().ListByRegex(regex2)
	s.NoError(err, "unexpected error listing by regEx")
	s.Equal(expected, actual2)
}
func (s *memLocationTest) TestExists() {
	otherFile, nerr := s.fileSystem.NewFile("", "/foo/foo.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.True(s.testFile.Location().Exists())
	s.True(otherFile.Location().Exists())
}
func (s *memLocationTest) TestNewLocation() {
	otherFile, nerr := s.fileSystem.NewFile("", "/foo/foo.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	fileLocation := otherFile.Location()
	subDir, lerr := fileLocation.NewLocation("other/")
	s.NoError(lerr, "unexpected error creating a new location")
	s.Equal("/foo/other/", subDir.Path())
	relDir, lerr2 := subDir.NewLocation("../../bar/")
	s.NoError(lerr2, "unexpected error creating a new location")
	s.Equal("/bar/", relDir.Path(), "relative dot path works")
}
func (s *memLocationTest) TestNewLocationRelativePath() {
	newFile, nerr := s.fileSystem.NewFile("C", "/newLocTest/dir/file.txt")
	s.NoError(nerr, "unexpected error creating a file")
	_, werr := newFile.Write([]byte("Hello world!"))
	s.NoError(werr, "unexpected write error")
	s.NoError(newFile.Close(), "unexpected error closing file")
	loc, nerr2 := s.fileSystem.NewLocation("C", "/newLocTest/")
	s.NoError(nerr2, "unexpected error creating a new location")
	s.True(loc.Exists())
	otherFile, lerr := loc.NewFile("dir/file2.txt")
	s.NoError(lerr, "unexpected error creating a file from location")
	s.NoError(otherFile.Touch(), "unexpected error touching file")
	s.Equal(newFile.Location().Path(), otherFile.Location().Path(), "absolute location paths should be equal")
}
func (s *memLocationTest) TestNewFile() {
	loc, err := s.fileSystem.NewLocation("", "/foo/bar/baz/")
	s.NoError(err, "unexpected error creating a new location")
	newfile, nerr := loc.NewFile("../../bam/this.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.Equal("/foo/bam/this.txt", newfile.Path(), "relative dot path works")
}
func (s *memLocationTest) TestNewFileSameName() {
	sharedPath := "/path/to/file.txt"
	firstFile, err := s.fileSystem.NewFile("", sharedPath)
	s.NoError(err, "unexpected error creating a file")
	location := firstFile.Location()
	expectedText := "hey y'all!"
	_, err = firstFile.Write([]byte(expectedText))
	s.NoError(err, "unexpected error writing to file")
	secondFile, err := location.NewFile(path.Base(sharedPath))
	s.NoError(err, "unexpected error creating a file")
	expectedSlice := make([]byte, len(expectedText))
	_, err = secondFile.Read(expectedSlice)
	s.Error(err, "expected read error since firstFile was never closed")
	s.NoError(firstFile.Close(), "unexpected error closing file")
	_, err = secondFile.Read(expectedSlice)
	s.NoError(err, "unexpected read error")
	s.Equal(expectedText, string(expectedSlice))
}
func (s *memLocationTest) TestChangeDir() {
	newFile, nerr := s.fileSystem.NewFile("", "/dir/to/change/change.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.NoError(newFile.Touch(), "unexpected error touching file")
	loc := newFile.Location()
	s.NoError(loc.ChangeDir("extraDir/"), "unexpected error while changing directory")
	exists, eerr := loc.Exists()
	s.NoError(eerr, "unexpected error checking for Existence")
	s.True(exists)
	s.False(newFile.Location().Path() == loc.Path())
}
func (s *memLocationTest) TestVolume() {
	newFile, nerr := s.fileSystem.NewFile("D:", "/path/to/file/example.txt")
	s.NoError(nerr, "unexpected error creating a file")
	s.NoError(newFile.Touch(), "unexpected error touching file")
	s.NoError(newFile.Close(), "unexpected error closing file")
	s.Equal("D:", newFile.Location().Volume())
}
func (s *memLocationTest) TestPath() {
	file, nerr := s.fileSystem.NewFile("", "/some/file/test.txt")
	s.NoError(nerr, "unexpected error creating a new file")
	s.NoError(file.Touch(), "unexpected error touching file")
	location := file.Location()
	s.Equal("/some/file/", location.Path())
	s.NoError(file.Delete(), "Delete failed unexpectedly")
}