price_test.go 707 B

1234567891011121314151617181920212223242526272829
  1. package strconv // import "github.com/tdewolff/parse/strconv"
  2. import (
  3. "testing"
  4. "github.com/tdewolff/test"
  5. )
  6. func TestAppendPrice(t *testing.T) {
  7. priceTests := []struct {
  8. price int64
  9. dec bool
  10. expected string
  11. }{
  12. {0, false, "0"},
  13. {0, true, "0.00"},
  14. {100, true, "1.00"},
  15. {-100, true, "1.00"},
  16. {100000, false, "1,000"},
  17. {100000, true, "1,000.00"},
  18. {123456789012, true, "1,234,567,890.12"},
  19. {9223372036854775807, true, "92,233,720,368,547,758.07"},
  20. {-9223372036854775808, true, "92,233,720,368,547,758.08"},
  21. }
  22. for _, tt := range priceTests {
  23. price := AppendPrice([]byte{}, tt.price, tt.dec, ',', '.')
  24. test.String(t, string(price), tt.expected, "for", tt.price)
  25. }
  26. }