packrat/lib/x86_64-pc-linux-gnu/3.2.3/jsonlite/tests/test-libjson-escaping.R

context("libjson Escaping")

test_that("escaping and parsing of special characters", {

  #create random strings
  mychars <- c('a', 'b', " ", '"', "\\", "\t", "\n", "'", "/", "#", "$");
  createstring <- function(length){
    paste(mychars[ceiling(runif(length, 0, length(mychars)))], collapse="")
  }

  #generate 1000 random strings
  for(i in 1:200){
    x <- createstring(i);
    expect_that(x, equals(fromJSON(toJSON(x))));
    expect_that(x, equals(fromJSON(toJSON(x, pretty=TRUE))));

    y <- setNames(list(123), x)
    expect_that(x, equals(fromJSON(toJSON(x, pretty=TRUE))));
  }

});

test_that("filter invalid escape characters", {

  #The \v and \a characters are not supported by JSON. This is a common bug
  #expect_that(validate(toJSON("foo\v\bar\abaz")), is_true());
  #Update: yajl doesn't support \v and \a characters at all. Dropping this test.

});
etsakl/DasyMapR documentation built on May 16, 2019, 9:07 a.m.