basic.js 684 B

123456789101112131415161718192021222324
  1. var test = require('tap').test
  2. var sigmund = require('../sigmund.js')
  3. // occasionally there are duplicates
  4. // that's an acceptable edge-case. JSON.stringify and util.inspect
  5. // have some collision potential as well, though less, and collision
  6. // detection is expensive.
  7. var hash = '{abc/def/g{0h1i2{jkl'
  8. var obj1 = {a:'b',c:/def/,g:['h','i',{j:'',k:'l'}]}
  9. var obj2 = {a:'b',c:'/def/',g:['h','i','{jkl']}
  10. var obj3 = JSON.parse(JSON.stringify(obj1))
  11. obj3.c = /def/
  12. obj3.g[2].cycle = obj3
  13. var cycleHash = '{abc/def/g{0h1i2{jklcycle'
  14. test('basic', function (t) {
  15. t.equal(sigmund(obj1), hash)
  16. t.equal(sigmund(obj2), hash)
  17. t.equal(sigmund(obj3), cycleHash)
  18. t.end()
  19. })