bytes_test.go 765 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package bytes
  2. import (
  3. "testing"
  4. "github.com/labstack/gommon/bytes"
  5. "fmt"
  6. )
  7. func TestFormat(t *testing.T) {
  8. fmt.Println(bytes.Format(1323))
  9. // Zero
  10. f := Format(0)
  11. if f != "--" {
  12. t.Errorf("formatted bytes should be --, found %s", f)
  13. }
  14. // B
  15. f = Format(515)
  16. if f != "515 B" {
  17. t.Errorf("formatted bytes should be 515 B, found %s", f)
  18. }
  19. // MB
  20. f = Format(13231323)
  21. if f != "12.62 MB" {
  22. t.Errorf("formatted bytes should be 12.62 MB, found %s", f)
  23. }
  24. // Exact
  25. f = Format(1024 * 1024 * 1024)
  26. if f != "1.00 GB" {
  27. t.Errorf("formatted bytes should be 1.00 GB, found %s", f)
  28. }
  29. }
  30. func TestBinaryPrefix(t *testing.T) {
  31. BinaryPrefix(true)
  32. f := Format(1323)
  33. if f != "1.29 KiB" {
  34. t.Errorf("formatted bytes should be 1.29 KiB, found %s", f)
  35. }
  36. }