Skip to content

Commit

Permalink
Write references before resetting bib data (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgallou authored Oct 22, 2024
1 parent 5a78054 commit 9698c08
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# pakret (development version)

* pakret can now write references in multiple `.bib` files within the same document (#26).

* Fixed an issue with `pkrt_set(bib =)` that may lead to the replication or deletion of some bib entries in the newly defined `.bib` file in some edge cases (#22).

# pakret 0.2.1
Expand Down
1 change: 1 addition & 0 deletions R/pkrt-set.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ reset <- function(x) {
update <- function(x) {
do.call(set, as.list(x))
if (is_updating_bib(x)) {
bib_write()
bib_set()
}
}
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-pkrt-set.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ test_that("writing bib entries in the desired file works", {
expect_length(extract(res, "(?m)^@"), 2L)
})

test_that("writing bib entries in multiple file works", {
skip_on_os("windows")
template <- make_template(lines = dedent("
```{r}
pkrt_set(bib = 2L)
pkrt('bar')
pkrt_set(bib = NULL)
pkrt('foo')
```
"))
dir <- local_files(template, bib = local_set(n = 2L))

res <- read_local_file(dir, target = "file_1.bib")
expect_match(res, "^@Manual\\{foo,")
expect_length(extract(res, "(?m)^@"), 1L)

res <- read_local_file(dir, target = "file_2.bib")
expect_match(res, "^@Manual\\{bar,")
expect_length(extract(res, "(?m)^@"), 1L)
})

# errors

test_that("pkrt_set() gives meaningful error messages", {
Expand Down

0 comments on commit 9698c08

Please sign in to comment.