1 context("Utility function")
3 test_that("trimFromStart trims string correctly if string starts with trimCharacters", {
5 sample <- "./something/random"
6 trimCharacters <- "./something/"
8 result <- trimFromStart(sample, trimCharacters)
10 expect_that(result, equals("random"))
13 test_that("trimFromStart returns original string if string doesn't starts with trimCharacters", {
15 sample <- "./something/random"
16 trimCharacters <- "./nothing/"
18 result <- trimFromStart(sample, trimCharacters)
20 expect_that(result, equals("./something/random"))
23 test_that("trimFromEnd trims string correctly if string ends with trimCharacters", {
25 sample <- "./something/random"
26 trimCharacters <- "/random"
28 result <- trimFromEnd(sample, trimCharacters)
30 expect_that(result, equals("./something"))
33 test_that("trimFromEnd returns original string if string doesn't end with trimCharacters", {
35 sample <- "./something/random"
36 trimCharacters <- "specific"
38 result <- trimFromStart(sample, trimCharacters)
40 expect_that(result, equals("./something/random"))
43 test_that("RListToPythonList converts nested R list to char representation of Python list", {
45 sample <- list("insert", list("random", list("text")), list("here"))
47 result <- RListToPythonList(sample)
48 resultWithSeparator <- RListToPythonList(sample, separator = ",+")
50 expect_that(result, equals("[\"insert\", [\"random\", \"text\"], \"here\"]"))
51 expect_that(resultWithSeparator,
52 equals("[\"insert\",+[\"random\",+\"text\"],+\"here\"]"))
55 test_that("appendToStartIfNotExist appends characters to beginning of a string", {
58 charactersToAppend <- "Happy "
60 result <- appendToStartIfNotExist(sample, charactersToAppend)
62 expect_that(result, equals("Happy New Year"))
65 test_that(paste("appendToStartIfNotExist returns original string if string",
66 "doesn't start with specified characters"), {
68 sample <- "Happy New Year"
69 charactersToAppend <- "Happy"
71 result <- appendToStartIfNotExist(sample, charactersToAppend)
73 expect_that(result, equals("Happy New Year"))
76 test_that(paste("splitToPathAndName splits relative path to file/folder",
77 "name and rest of the path"), {
79 relativePath <- "path/to/my/file.exe"
81 result <- splitToPathAndName( relativePath)
83 expect_that(result$name, equals("file.exe"))
84 expect_that(result$path, equals("path/to/my"))