diff --git a/tests/testthat/test_extract_text.R b/tests/testthat/test_extract_text.R index 114e3da..e3dd306 100644 --- a/tests/testthat/test_extract_text.R +++ b/tests/testthat/test_extract_text.R @@ -4,22 +4,30 @@ sf <- system.file("examples", "text.pdf", package = "tabulapdf") test_that("Text can be extracted from the whole document", { txt <- extract_text(sf, encoding = "UTF-8") - expect_identical(txt, "42 is the number from which the meaning of life, the universe, and everything can be derived.\n42 is the number from which the meaning of life, the universe, and everything can be derived.\n") + txt <- gsub("[\r\n]", " ", txt) + txt <- gsub("\\s$", "", txt) + expect_identical(txt, "42 is the number from which the meaning of life, the universe, and everything can be derived. 42 is the number from which the meaning of life, the universe, and everything can be derived.") }) test_that("'page' argument in extract_text works", { txt <- extract_text(sf, pages = 1, encoding = "UTF-8") - expect_identical(txt, "42 is the number from which the meaning of life, the universe, and everything can be derived.\n") + txt <- gsub("[\r\n]", " ", txt) + txt <- gsub("\\s$", "", txt) + expect_identical(txt, "42 is the number from which the meaning of life, the universe, and everything can be derived.") }) test_that("'area' argument in extract_text works", { txt <- extract_text(sf, area = list(c(10, 15, 100, 550)), encoding = "UTF-8") - expect_identical(txt[1], "42 is the number from which the meaning of life, the universe, and everything can be derived.\n") + txt <- gsub("[\r\n]", " ", txt) + txt <- gsub("\\s$", "", txt) + expect_identical(txt[1], "42 is the number from which the meaning of life, the universe, and everything can be derived.") }) test_that("'area' and 'page' arguments in extract_text work together", { txt <- extract_text(sf, pages = 1, area = list(c(10, 15, 100, 550)), encoding = "UTF-8") - expect_identical(txt, "42 is the number from which the meaning of life, the universe, and everything can be derived.\n") + txt <- gsub("[\r\n]", " ", txt) + txt <- gsub("\\s$", "", txt) + expect_identical(txt, "42 is the number from which the meaning of life, the universe, and everything can be derived.") }) test_that("Multiple pages with different areas can be extracted", { @@ -30,11 +38,14 @@ test_that("Multiple pages with different areas can be extracted", { c(10, 15, 100, 500) ), encoding = "UTF-8" ) + txt <- gsub("[\r\n]", " ", txt) + txt <- gsub("\\s$", "", txt) + expect_identical( txt, c( - "42 is the number from which the meaning of life, the universe, and everything can be derived.\n", - "42 is the number from which the meaning of life, the universe, and everything can be deriv\n" + "42 is the number from which the meaning of life, the universe, and everything can be derived.", + "42 is the number from which the meaning of life, the universe, and everything can be deriv" ) ) })