UNPKG

848 BJavaScriptView Raw
1const assert = require('assert')
2
3const {
4 DEFAULT_ALGORITHM,
5 SHA1,
6 checksum,
7 checksumFilePath,
8 hashFromFileContent,
9} = require('./checksum')
10
11// NOTE: Using `echo -n <string> | sha1sum` to generate expected result
12assert(checksum('', SHA1) === 'da39a3ee5e6b4b0d3255bfef95601890afd80709')
13assert(checksum('42', SHA1) === '92cfceb39d57d914ed8b14d0e37643de0797ae56')
14assert(checksum('abc', SHA1) === 'a9993e364706816aba3e25717850c26c9cd0d89d')
15
16assert(DEFAULT_ALGORITHM === SHA1)
17assert(checksum('foo') === checksum('foo', SHA1))
18
19assert(hashFromFileContent('1234 x.txt') === '1234')
20assert(hashFromFileContent(' 1234 x.txt ') === '1234')
21
22assert(checksumFilePath('./test.txt') === '.test.txt.sha')
23assert(checksumFilePath('../test.txt') === '../.test.txt.sha')
24
25// TODO:
26// assert(checksumFilePath('.test.txt') === '.test.txt.sha')