1library(pystr)
2context("pystr_center")
3
4test_that("the extra space is put on the right if there's an odd amount of spaces to fill", {
5  original = "hello"
6  centered = pystr_center(original, 10, "*")
7  expect_equal(centered, "**hello***")
8})
9
10test_that("the extra space is distributed evenly if there's an even amount of spaces to fill", {
11  original = "hello"
12  centered = pystr_center(original, 11, "*")
13  expect_equal(centered, "***hello***")
14})
15
16test_that("spaces are used by default", {
17  original = "s"
18  centered = pystr_center(original, 3)
19  expect_equal(centered, " s ")
20})
21
22test_that("the original string is returned if width <= nchar(str)", {
23  original = "hello"
24  centered = pystr_center(original, 3)
25  expect_equal(centered, "hello")
26})
27
28test_that("spaced are maintained in the middle", {
29  original = "hello world"
30  centered = pystr_center(original, 15, "*")
31  expect_equal(centered, "**hello world**")
32})
33
34test_that("it works with character vectors", {
35  original = c("hello", "world")
36  centered = pystr_center(original, 7, "*")
37  expect_equal(centered, c("*hello*", "*world*"))
38})
39
40
41test_that("it works with NAs", {
42  original = c("hello", NA)
43  centered = pystr_center(original, 7, "*")
44  expect_equal(centered, c("*hello*", NA))
45})
46