Merge branch 'master' of git.curoverse.com:arvados into 11876-r-sdk
[arvados.git] / sdk / R / tests / testthat / test-util.R
1 context("Utility function")
2
3 test_that("trimFromStart trims string correctly if string starts with trimCharacters", {
4
5     sample <- "./something/random"
6     trimCharacters <- "./something/"
7
8     result <- trimFromStart(sample, trimCharacters)
9
10     expect_that(result, equals("random"))
11 }) 
12
13 test_that("trimFromStart returns original string if string doesn't starts with trimCharacters", {
14
15     sample <- "./something/random"
16     trimCharacters <- "./nothing/"
17
18     result <- trimFromStart(sample, trimCharacters)
19
20     expect_that(result, equals("./something/random"))
21 }) 
22
23 test_that("trimFromEnd trims string correctly if string ends with trimCharacters", {
24
25     sample <- "./something/random"
26     trimCharacters <- "/random"
27
28     result <- trimFromEnd(sample, trimCharacters)
29
30     expect_that(result, equals("./something"))
31 }) 
32
33 test_that("trimFromEnd returns original string if string doesn't end with trimCharacters", {
34
35     sample <- "./something/random"
36     trimCharacters <- "specific"
37
38     result <- trimFromStart(sample, trimCharacters)
39
40     expect_that(result, equals("./something/random"))
41 }) 
42
43 test_that("RListToPythonList converts nested R list to char representation of Python list", {
44
45     sample <- list("insert", list("random", list("text")), list("here")) 
46
47     result              <- RListToPythonList(sample)
48     resultWithSeparator <- RListToPythonList(sample, separator = ",+")
49
50     expect_that(result, equals("[\"insert\", [\"random\", \"text\"], \"here\"]"))
51     expect_that(resultWithSeparator,
52                 equals("[\"insert\",+[\"random\",+\"text\"],+\"here\"]"))
53 }) 
54
55 test_that("appendToStartIfNotExist appends characters to beginning of a string", {
56
57     sample <- "New Year"
58     charactersToAppend <- "Happy "
59
60     result <- appendToStartIfNotExist(sample, charactersToAppend)
61
62     expect_that(result, equals("Happy New Year"))
63 }) 
64
65 test_that(paste("appendToStartIfNotExist returns original string if string",
66                 "doesn't start with specified characters"), {
67
68     sample <- "Happy New Year"
69     charactersToAppend <- "Happy"
70
71     result <- appendToStartIfNotExist(sample, charactersToAppend)
72
73     expect_that(result, equals("Happy New Year"))
74 }) 
75
76 test_that(paste("splitToPathAndName splits relative path to file/folder",
77                 "name and rest of the path"), {
78
79     relativePath <- "path/to/my/file.exe"
80
81     result <- splitToPathAndName( relativePath)
82
83     expect_that(result$name, equals("file.exe"))
84     expect_that(result$path, equals("path/to/my"))
85 })