[Pkg-javascript-commits] [node-sha.js] 09/31: tests: compare hex, not byte-by-byte (easier debugging)
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Nov 30 11:23:25 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 5d5a8d882b614060b774e195821a43051f3345b7
Author: Daniel Cousens <github at dcousens.com>
Date: Fri May 19 22:13:34 2017 +1000
tests: compare hex, not byte-by-byte (easier debugging)
---
hexpp.js | 26 --------------------------
test/hash.js | 22 ++++++----------------
test/vectors.js | 2 --
3 files changed, 6 insertions(+), 44 deletions(-)
diff --git a/hexpp.js b/hexpp.js
deleted file mode 100644
index 4f1e921..0000000
--- a/hexpp.js
+++ /dev/null
@@ -1,26 +0,0 @@
-function toHex (buf, group, wrap, LE) {
- buf = buf.buffer || buf
- var s = ''
- var l = buf.byteLength || buf.length
- for (var i = 0; i < l ; i++) {
- var byteParam = (i & 0xfffffffc) | (!LE ? i % 4 : 3 - i % 4)
- s += ((buf[byteParam] >> 4).toString(16)) +
- ((buf[byteParam] & 0xf).toString(16)) +
- (group - 1 === i % group ? ' ' : '') +
- (wrap - 1 === i % wrap ? '\n' : '')
- }
- return s
-}
-
-var hexpp = module.exports = function hexpp (buffer, opts) {
- opts = opts || {}
- opts.groups = opts.groups || 4
- opts.wrap = opts.wrap || 16
- return toHex(buffer, opts.groups, opts.wrap, opts.bigendian, opts.ints)
-}
-
-hexpp.defaults = function (opts) {
- return function (b) {
- return hexpp(b, opts)
- }
-}
diff --git a/test/hash.js b/test/hash.js
index 60ae231..cd4d6c5 100644
--- a/test/hash.js
+++ b/test/hash.js
@@ -1,4 +1,3 @@
-var hexpp = require('../hexpp').defaults({ bigendian: false })
var tape = require('tape')
var Hash = require('../hash')
@@ -6,25 +5,22 @@ var hex = '0A1B2C3D4E5F6G7H'
function equal (t, a, b) {
t.equal(a.length, b.length)
-
- for (var i = 0; i < a.length; i++) {
- t.equal(a[i], b[i])
- }
+ t.equal(a.toString('hex'), b.toString('hex'))
}
-var hexBuf = new Buffer([48, 65, 49, 66, 50, 67, 51, 68, 52, 69, 53, 70, 54, 71, 55, 72])
+var hexBuf = new Buffer('0A1B2C3D4E5F6G7H', 'utf8')
var count16 = {
strings: ['0A1B2C3D4E5F6G7H'],
buffers: [
hexBuf,
- new Buffer([128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128])
+ new Buffer('80000000000000000000000000000080', 'hex')
]
}
var empty = {
strings: [''],
buffers: [
- new Buffer([ 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ])
+ new Buffer('80000000000000000000000000000000', 'hex')
]
}
@@ -32,7 +28,7 @@ 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('80000000000000000000000000000080', 'hex')
]
}
@@ -41,7 +37,7 @@ var long = {
buffers: [
hexBuf,
hexBuf,
- new Buffer([128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0])
+ new Buffer('80000000000000000000000000000100', 'hex')
]
}
@@ -56,12 +52,6 @@ function makeTest (name, data) {
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) {
diff --git a/test/vectors.js b/test/vectors.js
index 4aef39c..b389087 100644
--- a/test/vectors.js
+++ b/test/vectors.js
@@ -2,7 +2,6 @@ var tape = require('tape')
var vectors = require('hash-test-vectors')
// var from = require('bops/typedarray/from')
var Buffer = require('buffer').Buffer
-var hexpp = require('../hexpp')
var createHash = require('../')
@@ -14,7 +13,6 @@ function makeTest (alg, i, verbose) {
console.log(v)
console.log('VECTOR', i)
console.log('INPUT', v.input)
- console.log(hexpp(new Buffer(v.input, 'base64')))
console.log(new Buffer(v.input, 'base64').toString('hex'))
}
--
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