Skip to content

Commit

Permalink
tests: complete unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jorainer committed Nov 20, 2024
1 parent 40c14e0 commit 8e2433f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions R/functions-mgf.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,16 @@ readMgfSplit <- function(f, msLevel = 2L,
spd$CHARGE <- paste0(abs(spd$CHARGE), sign_char)
spd$CHARGE[nas] <- ""
}
if (!exportTitle)
if (!exportTitle && any(colnames(spd) %in% "TITLE"))
spd$TITLE <- NULL
l <- nrow(spd)
tmp <- lapply(colnames(spd), function(z) {
paste0(z, "=", spd[, z], "\n")
})
if (exportTitle && !any(colnames(spd) == "TITLE")) {
if (exportTitle && !any(colnames(spd) %in% "TITLE")) {
sn <- spectraNames(x)
if (!is.null(sn) && any(sn != as.character(seq_along(x))))
title <- paste0("TITLE=", spectraNames(x), "\n")
if (any(sn != as.character(seq_along(x))))
title <- paste0("TITLE=", sn, "\n")
else
title <- paste0("TITLE=msLevel ", spd$msLevel, "; retentionTime ",
spd$rtime, "; scanNum ", spd$acquisitionNum, "\n")
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test_MsBackendMgf.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ test_that("export,MsBackendMgf works", {
expect_true(length(grep("TITLE", res)) == 0)

spectraNames(sps) <- NULL
sps$TITLE <- NULL
export(MsBackendMgf(), sps, file = fl, exportTitle = TRUE)
res <- readLines(fl)
expect_true(length(grep("TITLE=msLevel", res)) == 0)
expect_true(length(grep("TITLE=msLevel", res)) > 0)

spectraNames(sps) <- paste0("yes", seq_along(sps))
sps$TITLE <- NULL
export(MsBackendMgf(), sps, file = fl, exportTitle = TRUE)
res <- readLines(fl)
expect_true(length(grep("TITLE=yes", res)) == 0)
expect_true(length(grep("TITLE=yes", res)) > 0)

expect_error(export(MsBackendMgf(), file = fl), "missing")
expect_error(export(MsBackendMgf(), x = spd, file = fl), "spectra data to")
Expand Down

0 comments on commit 8e2433f

Please sign in to comment.