github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/file/test/file_test.go (about) 1 package test 2 3 import ( 4 "github.com/isyscore/isc-gobase/isc" 5 "github.com/magiconair/properties/assert" 6 "os" 7 "path/filepath" 8 "testing" 9 10 "github.com/isyscore/isc-gobase/file" 11 ) 12 13 func TestFile(t *testing.T) { 14 // file.WriteFile("./sample.txt", "aaa") 15 dir, _ := os.Getwd() 16 path := filepath.Join(dir, "sample.txt") 17 18 file.AppendFile(path, "ccc") 19 file.DeleteFile("sample.txt") 20 } 21 22 func TestExtract(t *testing.T) { 23 dir, _ := os.Getwd() 24 path := filepath.Join(dir, "sample.txt") 25 p0 := file.ExtractFilePath(path) 26 t.Logf("p0: %s", p0) 27 n0 := file.ExtractFileName(path) 28 t.Logf("n0: %s", n0) 29 e0 := file.ExtractFileExt(path) 30 t.Logf("e0: %s", e0) 31 c0 := file.ChangeFileExt(path, "xyz") 32 t.Logf("c0: %s", c0) 33 } 34 35 func TestCreatFile(t *testing.T) { 36 file.CreateFile("./file/test.txt") 37 file.CreateFile("./test2.txt") 38 39 file.DeleteFile("./test2.txt") 40 file.DeleteDirs("./file/") 41 } 42 43 func TestChild(t *testing.T) { 44 f, _ := file.Child("../") 45 for i := range f { 46 t.Logf("file_name: %s", f[i].Name()) 47 } 48 } 49 50 func TestFileSize(t *testing.T) { 51 assert.Equal(t, isc.ToInt64(40), file.Size("./assert_file_size.txt")) 52 } 53 54 func TestFileFormatSize(t *testing.T) { 55 assert.Equal(t, "40.00B", file.SizeFormat("./assert_file_size.txt")) 56 } 57 58 func TestFileCopy(t *testing.T) { 59 err := file.CopyFileWithError("./assert_file_size.txt", "./temp/assert_file_size_copy.txt") 60 assert.Equal(t, err, nil) 61 assert.Equal(t, "40.00B", file.SizeFormat("./temp/assert_file_size_copy.txt")) 62 file.DeleteDirs("./temp") 63 }