Skip to content

Commit

Permalink
test: added tests for file_mod functions
Browse files Browse the repository at this point in the history
  • Loading branch information
brycefrank committed Sep 27, 2024
1 parent f4bf47f commit 31b7e4a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 6 additions & 2 deletions R/file_mod.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ parse_parameter_names <- function(filenames) {

if(nrow(matches) == 0) {
return(NULL)
} else if(length(filenames) == 1 && filenames[[1]] == "") {
return(NULL)
} else {
return(unique(paste0(matches[,2], "_", matches[,3])))
}
Expand All @@ -16,8 +18,10 @@ parse_parameter_names <- function(filenames) {
#' Get publication IDs modified since a specified commit
#'
#' @param last_commit The commit ID to check to
get_modified_files <- function(last_commit) {
sys_string <- paste0("git diff --name-only ", last_commit, " HEAD")
get_modified_files <- function(last_commit, end_commit = "HEAD") {
end_commit <- paste0(" ", end_commit)

sys_string <- paste0("git diff --name-only ", last_commit, end_commit)
files <- system(sys_string, intern = TRUE)

modified_via_params <- files[startsWith(files, "parameters")] |>
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-file-mod.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test_that("parse_parameter_names returns correct pub ID", {
expect_equal(parse_parameter_names("kozak_1988.csv"), "kozak_1988")

empty_parse <- parse_parameter_names("")
expect_true(is.null(empty_parse))
})

test_that("get_modified_files returns valid pub IDs", {
check <- get_modified_files("32006ca", "018e79d")

expect_equal(check, "sharma_2015")
})
2 changes: 1 addition & 1 deletion tests/testthat/test-publication-processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ test_that("get_current_pub_ids_params returns valid publication ids", {

# All pub_ids contain only characters before the year
all(grepl("^[a-zA-Z]+_\\d{4}[a-zA-Z]?$", current_pub_ids))
})
})

0 comments on commit 31b7e4a

Please sign in to comment.