index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var tape = require('tape')
  2. var Buffer = require('safe-buffer').Buffer
  3. var shasum = require('..')
  4. tape('strings', function (t) {
  5. t.plan(3)
  6. t.strictEqual(shasum('abc'), 'a9993e364706816aba3e25717850c26c9cd0d89d')
  7. t.strictEqual(shasum('abce'), '0a431a7631cabf6b11b984a943127b5e0aa9d687')
  8. t.strictEqual(shasum('ab\xff'), 'ba5142a8207bd61baddf325088732e71cbfe8eb6')
  9. })
  10. tape('json values', function (t) {
  11. t.plan(2)
  12. t.strictEqual(shasum({}), 'bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f')
  13. t.strictEqual(shasum([]), '97d170e1550eee4afc0af065b78cda302a97674c')
  14. })
  15. tape('buffers', function (t) {
  16. t.plan(2)
  17. t.strictEqual(shasum(Buffer.from('abc')),
  18. 'a9993e364706816aba3e25717850c26c9cd0d89d')
  19. t.strictEqual(shasum(Buffer.from('ab\xff').toString()),
  20. 'ba5142a8207bd61baddf325088732e71cbfe8eb6')
  21. })
  22. tape('circular json', function (t) {
  23. t.plan(1)
  24. var a = { b: 1 }
  25. a.a = a
  26. t.strictEqual(shasum(a), 'a22ca7ba0fe6144501fe50d9c8a9ba889057db3b')
  27. })
  28. tape('stability', function (t) {
  29. t.plan(4)
  30. t.strictEqual(shasum({ a: 1, b: 2, c: 3 }), shasum({ c: 3, b: 2, a: 1 }))
  31. t.strictEqual(shasum({ a: 1, b: 2, c: 3 }), shasum({ c: 3, b: 2, a: 1 }))
  32. t.strictEqual(shasum({ a: 1, b: [2, 3], c: 4 }), shasum({ c: 4, b: [2, 3], a: 1 }))
  33. t.strictEqual(shasum({ a: 1, b: [2, { c: 3, d: 4 }], e: 5 }), shasum({ e: 5, b: [2, { d: 4, c: 3 }], a: 1 }))
  34. })