[Pkg-javascript-commits] [node-sha.js] 202/237: tests: adhere to standard

Bastien Roucariès rouca at moszumanska.debian.org
Fri May 5 09:04:00 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 e6851ca9bb0843fa90d8eee7d3f7b3f9d1bbe4fb
Author: Daniel Cousens <github at dcousens.com>
Date:   Sat May 30 13:33:59 2015 +1000

    tests: adhere to standard
---
 test/hash.js | 79 +++++++++++++++++++++++++++---------------------------------
 test/test.js | 41 +++++++++++++++----------------
 2 files changed, 54 insertions(+), 66 deletions(-)

diff --git a/test/hash.js b/test/hash.js
index 6a369cd..2f376b4 100644
--- a/test/hash.js
+++ b/test/hash.js
@@ -1,79 +1,72 @@
-var hexpp = require('../hexpp').defaults({bigendian: false})
+var hexpp = require('../hexpp').defaults({ bigendian: false })
 var tape = require('tape')
 var Hash = require('../hash')
 
-var hex = '0A1B2C3D4E5F6G7H', hexbuf
-function equal(t, a, b) {
+var hex = '0A1B2C3D4E5F6G7H'
+
+function equal (t, a, b) {
   t.equal(a.length, b.length)
-  for(var i = 0; i < a.length; i++)
+
+  for (var i = 0; i < a.length; i++) {
     t.equal(a[i], b[i])
+  }
 }
 
+var hexBuf = new Buffer([48, 65, 49, 66, 50, 67, 51, 68, 52, 69, 53, 70, 54, 71, 55, 72])
 var count16 = {
-      strings: ['0A1B2C3D4E5F6G7H'],
-      buffers: [
-        hexbuf = new Buffer([
-          48, 65, 49, 66,   50, 67, 51, 68,
-          52, 69, 53, 70,   54, 71, 55, 72
-        ]),
-        new Buffer([
-         128,  0,  0,  0,    0,  0,  0,  0,
-           0,  0,  0,  0,    0,  0,  0, 128
-        ])
-      ]
-    }
+  strings: ['0A1B2C3D4E5F6G7H'],
+  buffers: [
+    hexBuf,
+    new Buffer([ 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128])
+  ]
+}
+
 var empty = {
-      strings: [''],
-      buffers: [
-        new Buffer([
-         128,  0,  0,  0,    0,  0,  0,  0,
-           0,  0,  0,  0,    0,  0,  0,  0
-        ])
-      ]
-    }
-var hh = 'abcdefhijklmnopq'
+  strings: [''],
+  buffers: [
+    new Buffer([ 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ])
+  ]
+}
 
 var multi = {
       strings: ['abcd', 'efhijk', 'lmnopq'],
       buffers: [
         new Buffer('abcdefhijklmnopq', 'ascii'),
-        new Buffer([
-         128,  0,  0,  0,    0,  0,  0,  0,
-           0,  0,  0,  0,    0,  0,  0,  128
-        ])
+        new Buffer([128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128])
       ]
     }
 
 var long = {
-      strings: [hex+hex],
-      buffers: [
-        hexbuf,
-        hexbuf,
-        new Buffer([
-         128,  0,  0,  0,    0,  0,  0,  0,
-           0,  0,  0,  0,    0,  0,  1,  0
-        ])
-      ]
-    }
+  strings: [hex + hex],
+  buffers: [
+    hexBuf,
+    hexBuf,
+    new Buffer([128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0])
+  ]
+}
 
-function makeTest(name, data) {
+function makeTest (name, data) {
   tape(name, function (t) {
 
     var h = new Hash(16, 8)
     var hash = new Buffer(20)
     var n = 2
     var expected = data.buffers.slice()
-    //t.plan(expected.length + 1)
+    // t.plan(expected.length + 1)
+
     h._update = function (block) {
       var e = expected.shift()
+
       console.log('---block---')
       console.log(hexpp(block), block.length)
       console.log('---e---')
       console.log(hexpp(e), block.length)
       console.log(block)
       equal(t, block, e)
-      if(n < 0)
+
+      if (n < 0) {
         throw new Error('expecting only 2 calls to _update')
+      }
 
       return hash
     }
@@ -84,7 +77,6 @@ function makeTest(name, data) {
 
     equal(t, h.digest(), hash)
     t.end()
-
   })
 }
 
@@ -92,4 +84,3 @@ makeTest('Hash#update 1 in 1', count16)
 makeTest('empty Hash#update', empty)
 makeTest('Hash#update 1 in 3', multi)
 makeTest('Hash#update 2 in 1', long)
-
diff --git a/test/test.js b/test/test.js
index 15ad98d..0a46e44 100644
--- a/test/test.js
+++ b/test/test.js
@@ -3,19 +3,18 @@ var tape = require('tape')
 var Sha1 = require('../').sha1
 
 var inputs = [
- ['', 'ascii'],
- ['abc', 'ascii'],
- ['123', 'ascii'],
- ['123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 'ascii'],
- ['123456789abcdef123456789abcdef123456789abcdef123456789abc', 'ascii'],
- ['123456789abcdef123456789abcdef123456789abcdef123456789ab', 'ascii'],
- ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde', 'ascii'],
- ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', 'ascii'],
- ['foobarbaz', 'ascii']
+  ['', 'ascii'],
+  ['abc', 'ascii'],
+  ['123', 'ascii'],
+  ['123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 'ascii'],
+  ['123456789abcdef123456789abcdef123456789abcdef123456789abc', 'ascii'],
+  ['123456789abcdef123456789abcdef123456789abcdef123456789ab', 'ascii'],
+  ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde', 'ascii'],
+  ['0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef', 'ascii'],
+  ['foobarbaz', 'ascii']
 ]
 
 tape("hash is the same as node's crypto", function (t) {
-
   inputs.forEach(function (v) {
     var a = new Sha1().update(v[0], v[1]).digest('hex')
     var e = crypto.createHash('sha1').update(v[0], v[1]).digest('hex')
@@ -24,19 +23,19 @@ tape("hash is the same as node's crypto", function (t) {
   })
 
   t.end()
-
 })
 
 tape('call update multiple times', function (t) {
-  var n = 1
   inputs.forEach(function (v) {
     var hash = new Sha1()
     var _hash = crypto.createHash('sha1')
-    for(var i = 0; i < v[0].length; i=(i+1)*2) {
-      var s = v[0].substring(i, (i+1)*2)
+
+    for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
+      var s = v[0].substring(i, (i + 1) * 2)
       hash.update(s, v[1])
       _hash.update(s, v[1])
     }
+
     var a = hash.digest('hex')
     var e = _hash.digest('hex')
     console.log(a, '==', e)
@@ -45,11 +44,9 @@ tape('call update multiple times', function (t) {
   t.end()
 })
 
-
 tape('call update twice', function (t) {
-
   var _hash = crypto.createHash('sha1')
-  var hash  = new Sha1()
+  var hash = new Sha1()
 
   _hash.update('foo', 'ascii')
   hash.update('foo', 'ascii')
@@ -67,22 +64,22 @@ tape('call update twice', function (t) {
   t.end()
 })
 
-
 tape('hex encoding', function (t) {
-  var n = 1
   inputs.forEach(function (v) {
     var hash = new Sha1()
     var _hash = crypto.createHash('sha1')
-    for(var i = 0; i < v[0].length; i=(i+1)*2) {
-      var s = v[0].substring(i, (i+1)*2)
+
+    for (var i = 0; i < v[0].length; i = (i + 1) * 2) {
+      var s = v[0].substring(i, (i + 1) * 2)
       hash.update(new Buffer(s, 'ascii').toString('hex'), 'hex')
       _hash.update(new Buffer(s, 'ascii').toString('hex'), 'hex')
     }
     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