bytesconv_64_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //go:build amd64 || arm64 || ppc64 || ppc64le
  2. // +build amd64 arm64 ppc64 ppc64le
  3. package fasthttp
  4. import (
  5. "testing"
  6. )
  7. func TestWriteHexInt(t *testing.T) {
  8. t.Parallel()
  9. testWriteHexInt(t, 0, "0")
  10. testWriteHexInt(t, 1, "1")
  11. testWriteHexInt(t, 0x123, "123")
  12. testWriteHexInt(t, 0x7fffffffffffffff, "7fffffffffffffff")
  13. }
  14. func TestAppendUint(t *testing.T) {
  15. t.Parallel()
  16. testAppendUint(t, 0)
  17. testAppendUint(t, 123)
  18. testAppendUint(t, 0x7fffffffffffffff)
  19. for i := 0; i < 2345; i++ {
  20. testAppendUint(t, i)
  21. }
  22. }
  23. func TestReadHexIntSuccess(t *testing.T) {
  24. t.Parallel()
  25. testReadHexIntSuccess(t, "0", 0)
  26. testReadHexIntSuccess(t, "fF", 0xff)
  27. testReadHexIntSuccess(t, "00abc", 0xabc)
  28. testReadHexIntSuccess(t, "7fffffff", 0x7fffffff)
  29. testReadHexIntSuccess(t, "000", 0)
  30. testReadHexIntSuccess(t, "1234ZZZ", 0x1234)
  31. testReadHexIntSuccess(t, "7ffffffffffffff", 0x7ffffffffffffff)
  32. }
  33. func TestParseUintError64(t *testing.T) {
  34. t.Parallel()
  35. // Overflow by last digit: 2 ** 64 / 2 * 10 ** n
  36. testParseUintError(t, "9223372036854775808")
  37. testParseUintError(t, "92233720368547758080")
  38. testParseUintError(t, "922337203685477580800")
  39. }
  40. func TestParseUintSuccess(t *testing.T) {
  41. t.Parallel()
  42. testParseUintSuccess(t, "0", 0)
  43. testParseUintSuccess(t, "123", 123)
  44. testParseUintSuccess(t, "1234567890", 1234567890)
  45. testParseUintSuccess(t, "123456789012345678", 123456789012345678)
  46. // Max supported value: 2 ** 64 / 2 - 1
  47. testParseUintSuccess(t, "9223372036854775807", 9223372036854775807)
  48. }