-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathformat_test.go
59 lines (49 loc) · 1.61 KB
/
format_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
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// go-aah/essentials source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package ess
import (
"testing"
"aahframework.org/test.v0/assert"
)
func TestBStrToBytes(t *testing.T) {
checkBytesValue(t, "2b", int64(2))
checkBytesValue(t, "2B", int64(2))
checkBytesValue(t, "2b", int64(2))
checkBytesValue(t, "2B", int64(2))
}
func TestKBStrToBytes(t *testing.T) {
checkBytesValue(t, "2kb", int64(2048))
checkBytesValue(t, "2KB", int64(2048))
checkBytesValue(t, "2kib", int64(2048))
checkBytesValue(t, "2KiB", int64(2048))
}
func TestMBStrToBytes(t *testing.T) {
checkBytesValue(t, "2mb", int64(2097152))
checkBytesValue(t, "2MB", int64(2097152))
checkBytesValue(t, "2mib", int64(2097152))
checkBytesValue(t, "2MiB", int64(2097152))
}
func TestGBStrToBytes(t *testing.T) {
checkBytesValue(t, "2gb", int64(2147483648))
checkBytesValue(t, "2GB", int64(2147483648))
checkBytesValue(t, "2Gib", int64(2147483648))
checkBytesValue(t, "2GiB", int64(2147483648))
}
func TestTBStrToBytes(t *testing.T) {
checkBytesValue(t, "2tb", int64(2199023255552))
checkBytesValue(t, "2TB", int64(2199023255552))
checkBytesValue(t, "2Tib", int64(2199023255552))
checkBytesValue(t, "2TiB", int64(2199023255552))
}
func TestErrStrToBytes(t *testing.T) {
v1, err := StrToBytes("2")
assert.NotNil(t, err)
assert.Equal(t, "format: invalid input '2'", err.Error())
assert.Equal(t, int64(0), v1)
}
func checkBytesValue(t *testing.T, value string, expt int64) {
v, err := StrToBytes(value)
assert.Nil(t, err)
assert.Equal(t, expt, v)
}