File: test_hash_multihash.R

package info (click to toggle)
r-cran-openssl 2.0.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,312 kB
  • sloc: ansic: 3,074; sh: 20; makefile: 5
file content (35 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
context("Multihash")

test_that("Multihash for connections or raw vectors", {
  desc <- system.file('DESCRIPTION')
  buf <- readBin(desc, raw(), 1e5)
  algos <- c("sha1", "sha256", "sha512")
  out1 <- multihash(buf, algos = algos)
  out2 <- multihash(file(desc), algos = algos)
  expect_identical(out1, out2)
  expect_named(out1, algos)
  expect_equal(out1$sha1, sha1(file(desc)))
  expect_equal(out1$sha256, sha256(file(desc)))
  expect_equal(out1$sha512, sha512(file(desc)))
})

test_that("Multihash for text vectors", {
  algos <- c("sha1", "sha256", "sha512")
  out0 <- multihash(character(), algos = algos)
  expect_is(out0, 'data.frame')
  expect_named(out0, algos)
  expect_equal(nrow(out0), 0)

  out1 <- multihash("foo", algos = algos)
  expect_is(out1, 'data.frame')
  expect_named(out1, algos)
  expect_equal(nrow(out1), 1)

  out2 <- multihash(c("foo", "bar"), algos = algos)
  expect_is(out2, 'data.frame')
  expect_named(out2, algos)
  expect_equal(nrow(out2), 2)

  expect_equal(out2[1,], out1)

})