Skip to content

Commit

Permalink
Added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Dec 31, 2018
1 parent da154e4 commit 3c05ea8
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Imports:
Suggests:
bibtex,
covr,
rorcid
rorcid,
testthat,
stringr
License: GPL-3
Encoding: UTF-8
BugReports: https://github.com/ropenscilabs/vitae/issues
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(vitae)

test_check("vitae")
7 changes: 7 additions & 0 deletions tests/testthat/setup-data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_entries <- data.frame(
what = c("Award", "Award", "_&*!@#"),
date = c(Sys.Date() - 10, Sys.Date() - 10, Sys.Date()),
with = c("testthat", "testthat", "testthat"),
at = c("Earth", "Earth", "Mars"),
extra = c("first success", "second success", NA)
)
67 changes: 67 additions & 0 deletions tests/testthat/test-entries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
context("test-entries")

test_that("brief_entries", {
entries <- test_entries %>%
brief_entries(what, date, with) %>%
distinct
expect_s3_class(entries, "vitae_brief")
print <- knitr::knit_print(entries)

expect_match(print, "briefsection")
expect_equal(NROW(entries), 2)
expect_equal(stringr::str_count(print, "briefitem"), 2)

expect_equal(stringr::str_count(print, "Award"), 1)
expect_equal(stringr::str_count(print, "testthat"), 2)
expect_match(print, as.character(Sys.Date() - 10))
})

test_that("detailed_entries", {
entries <- test_entries %>%
detailed_entries(what, date, with, at, extra)
expect_s3_class(entries, "vitae_detailed")
print <- knitr::knit_print(entries)

expect_match(print, "detailedsection")
expect_equal(NROW(entries), 2)
expect_equal(stringr::str_count(print, "detaileditem"), 2)

expect_equal(stringr::str_count(print, "\\\\item"), 2)

expect_equal(stringr::str_count(print, "\\\\_\\\\&*"), 1)
expect_equal(stringr::str_count(print, "Mars"), 1)
expect_match(print, as.character(Sys.Date() - 10))

entries <- test_entries %>%
detailed_entries(what, date, with, at, extra, .protect = FALSE)
expect_s3_class(entries, "vitae_detailed")
print <- knitr::knit_print(entries)

expect_match(print, "detailedsection")
expect_equal(NROW(entries), 2)
expect_equal(stringr::str_count(print, "detaileditem"), 2)

expect_equal(stringr::str_count(print, "\\\\item"), 2)

expect_equal(stringr::str_count(print, "\\_\\&*"), 1)
expect_equal(stringr::str_count(print, "Mars"), 1)
expect_match(print, as.character(Sys.Date() - 10))
})



test_that("bibliography_entries", {
tmpbib <- tempfile()
knitr::write_bib(c("vitae", "testthat"), file = tmpbib)

entries <- bibliography_entries(tmpbib)

expect_s3_class(entries, "vitae_bibliography")
print <- knitr::knit_print(entries)

expect_match(print, "defbibheading")
expect_equal(NROW(entries), 2)

expect_match(print, "vitae")
expect_match(print, "testthat")
})

0 comments on commit 3c05ea8

Please sign in to comment.