react / wstein / node_modules / browserify / node_modules / shasum / node_modules / sha.js / test / hash.js
80540 viewsvar hexpp = require('../hexpp').defaults({bigendian: false})1var tape = require('tape')2var Hash = require('../hash')34var hex = '0A1B2C3D4E5F6G7H', hexbuf5function equal(t, a, b) {6t.equal(a.length, b.length)7for(var i = 0; i < a.length; i++)8t.equal(a[i], b[i])9}1011var count16 = {12strings: ['0A1B2C3D4E5F6G7H'],13buffers: [14hexbuf = new Buffer([1548, 65, 49, 66, 50, 67, 51, 68,1652, 69, 53, 70, 54, 71, 55, 7217]),18new Buffer([19128, 0, 0, 0, 0, 0, 0, 0,200, 0, 0, 0, 0, 0, 0, 12821])22]23}24var empty = {25strings: [''],26buffers: [27new Buffer([28128, 0, 0, 0, 0, 0, 0, 0,290, 0, 0, 0, 0, 0, 0, 030])31]32}33var hh = 'abcdefhijklmnopq'3435var multi = {36strings: ['abcd', 'efhijk', 'lmnopq'],37buffers: [38new Buffer('abcdefhijklmnopq', 'ascii'),39new Buffer([40128, 0, 0, 0, 0, 0, 0, 0,410, 0, 0, 0, 0, 0, 0, 12842])43]44}4546var long = {47strings: [hex+hex],48buffers: [49hexbuf,50hexbuf,51new Buffer([52128, 0, 0, 0, 0, 0, 0, 0,530, 0, 0, 0, 0, 0, 1, 054])55]56}5758function makeTest(name, data) {59tape(name, function (t) {6061var h = new Hash(16, 8)62var hash = new Buffer(20)63var n = 264var expected = data.buffers.slice()65//t.plan(expected.length + 1)66h._update = function (block) {67var e = expected.shift()68console.log('---block---')69console.log(hexpp(block), block.length)70console.log('---e---')71console.log(hexpp(e), block.length)72console.log(block)73equal(t, block, e)74if(n < 0)75throw new Error('expecting only 2 calls to _update')7677return hash78}7980data.strings.forEach(function (string) {81h.update(string, 'ascii')82})8384equal(t, h.digest(), hash)85t.end()8687})88}8990makeTest('Hash#update 1 in 1', count16)91makeTest('empty Hash#update', empty)92makeTest('Hash#update 1 in 3', multi)93makeTest('Hash#update 2 in 1', long)94959697