1library(pystr) 2context("pystr_splitlines") 3 4test_that("it splits correctly when \r\n is first", { 5 expected = c("First", "Second", "Third") 6 expect_equal(pystr_splitlines("First\r\nSecond\rThird")[[1]], expected) 7}) 8 9test_that("it splits correctly when \r\n is second", { 10 expected = c("First", "Second", "Third") 11 expect_equal(pystr_splitlines("First\nSecond\r\nThird")[[1]], expected) 12}) 13 14test_that("it splits correctly when \r\n is last", { 15 expected = c("First", "Second", "Third") 16 expect_equal(pystr_splitlines("First\nSecond\nThird\r\n")[[1]], expected) 17}) 18 19test_that("it keeps the ends correctly when \r\n is first", { 20 expected = c("First\r\n", "Second\r", "Third") 21 expect_equal(pystr_splitlines("First\r\nSecond\rThird", TRUE)[[1]], expected) 22}) 23 24test_that("it keepds the ends correctly when \r\n is second", { 25 expected = c("First\n", "Second\r\n", "Third") 26 expect_equal(pystr_splitlines("First\nSecond\r\nThird", TRUE)[[1]], expected) 27}) 28 29test_that("it keeps the ends correctly when \r\n is last", { 30 expected = c("First\n", "Second\n", "Third\r\n") 31 expect_equal(pystr_splitlines("First\nSecond\nThird\r\n", TRUE)[[1]], expected) 32}) 33 34test_that("it returns the string itself if there are no linebreaks", { 35 expect_equal(pystr_splitlines("fdsa")[[1]], "fdsa") 36}) 37 38test_that("it returns a list of character vectors", { 39 input = c("A\rB\rC", "B\rC", "C") 40 output = list(c("A", "B", "C"), c("B", "C"), "C") 41 expect_equal(pystr_splitlines(input), output) 42}) 43