gf/g/os/gfile/gfile_size_test.go

52 lines
954 B
Go
Raw Normal View History

2019-04-10 17:54:28 +08:00
//test 100%
2019-04-10 16:22:29 +08:00
package gfile
import (
"github.com/gogf/gf/g/test/gtest"
"testing"
)
2019-04-12 09:47:55 +08:00
func TestSize(t *testing.T) {
gtest.Case(t, func() {
var (
paths1 string = "./testfile/dirfiles/t1.txt"
sizes int64
2019-04-10 16:22:29 +08:00
)
2019-04-12 09:47:55 +08:00
sizes = Size(paths1)
gtest.Assert(sizes, 16)
2019-04-10 17:54:28 +08:00
2019-04-12 09:47:55 +08:00
sizes = Size("")
gtest.Assert(sizes, 0)
2019-04-10 16:22:29 +08:00
})
}
2019-04-12 09:47:55 +08:00
func TestFormatSize(t *testing.T) {
gtest.Case(t, func() {
gtest.Assert(FormatSize(0), "0.00B")
gtest.Assert(FormatSize(16), "16.00B")
2019-04-10 16:22:29 +08:00
2019-04-12 09:47:55 +08:00
gtest.Assert(FormatSize(1024), "1.00K")
2019-04-10 16:22:29 +08:00
2019-04-12 09:47:55 +08:00
gtest.Assert(FormatSize(16000000), "15.26M")
2019-04-10 16:22:29 +08:00
2019-04-12 09:47:55 +08:00
gtest.Assert(FormatSize(1600000000), "1.49G")
2019-04-10 17:54:28 +08:00
2019-04-12 09:47:55 +08:00
gtest.Assert(FormatSize(9600000000000), "8.73T")
gtest.Assert(FormatSize(9600000000000000), "8.53P")
2019-04-10 17:54:28 +08:00
2019-04-12 09:47:55 +08:00
gtest.Assert(FormatSize(9600000000000000000), "TooLarge")
2019-04-10 16:22:29 +08:00
})
}
2019-04-12 09:47:55 +08:00
func TestReadableSize(t *testing.T) {
gtest.Case(t, func() {
2019-04-10 16:22:29 +08:00
2019-04-12 09:47:55 +08:00
gtest.Assert(ReadableSize("./testfile/dirfiles/t1.txt"), "16.00B")
gtest.Assert(ReadableSize(""), "0.00B")
2019-04-10 16:22:29 +08:00
})
}