Skip to content

Commit

Permalink
fix test (#688)
Browse files Browse the repository at this point in the history
* fix test

* update
  • Loading branch information
mhallal1 authored Jul 8, 2022
1 parent 9cc3b30 commit ff351d9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tests/testthat/test-get_rcode.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
testthat::test_that("get_rcode returns header only for empty chunks", {
ch <- teal.code::chunks_new()

r_code_from_chunks <- get_rcode(chunks = ch)
r_code_from_header <- sprintf("\n\n%s\n", paste(get_rcode_header(), collapse = "\n"))
r_code_from_chunks <- strsplit(get_rcode(chunks = ch), "\n")[[1]]
r_code_from_header <- strsplit(sprintf("\n\n%s\n", paste(get_rcode_header(), collapse = "\n")), "\n")[[1]]

# removing the Date line from the header as the seconds may be different
# in the two strings
testthat::expect_identical(
strsplit(r_code_from_chunks, "\n")[[1]][c(1:5, 7:14)],
strsplit(r_code_from_header, "\n")[[1]][c(1:5, 7:14)]
r_code_from_chunks[c(1:5, 7:length(r_code_from_chunks))],
r_code_from_header[c(1:5, 7:length(r_code_from_header))]
)
})

testthat::test_that("get_rcode returns code from chunks at the end", {
ch <- teal.code::chunks_new()
teal.code::chunks_push(id = "test", chunks = ch, quote(a <- 1))

r_code_from_chunks <- strsplit(get_rcode(chunks = ch), "\n")[[1]]
r_code_from_header <- strsplit(sprintf("\n\n%s\n\na <- 1", paste(get_rcode_header(), collapse = "\n")), "\n")[[1]]

testthat::expect_identical(
get_rcode(chunks = ch),
sprintf("\n\n%s\n\na <- 1", paste(get_rcode_header(), collapse = "\n"))
r_code_from_chunks[c(1:5, 7:length(r_code_from_chunks))],
r_code_from_header[c(1:5, 7:length(r_code_from_header))]
)
})

Expand Down

0 comments on commit ff351d9

Please sign in to comment.