Ver Fonte

Minor fixes for bytes package

Vishal Rana há 10 anos atrás
pai
commit
d251db5060
2 ficheiros alterados com 5 adições e 16 exclusões
  1. 3 3
      bytes/bytes.go
  2. 2 13
      bytes/bytes_test.go

+ 3 - 3
bytes/bytes.go

@@ -13,6 +13,8 @@ var (
 func BinaryPrefix(on bool) {
 	if on {
 		sfx = "iB"
+	} else {
+		sfx = "B"
 	}
 }
 
@@ -21,9 +23,7 @@ func Format(b uint64) string {
 	n := float64(b)
 	unit := float64(1024)
 
-	if n == 0 {
-		return "--"
-	} else if n < unit {
+	if n < unit {
 		return fmt.Sprintf("%.0f B", n)
 	} else {
 		e := math.Floor(math.Log(n) / math.Log(unit))

+ 2 - 13
bytes/bytes_test.go

@@ -1,21 +1,10 @@
 package bytes
 
-import (
-	"testing"
-	"github.com/labstack/gommon/bytes"
-	"fmt"
-)
+import "testing"
 
 func TestFormat(t *testing.T) {
-	fmt.Println(bytes.Format(1323))
-	// Zero
-	f := Format(0)
-	if f != "--" {
-		t.Errorf("formatted bytes should be --, found %s", f)
-	}
-
 	// B
-	f = Format(515)
+	f := Format(515)
 	if f != "515 B" {
 		t.Errorf("formatted bytes should be 515 B, found %s", f)
 	}