bytes_test.go 492 B

123456789101112131415161718192021222324252627282930
  1. package bytes
  2. import "testing"
  3. func TestBytes(t *testing.T) {
  4. // B
  5. b := Format(515)
  6. if b != "515 B" {
  7. t.Errorf("expected `515 B`, got %s", b)
  8. }
  9. // MB
  10. b = Format(13231323)
  11. if b != "13.23 MB" {
  12. t.Errorf("expected `13.23 MB`, got %s", b)
  13. }
  14. // Exact
  15. b = Format(1000 * 1000 * 1000)
  16. if b != "1.00 GB" {
  17. t.Errorf("expected `1.00 GB`, got %s", b)
  18. }
  19. // Binary prefix
  20. BinaryPrefix(true)
  21. b = Format(1323)
  22. if b != "1.29 KiB" {
  23. t.Errorf("expected `1.29 KiB`, got %s", b)
  24. }
  25. }