1 context("Utility function")
3 test_that("listAll always returns all resource items from server", {
5 serverResponseLimit <- 3
7 items <- list("collection1", "collection2", "collection3", "collection4",
8 "collection5", "collection6", "collection7", "collection8")
10 testFunction <- function(offset, ...)
13 response$items_available <- itemsAvailable
15 maxIndex <- offset + serverResponseLimit
16 lastElementIndex <- if(maxIndex < itemsAvailable) maxIndex else itemsAvailable
18 response$items <- items[(offset + 1):lastElementIndex]
22 result <- listAll(testFunction)
24 expect_that(length(result), equals(8))
27 test_that("trimFromStart trims string correctly if string starts with trimCharacters", {
29 sample <- "./something/random"
30 trimCharacters <- "./something/"
32 result <- trimFromStart(sample, trimCharacters)
34 expect_that(result, equals("random"))
37 test_that("trimFromStart returns original string if string doesn't starts with trimCharacters", {
39 sample <- "./something/random"
40 trimCharacters <- "./nothing/"
42 result <- trimFromStart(sample, trimCharacters)
44 expect_that(result, equals("./something/random"))
47 test_that("trimFromEnd trims string correctly if string ends with trimCharacters", {
49 sample <- "./something/random"
50 trimCharacters <- "/random"
52 result <- trimFromEnd(sample, trimCharacters)
54 expect_that(result, equals("./something"))
57 test_that("trimFromEnd returns original string if string doesn't end with trimCharacters", {
59 sample <- "./something/random"
60 trimCharacters <- "specific"
62 result <- trimFromStart(sample, trimCharacters)
64 expect_that(result, equals("./something/random"))
67 test_that("RListToPythonList converts nested R list to char representation of Python list", {
69 sample <- list("insert", list("random", list("text")), list("here"))
71 result <- RListToPythonList(sample)
72 resultWithSeparator <- RListToPythonList(sample, separator = ",+")
74 expect_that(result, equals("[\"insert\", [\"random\", \"text\"], \"here\"]"))
75 expect_that(resultWithSeparator,
76 equals("[\"insert\",+[\"random\",+\"text\"],+\"here\"]"))
79 test_that("appendToStartIfNotExist appends characters to beginning of a string", {
82 charactersToAppend <- "Happy "
84 result <- appendToStartIfNotExist(sample, charactersToAppend)
86 expect_that(result, equals("Happy New Year"))
89 test_that(paste("appendToStartIfNotExist returns original string if string",
90 "doesn't start with specified characters"), {
92 sample <- "Happy New Year"
93 charactersToAppend <- "Happy"
95 result <- appendToStartIfNotExist(sample, charactersToAppend)
97 expect_that(result, equals("Happy New Year"))
100 test_that(paste("splitToPathAndName splits relative path to file/folder",
101 "name and rest of the path"), {
103 relativePath <- "path/to/my/file.exe"
105 result <- splitToPathAndName( relativePath)
107 expect_that(result$name, equals("file.exe"))
108 expect_that(result$path, equals("path/to/my"))