X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/defe89ef5c3e8995b275120f060cf85296f6396b..32b8eda74f24d1df963a18da5f8023b15d209ca9:/sdk/R/tests/testthat/test-util.R diff --git a/sdk/R/tests/testthat/test-util.R b/sdk/R/tests/testthat/test-util.R index a89786060e..ea091517c6 100644 --- a/sdk/R/tests/testthat/test-util.R +++ b/sdk/R/tests/testthat/test-util.R @@ -1,5 +1,29 @@ context("Utility function") +test_that("listAll always returns all resource items from server", { + + serverResponseLimit <- 3 + itemsAvailable <- 8 + items <- list("collection1", "collection2", "collection3", "collection4", + "collection5", "collection6", "collection7", "collection8") + + testFunction <- function(offset, ...) + { + response <- list() + response$items_available <- itemsAvailable + + maxIndex <- offset + serverResponseLimit + lastElementIndex <- if(maxIndex < itemsAvailable) maxIndex else itemsAvailable + + response$items <- items[(offset + 1):lastElementIndex] + response + } + + result <- listAll(testFunction) + + expect_that(length(result), equals(8)) +}) + test_that("trimFromStart trims string correctly if string starts with trimCharacters", { sample <- "./something/random" @@ -39,3 +63,47 @@ test_that("trimFromEnd returns original string if string doesn't end with trimCh expect_that(result, equals("./something/random")) }) + +test_that("RListToPythonList converts nested R list to char representation of Python list", { + + sample <- list("insert", list("random", list("text")), list("here")) + + result <- RListToPythonList(sample) + resultWithSeparator <- RListToPythonList(sample, separator = ",+") + + expect_that(result, equals("[\"insert\", [\"random\", \"text\"], \"here\"]")) + expect_that(resultWithSeparator, + equals("[\"insert\",+[\"random\",+\"text\"],+\"here\"]")) +}) + +test_that("appendToStartIfNotExist appends characters to beginning of a string", { + + sample <- "New Year" + charactersToAppend <- "Happy " + + result <- appendToStartIfNotExist(sample, charactersToAppend) + + expect_that(result, equals("Happy New Year")) +}) + +test_that(paste("appendToStartIfNotExist returns original string if string", + "doesn't start with specified characters"), { + + sample <- "Happy New Year" + charactersToAppend <- "Happy" + + result <- appendToStartIfNotExist(sample, charactersToAppend) + + expect_that(result, equals("Happy New Year")) +}) + +test_that(paste("splitToPathAndName splits relative path to file/folder", + "name and rest of the path"), { + + relativePath <- "path/to/my/file.exe" + + result <- splitToPathAndName( relativePath) + + expect_that(result$name, equals("file.exe")) + expect_that(result$path, equals("path/to/my")) +})