Added two utility functions and created unit test for them.
[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 })