[Pkg-javascript-commits] [node-sha.js] 16/237: more tests

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:02:51 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-sha.js.

commit 655a7be9914298ad63ea77ba4c85dc34ed5f7f9b
Author: Dominic Tarr <dominic.tarr at gmail.com>
Date:   Thu Dec 26 22:32:13 2013 +0700

    more tests
---
 test/hash.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------
 test/test.js | 22 ++++++++++++++++++++++
 2 files changed, 74 insertions(+), 8 deletions(-)

diff --git a/test/hash.js b/test/hash.js
index 00d7d69..ad1aa98 100644
--- a/test/hash.js
+++ b/test/hash.js
@@ -1,15 +1,53 @@
 
 var Hash = require('../hash')
-
+var hexpp = require('../hexpp').defaults({bigendian: true})
 var tape = require('tape')
+var hex = '0A1B2C3D4E5F6G7H'
+
+var u = require('../util')
+
+function toBuffers (string, length) {
+  var a = []
+  for(var i = 0; i < string.length / length; i ++) {
+    a[i] = new Uint8Array(length)
+    u.write(a[i], string, 'ascii', 0, i*length, Math.min((i+1)*length, string.length))
+  }
+  return a
+}
+
+tape('Hash#update 1 in 1 messages', function (t) {
+
+  var h = new Hash(16, 12)
+  var n = 1
+  t.plan(2)
+  h._update = function (block) {
+    console.log('---WRITTEN---')
+    console.log(hexpp(this._block))
+    t.deepEqual(block, toBuffers(hex, 16)[0].buffer)
+    if(n < 0)
+      throw new Error('expecting only 2 calls to _update')
+  }
+
+  h._final = function (block) {
+    t.equal(--n, 0)
+    console.log('final', block)
+    return new Uint8Array(20)
+  }
+
+  h.update(hex)
+  h.digest()
+  t.end()
+
+})
 
 tape('Hash#update 2 in 1 messages', function (t) {
 
-  var h = new Hash(16)
+  var h = new Hash(16, 12)
   var n = 3
   t.plan(3)
   h._update = function (block) {
-    console.log(block)
+    console.log('---WRITTEN---')
+    console.log(hexpp(this._block))
     t.ok(--n)
     if(n < 0)
       throw new Error('expecting only 2 calls to _update')
@@ -21,20 +59,26 @@ tape('Hash#update 2 in 1 messages', function (t) {
     return new Uint8Array(20)
   }
 
-  h.update('0123456789abcdef0123456789abcdef')
+  h.update(hex+hex)
   var hash = h.digest()
   console.log(hash)
 
   t.end()
 })
 
-tape('Hash#update 2 in 3 messages', function (t) {
+tape('Hash#update 1 in 3 messages', function (t) {
 
   var h = new Hash(16)
-  var n = 3
+  var n = 2
   t.plan(3)
+  var hh = hex+hex
+  var hh = 'abcdefhijklmnopq'
+  var expected = toBuffers(hh, 16)
+  console.log('expected')
   h._update = function (block) {
-    console.log(block)
+    console.log('---WRITTEN---')
+    console.log(hexpp(this._block))
+    t.deepEqual(block, expected.shift().buffer)
     t.ok(--n)
     if(n < 0)
       throw new Error('expecting only 2 calls to _update')
@@ -46,7 +90,7 @@ tape('Hash#update 2 in 3 messages', function (t) {
     return new Uint8Array(20)
   }
 
-  h.update('0123').update('456789abc').update('def0123456789abcdef')
+  h.update(hh.substring(0, 4)).update(hh.substring(4, 10)).update(hh.substring(10, 16))
   var hash = h.digest()
   console.log(hash)
 
diff --git a/test/test.js b/test/test.js
index 7e80b93..199add4 100644
--- a/test/test.js
+++ b/test/test.js
@@ -80,3 +80,25 @@ tape('call update twice', function (t) {
   t.equal(a, e)
   t.end()
 })
+
+//to test what happens when updated data overlaps edge of
+//working buffer...
+//tape('append message 5 times', function (t) {
+//  var n = 1
+//  //inputs.forEach(function (v) {
+//    var v = inputs[4]
+//    console.log('HASH', v, v[0].length)
+//    var hash = new Sha1()
+//    var _hash = crypto.createHash('sha1')
+//    for(var i = 0; i < 5; i++) {
+//      hash.update(v[0], v[1])
+//      _hash.update(v[0], v[1])
+//    }
+//    var a = hash.digest('hex')
+//    var e = _hash.digest('hex')
+//    console.log(a, e)
+//    t.equal(a, e)
+//  //})
+//  t.end()
+//})
+//

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-sha.js.git



More information about the Pkg-javascript-commits mailing list