Skip to content

Commit

Permalink
adapt line ending for windows testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Apr 29, 2024
1 parent 4ea1bfb commit 63008f9
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions tests/testthat/test_extract_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -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"
)
)
})
Expand Down

0 comments on commit 63008f9

Please sign in to comment.