github.com/zhongdalu/gf@v1.0.0/g/os/gfile/gfile_z_size_test.go (about)

     1  package gfile_test
     2  
     3  import (
     4  	"github.com/zhongdalu/gf/g/os/gfile"
     5  	"github.com/zhongdalu/gf/g/test/gtest"
     6  	"testing"
     7  )
     8  
     9  func TestSize(t *testing.T) {
    10  	gtest.Case(t, func() {
    11  		var (
    12  			paths1 string = "/testfile_t1.txt"
    13  			sizes  int64
    14  		)
    15  
    16  		createTestFile(paths1, "abcdefghijklmn")
    17  		defer delTestFiles(paths1)
    18  
    19  		sizes = gfile.Size(testpath() + paths1)
    20  		gtest.Assert(sizes, 14)
    21  
    22  		sizes = gfile.Size("")
    23  		gtest.Assert(sizes, 0)
    24  
    25  	})
    26  }
    27  
    28  func TestFormatSize(t *testing.T) {
    29  	gtest.Case(t, func() {
    30  		gtest.Assert(gfile.FormatSize(0), "0.00B")
    31  		gtest.Assert(gfile.FormatSize(16), "16.00B")
    32  
    33  		gtest.Assert(gfile.FormatSize(1024), "1.00K")
    34  
    35  		gtest.Assert(gfile.FormatSize(16000000), "15.26M")
    36  
    37  		gtest.Assert(gfile.FormatSize(1600000000), "1.49G")
    38  
    39  		gtest.Assert(gfile.FormatSize(9600000000000), "8.73T")
    40  		gtest.Assert(gfile.FormatSize(9600000000000000), "8.53P")
    41  
    42  		gtest.Assert(gfile.FormatSize(9600000000000000000), "TooLarge")
    43  
    44  	})
    45  }
    46  
    47  func TestReadableSize(t *testing.T) {
    48  	gtest.Case(t, func() {
    49  
    50  		var (
    51  			paths1 string = "/testfile_t1.txt"
    52  		)
    53  		createTestFile(paths1, "abcdefghijklmn")
    54  		defer delTestFiles(paths1)
    55  		gtest.Assert(gfile.ReadableSize(testpath()+paths1), "14.00B")
    56  		gtest.Assert(gfile.ReadableSize(""), "0.00B")
    57  
    58  	})
    59  }