tests/testthat/test-V8.R

test_that("V8 prettify JavaScript with default `tabSize`", {
  skip_if_not_installed("V8")
  skip_if(substr(V8::engine_info()$version, 1 , 1) < 6, "V8 engine too old.")
  code <- c(
    "function f(x){",
    "var y= x+1",
    "console.log('y:',y) ;",
    "}"
  )
  prettyCode <- prettify_V8(code, "javascript")
  expect_equal(
    prettyCode,
    "function f(x) {\n  var y = x + 1;\n  console.log(\"y:\", y);\n}\n"
  )
})

test_that("V8 prettify JavaScript with given `tabSize`", {
  skip_if_not_installed("V8")
  skip_if(substr(V8::engine_info()$version, 1 , 1) < 6, "V8 engine too old.")
  code <- c(
    "function f(x){",
    "var y= x+1",
    "console.log('y:',y) ;",
    "}"
  )
  prettyCode <- prettify_V8(code, "javascript", tabSize = 4)
  expect_equal(
    prettyCode,
    "function f(x) {\n    var y = x + 1;\n    console.log(\"y:\", y);\n}\n"
  )
})

test_that("V8 reindent JavaScript with default `tabSize`", {
  skip_if_not_installed("V8")
  skip_if(substr(V8::engine_info()$version, 1 , 1) < 6, "V8 engine too old.")
  code <- c(
    "function f(x){",
    "var y= x+1",
    "console.log('y:',y) ;",
    "}"
  )
  prettyCode <- reindent_V8(code, "javascript")
  expect_equal(
    prettyCode,
    "function f(x){\r\n  var y= x+1\r\n  console.log('y:',y) ;\r\n}"
  )
})

test_that("V8 reindent JavaScript with given `tabSize`", {
  skip_if_not_installed("V8")
  skip_if(substr(V8::engine_info()$version, 1 , 1) < 6, "V8 engine too old.")
  code <- c(
    "function f(x){",
    "var y= x+1",
    "console.log('y:',y) ;",
    "}"
  )
  prettyCode <- reindent_V8(code, "javascript", tabSize = 4)
  expect_equal(
    prettyCode,
    "function f(x){\r\n    var y= x+1\r\n    console.log('y:',y) ;\r\n}"
  )
})

Try the prettifyAddins package in your browser

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

prettifyAddins documentation built on Sept. 14, 2023, 5:06 p.m.