File: test-pad.r

package info (click to toggle)
r-cran-stringr 0.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 308 kB
  • sloc: makefile: 3
file content (20 lines) | stat: -rw-r--r-- 597 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
context("Test padding")

test_that("long strings are unchanged", {
  lengths <- sample(40:100, 10)
  strings <- vapply(lengths, function(x)
    str_c(letters[sample(26, x, rep = T)], collapse = ""),
    character(1))

  padded <- str_pad(strings, width = 30)
  expect_that(str_length(padded), equals(str_length(padded)))
})

test_that("directions work for simple case", {

  pad <- function(direction) str_pad("had", direction, width = 10)

  expect_that(pad("right"),  equals("had       "))
  expect_that(pad("left"),   equals("       had"))
  expect_that(pad("both"),   equals("   had    "))
})