Skip to content

Commit

Permalink
Add tests for raw blob content
Browse files Browse the repository at this point in the history
  • Loading branch information
stewid committed Nov 3, 2023
1 parent 52766eb commit 9e86572
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/blob.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ add(repo, "test.txt")
blob <- lookup(repo, tree(commit(repo, "New commit message"))$id[1])
stopifnot(identical(content(blob),
c("Hello world!", "HELLO WORLD!", "HeLlO wOrLd!")))
stopifnot(identical(rawToChar(content(blob, raw = TRUE)),
content(blob, split = FALSE)))

## Check content of binary file
set.seed(42)
writeBin(as.raw((sample(0:255, 1000, replace = TRUE))),
con = file.path(path, "test.bin"))
x <- as.raw((sample(0:255, 1000, replace = TRUE)))
writeBin(x, con = file.path(path, "test.bin"))
add(repo, "test.bin")
commit(repo, "Add binary file")
blob <- tree(last_commit(repo))["test.bin"]
stopifnot(identical(content(blob), NA_character_))
stopifnot(identical(x, content(blob, raw = TRUE)))

## Hash
stopifnot(identical(hash("Hello, world!\n"),
Expand Down

0 comments on commit 9e86572

Please sign in to comment.