1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 context("Utility function")
7 test_that("listAll always returns all resource items from server", {
9 serverResponseLimit <- 3
11 items <- list("collection1", "collection2", "collection3", "collection4",
12 "collection5", "collection6", "collection7", "collection8")
14 testFunction <- function(offset, ...)
17 response$items_available <- itemsAvailable
19 maxIndex <- offset + serverResponseLimit
20 lastElementIndex <- if(maxIndex < itemsAvailable) maxIndex else itemsAvailable
22 response$items <- items[(offset + 1):lastElementIndex]
26 result <- listAll(testFunction)
28 expect_that(length(result), equals(8))
31 test_that("trimFromStart trims string correctly if string starts with trimCharacters", {
33 sample <- "./something/random"
34 trimCharacters <- "./something/"
36 result <- trimFromStart(sample, trimCharacters)
38 expect_that(result, equals("random"))
41 test_that("trimFromStart returns original string if string doesn't starts with trimCharacters", {
43 sample <- "./something/random"
44 trimCharacters <- "./nothing/"
46 result <- trimFromStart(sample, trimCharacters)
48 expect_that(result, equals("./something/random"))
51 test_that("trimFromEnd trims string correctly if string ends with trimCharacters", {
53 sample <- "./something/random"
54 trimCharacters <- "/random"
56 result <- trimFromEnd(sample, trimCharacters)
58 expect_that(result, equals("./something"))
61 test_that("trimFromEnd returns original string if string doesn't end with trimCharacters", {
63 sample <- "./something/random"
64 trimCharacters <- "specific"
66 result <- trimFromStart(sample, trimCharacters)
68 expect_that(result, equals("./something/random"))
71 test_that("RListToPythonList converts nested R list to char representation of Python list", {
73 sample <- list("insert", list("random", list("text")), list("here"))
75 result <- RListToPythonList(sample)
76 resultWithSeparator <- RListToPythonList(sample, separator = ",+")
78 expect_that(result, equals("[\"insert\", [\"random\", \"text\"], \"here\"]"))
79 expect_that(resultWithSeparator,
80 equals("[\"insert\",+[\"random\",+\"text\"],+\"here\"]"))
83 test_that("appendToStartIfNotExist appends characters to beginning of a string", {
86 charactersToAppend <- "Happy "
88 result <- appendToStartIfNotExist(sample, charactersToAppend)
90 expect_that(result, equals("Happy New Year"))
93 test_that(paste("appendToStartIfNotExist returns original string if string",
94 "doesn't start with specified characters"), {
96 sample <- "Happy New Year"
97 charactersToAppend <- "Happy"
99 result <- appendToStartIfNotExist(sample, charactersToAppend)
101 expect_that(result, equals("Happy New Year"))
104 test_that(paste("splitToPathAndName splits relative path to file/folder",
105 "name and rest of the path"), {
107 relativePath <- "path/to/my/file.exe"
109 result <- splitToPathAndName( relativePath)
111 expect_that(result$name, equals("file.exe"))
112 expect_that(result$path, equals("path/to/my"))