tests/testthat/test_RCodeParse.R

# ---------------------------------------------------------------
#
#    Author     : [Damian]
#
#    Date       : 2018-01-04 22:43:26
#
#    Description: Tests for function from script RCodeParsing.R
#
# ---------------------------------------------------------------


testthat::context("R Code Parsing")

testthat::test_that("removeSpaces func", {
    testthat::expect_error(removeSpaces(1:100))
    testthat::expect_error(removeSpaces(function(...){}))
    testthat::expect_error(removeSpaces(.GlobalEnv))

    testthat::expect_equal(removeSpaces("x   y"), c("x", "y"))
    testthat::expect_equal(removeSpaces("f <- function()"), c("f", "<-", "function()"))

    tstString <- c(paste(c("Hi", paste0(rep(" ", 1000)), "there"), collapse = ""))
    testthat::expect_equal(removeSpaces(tstString), c("Hi", "there"))
    testthat::expect_equal(removeSpaces("oRtrack"), "oRtrack")
})


testthat::test_that("isFuncDEclaration func", {
    testthat::expect_error(isFunDeclaration(1:100))
    testthat::expect_error(isFunDeclaration())
    testthat::expect_error(isFunDeclaration(.GlobalEnv))

    testthat::expect_true(isFunDeclaration("x = function(arg){"))
    testthat::expect_true(isFunDeclaration("z <-  function   (...){return(NA)}"))
    testthat::expect_true(isFunDeclaration("function ()"))
    testthat::expect_true(isFunDeclaration("<-function"))
    testthat::expect_true(isFunDeclaration("<-   function  (...) {}"))
    testthat::expect_true(isFunDeclaration("<-function"))
    testthat::expect_true(isFunDeclaration("<-function(arg)"))
    testthat::expect_true(isFunDeclaration("=function(...)"))

    testthat::expect_false(isFunDeclaration("FUNCTION(arg, ...)"))
    testthat::expect_false(isFunDeclaration("random"))
})
DSkrzypiec/oRtrack documentation built on May 23, 2019, 7:32 a.m.