tests/testthat/test-int64-overflow.R

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' bit64::int64 is a signed integer.  but json has an unsigned 64bit
#' integer type.  We should warn when something happens here.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test_that("int64 overflow protection works", {
  
  expect_warning(read_json_str('[9223372036854775809]', int64 = 'bit64'), "overflow")
  
  expect_identical(read_json_str('[9223372036854775809]'), "9223372036854775809")  
  expect_identical(
    read_json_str('[9223372036854775807]', int64 = 'bit64'), 
    bit64::as.integer64("9223372036854775807")
  )
  
  
  
  expect_warning(read_json_str('9223372036854775809', int64 = 'bit64'), "overflow")
  
})

Try the yyjsonr package in your browser

Any scripts or data that you put into this service are public.

yyjsonr documentation built on May 29, 2024, 3:01 a.m.