Skip to content

Commit

Permalink
Fixed error on lowercase multiple parse (#35)
Browse files Browse the repository at this point in the history
bug: for example, 6gb or 6g will return 6.
  • Loading branch information
prabhah authored and vishr committed Jul 11, 2019
1 parent d700b06 commit 1f43c1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bytes/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"regexp"
"strconv"
"strings"
)

type (
Expand Down Expand Up @@ -73,7 +74,7 @@ func (*Bytes) Parse(value string) (i int64, err error) {
return 0, fmt.Errorf("error parsing value=%s", value)
}
bytesString := parts[1]
multiple := parts[2]
multiple := strings.ToUpper(parts[2])
bytes, err := strconv.ParseFloat(bytesString, 64)
if err != nil {
return
Expand Down
15 changes: 15 additions & 0 deletions bytes/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ func TestBytesParse(t *testing.T) {
assert.Equal(t, int64(12288), b)
}

// kb, lowercase multiple test
b, err = Parse("12.25kb")
if assert.NoError(t, err) {
assert.Equal(t, int64(12544), b)
}
b, err = Parse("12kb")
if assert.NoError(t, err) {
assert.Equal(t, int64(12288), b)
}
b, err = Parse("12k")
if assert.NoError(t, err) {
assert.Equal(t, int64(12288), b)
}


// KB with space
b, err = Parse("12.25 KB")
if assert.NoError(t, err) {
Expand Down

0 comments on commit 1f43c1e

Please sign in to comment.