[Pkg-javascript-commits] [node-hash-base] 01/03: Normalize encoding in tests (utf-8 to utf8)
Bastien Roucariès
rouca at moszumanska.debian.org
Thu May 4 10:21:25 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to annotated tag v2.0.2
in repository node-hash-base.
commit 0bb7c8871b177230c83ef27523812590a22ad6b4
Author: Kirill Fomichev <fanatid at ya.ru>
Date: Sat Apr 16 11:25:00 2016 +0300
Normalize encoding in tests (utf-8 to utf8)
---
.travis.yml | 1 -
index.js | 54 +++++++++++++++++++++++++++---------------------------
test/index.js | 16 ++++++++--------
3 files changed, 35 insertions(+), 36 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 85b53b8..d4dedd6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,4 +14,3 @@ matrix:
- node_js: "4"
env: TEST_SUITE=lint
script: npm run-script $TEST_SUITE
-
diff --git a/index.js b/index.js
index f0bc04e..6703851 100644
--- a/index.js
+++ b/index.js
@@ -15,6 +15,29 @@ function HashBase (blockSize) {
inherits(HashBase, Transform)
+HashBase.prototype._transform = function (chunk, encoding, callback) {
+ var error = null
+ try {
+ if (encoding !== 'buffer') chunk = new Buffer(chunk, encoding)
+ this.update(chunk)
+ } catch (err) {
+ error = err
+ }
+
+ callback(error)
+}
+
+HashBase.prototype._flush = function (callback) {
+ var error = null
+ try {
+ this.push(this._digest())
+ } catch (err) {
+ error = err
+ }
+
+ callback(error)
+}
+
HashBase.prototype.update = function (data, encoding) {
if (this._finalized) throw new Error('Digest already called')
if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding || 'binary')
@@ -39,6 +62,10 @@ HashBase.prototype.update = function (data, encoding) {
return this
}
+HashBase.prototype._update = function (data) {
+ throw new Error('_update is not implemented')
+}
+
HashBase.prototype.digest = function (encoding) {
if (this._finalized) throw new Error('Digest already called')
this._finalized = true
@@ -48,35 +75,8 @@ HashBase.prototype.digest = function (encoding) {
return digest
}
-HashBase.prototype._update = function (data) {
- throw new Error('_update is not implemented')
-}
-
HashBase.prototype._digest = function () {
throw new Error('_digest is not implemented')
}
-HashBase.prototype._transform = function (chunk, encoding, callback) {
- var error = null
- try {
- if (encoding !== 'buffer') chunk = new Buffer(chunk, encoding)
- this.update(chunk)
- } catch (err) {
- error = err
- }
-
- callback(error)
-}
-
-HashBase.prototype._flush = function (callback) {
- var error = null
- try {
- this.push(this._digest())
- } catch (err) {
- error = err
- }
-
- callback(error)
-}
-
module.exports = HashBase
diff --git a/test/index.js b/test/index.js
index e6a17f4..3b9a616 100644
--- a/test/index.js
+++ b/test/index.js
@@ -22,10 +22,10 @@ test('update', function (t) {
t.test('decode string with custom encoding', function (t) {
t.plan(1)
- var buffer = new Buffer('УТФ-8 text', 'utf-8')
+ var buffer = new Buffer('УТФ-8 text', 'utf8')
var base = new HashBase(buffer.length)
base._update = function () { t.same(this._block, buffer) }
- base.update(buffer.toString('utf-8'), 'utf-8')
+ base.update(buffer.toString('utf8'), 'utf8')
t.end()
})
@@ -76,14 +76,14 @@ test('digest', function (t) {
})
t.test('should return buffer by default', function (t) {
- t.base._digest = function () { return new Buffer('УТФ-8 text', 'utf-8') }
- t.same(t.base.digest(), new Buffer('УТФ-8 text', 'utf-8'))
+ t.base._digest = function () { return new Buffer('УТФ-8 text', 'utf8') }
+ t.same(t.base.digest(), new Buffer('УТФ-8 text', 'utf8'))
t.end()
})
t.test('should encode result with custom encoding', function (t) {
- t.base._digest = function () { return new Buffer('УТФ-8 text', 'utf-8') }
- t.same(t.base.digest('utf-8'), 'УТФ-8 text')
+ t.base._digest = function () { return new Buffer('УТФ-8 text', 'utf8') }
+ t.same(t.base.digest('utf8'), 'УТФ-8 text')
t.end()
})
@@ -140,8 +140,8 @@ test('_transform', function (t) {
t.test('should decode string with custom encoding', function (t) {
t.plan(2)
- t.base.update = function (data) { t.same(data, new Buffer('УТФ-8 text', 'utf-8')) }
- t.base._transform('УТФ-8 text', 'utf-8', function (err) {
+ t.base.update = function (data) { t.same(data, new Buffer('УТФ-8 text', 'utf8')) }
+ t.base._transform('УТФ-8 text', 'utf8', function (err) {
t.same(err, null)
})
t.end()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-hash-base.git
More information about the Pkg-javascript-commits
mailing list