Skip to content

Commit

Permalink
Add tests for multiple rows input in row_to_names()
Browse files Browse the repository at this point in the history
  • Loading branch information
matanhakim committed May 19, 2023
1 parent 7df603c commit 44c018f
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/testthat/test-row-to-names.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,37 @@ test_that("row_to_names invalid and semi-valid input checking", {
regexp="Extra arguments (...) may only be given if row_number = 'find_header'.",
fixed=TRUE
)

expect_error(
row_to_names(
example_data_row_to_names[[1]],
row_number=1, remove_row=TRUE, remove_rows_above=TRUE,
sep=8
),
regexp="`sep` must be of type `character`.",
fixed=TRUE
)

expect_error(
row_to_names(
example_data_row_to_names[[1]],
row_number=1, remove_row=TRUE, remove_rows_above=TRUE,
sep=c("_", "-")
),
regexp="`sep` must be of length 1.",
fixed=TRUE
)

expect_error(
row_to_names(
example_data_row_to_names[[1]],
row_number=1, remove_row=TRUE, remove_rows_above=TRUE,
sep=NA_character_
),
regexp="`sep` can't be of type `NA_character_`.",
fixed=TRUE
)

})

test_that("row_to_names works on factor columns", {
Expand Down Expand Up @@ -217,3 +248,34 @@ test_that("find_header works within row_to_names", {
setNames(find_correct[4:nrow(find_correct),], c("D", "E"))
)
})

test_that("multiple rows input works", {
q_row_to_names <- purrr::quietly(row_to_names)

expect_equal(
q_row_to_names(example_data_row_to_names[[1]], row_number=1) %>%
purrr::pluck("result") %>%
names(),
c("NA", "NA")
)

expect_equal(
q_row_to_names(example_data_row_to_names[[1]], row_number=c(1,1)) %>%
purrr::pluck("result") %>%
names(),
c("NA", "NA")
)

expect_equal(
row_to_names(example_data_row_to_names[[1]], row_number=1:2) %>%
names(),
c("Title", "Title2")
)

expect_equal(
row_to_names(example_data_row_to_names[[1]], row_number=1:5) %>%
names(),
c("Title_1_2_3", "Title2_4_5_6")
)

})

0 comments on commit 44c018f

Please sign in to comment.