-
Notifications
You must be signed in to change notification settings - Fork 0
/
dehumanize_test.go
71 lines (67 loc) · 2.7 KB
/
dehumanize_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package dehumanize
import (
log "github.com/cihub/seelog"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestYearDate(t *testing.T) {
defer log.Flush()
Convey("regex compiled", t, func() {
So(initErr, ShouldBeNil)
})
Convey("bytes conversion", t, func() {
So(SizeConvert("1b", 0), ShouldEqual, 1)
So(SizeConvert("1b", 1000), ShouldEqual, 1)
So(SizeConvert("1B", 0), ShouldEqual, 1)
})
Convey("kbytes conversion", t, func() {
So(SizeConvert("1kb", 0), ShouldEqual, 1024)
So(SizeConvert("1Kb", 0), ShouldEqual, 1024)
So(SizeConvert("1kB", 0), ShouldEqual, 1024)
So(SizeConvert("1KB", 0), ShouldEqual, 1024)
So(SizeConvert("1.2kb", 0), ShouldEqual, 1228)
So(SizeConvert("1kb", 1000), ShouldEqual, 1000)
So(SizeConvert("1.2kb", 1000), ShouldEqual, 1200)
})
Convey("mbytes conversion", t, func() {
So(SizeConvert("1mb", 0), ShouldEqual, 1024*1024)
So(SizeConvert("1Mb", 0), ShouldEqual, 1024*1024)
So(SizeConvert("1mB", 0), ShouldEqual, 1024*1024)
So(SizeConvert("1MB", 0), ShouldEqual, 1024*1024)
So(SizeConvert("1.2mb", 0), ShouldEqual, 1258291)
So(SizeConvert("1mb", 1000), ShouldEqual, 1000000)
So(SizeConvert("1.2mb", 1000), ShouldEqual, 1200000)
})
Convey("gbytes conversion", t, func() {
So(SizeConvert("1gb", 0), ShouldEqual, 1024*1024*1024)
So(SizeConvert("1Gb", 0), ShouldEqual, 1024*1024*1024)
So(SizeConvert("1gB", 0), ShouldEqual, 1024*1024*1024)
So(SizeConvert("1GB", 0), ShouldEqual, 1024*1024*1024)
So(SizeConvert("1.2gb", 0), ShouldEqual, 1288490188)
So(SizeConvert("1gb", 1000), ShouldEqual, 1000000000)
So(SizeConvert("1.2gb", 1000), ShouldEqual, 1200000000)
})
Convey("tbytes conversion", t, func() {
So(SizeConvert("1tb", 0), ShouldEqual, 1024*1024*1024*1024)
So(SizeConvert("1Tb", 0), ShouldEqual, 1024*1024*1024*1024)
So(SizeConvert("1tB", 0), ShouldEqual, 1024*1024*1024*1024)
So(SizeConvert("1TB", 0), ShouldEqual, 1024*1024*1024*1024)
So(SizeConvert("1.2tb", 0), ShouldEqual, 1319413953331)
So(SizeConvert("1tb", 1000), ShouldEqual, 1000000000000)
So(SizeConvert("1.2tb", 1000), ShouldEqual, 1200000000000)
})
Convey("tbytes conversion", t, func() {
So(SizeConvert("1pb", 0), ShouldEqual, 1024*1024*1024*1024*1024)
So(SizeConvert("1Pb", 0), ShouldEqual, 1024*1024*1024*1024*1024)
So(SizeConvert("1pB", 0), ShouldEqual, 1024*1024*1024*1024*1024)
So(SizeConvert("1PB", 1000), ShouldEqual, 1000000000000000)
So(SizeConvert("1.2pb", 1000), ShouldEqual, 1200000000000000)
})
Convey("garbage conversion", t, func() {
So(SizeConvert("1nb", 0), ShouldEqual, 0)
So(SizeConvert("1.2nb", 0), ShouldEqual, 0)
So(SizeConvert("", 0), ShouldEqual, 0)
So(SizeConvert("kb", 0), ShouldEqual, 0)
So(SizeConvert("1.b", 0), ShouldEqual, 1)
})
}