Comparing version 1.4.0 to 1.4.1
112
assert.js
@@ -0,1 +1,45 @@ | ||
'use strict'; | ||
// compare and isBuffer taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js | ||
// original notice: | ||
/*! | ||
* The buffer module from node.js, for the browser. | ||
* | ||
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> | ||
* @license MIT | ||
*/ | ||
function compare(a, b) { | ||
if (a === b) { | ||
return 0; | ||
} | ||
var x = a.length; | ||
var y = b.length; | ||
for (var i = 0, len = Math.min(x, y); i < len; ++i) { | ||
if (a[i] !== b[i]) { | ||
x = a[i]; | ||
y = b[i]; | ||
break; | ||
} | ||
} | ||
if (x < y) { | ||
return -1; | ||
} | ||
if (y < x) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
function isBuffer(b) { | ||
if (global.Buffer && typeof global.Buffer.isBuffer === 'function') { | ||
return global.Buffer.isBuffer(b); | ||
} | ||
return !!(b != null && b._isBuffer); | ||
} | ||
// based on node assert, original notice: | ||
// http://wiki.commonjs.org/wiki/Unit_Testing/1.0 | ||
@@ -25,26 +69,3 @@ // | ||
'use strict'; | ||
// UTILITY | ||
function compare(bufa, bufb) { | ||
var cmpLen = Math.min(bufa, bufb); | ||
if (cmpLen <= 0) { | ||
return 0; | ||
} | ||
var i = -1; | ||
var a,b; | ||
while (++i < cmpLen) { | ||
a = bufa[i]; | ||
b = bufb[i]; | ||
if (a < b) { | ||
return -1; | ||
} else if (a > b) { | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
var util = require('util/'); | ||
var Buffer = require('buffer').Buffer; | ||
var BufferShim = require('buffer-shims'); | ||
var hasOwn = Object.prototype.hasOwnProperty; | ||
@@ -59,2 +80,5 @@ var pSlice = Array.prototype.slice; | ||
function isView(arrbuf) { | ||
if (isBuffer(arrbuf)) { | ||
return false; | ||
} | ||
if (typeof global.ArrayBuffer !== 'function') { | ||
@@ -115,21 +139,21 @@ return false; | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(this, stackStartFunction); | ||
} else { | ||
// non v8 browsers so we can have a stacktrace | ||
var err = new Error(); | ||
if (err.stack) { | ||
var out = err.stack; | ||
Error.captureStackTrace(this, stackStartFunction); | ||
} else { | ||
// non v8 browsers so we can have a stacktrace | ||
var err = new Error(); | ||
if (err.stack) { | ||
var out = err.stack; | ||
// try to strip useless frames | ||
var fn_name = getName(stackStartFunction); | ||
var idx = out.indexOf('\n' + fn_name); | ||
if (idx >= 0) { | ||
// once we have located the function frame | ||
// we need to strip out everything before it (and its line) | ||
var next_line = out.indexOf('\n', idx + 1); | ||
out = out.substring(next_line + 1); | ||
} | ||
// try to strip useless frames | ||
var fn_name = getName(stackStartFunction); | ||
var idx = out.indexOf('\n' + fn_name); | ||
if (idx >= 0) { | ||
// once we have located the function frame | ||
// we need to strip out everything before it (and its line) | ||
var next_line = out.indexOf('\n', idx + 1); | ||
out = out.substring(next_line + 1); | ||
} | ||
this.stack = out; | ||
} | ||
this.stack = out; | ||
} | ||
} | ||
@@ -234,3 +258,3 @@ }; | ||
return true; | ||
} else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) { | ||
} else if (isBuffer(actual) && isBuffer(expected)) { | ||
return compare(actual, expected) === 0; | ||
@@ -269,4 +293,4 @@ | ||
actual instanceof Float64Array)) { | ||
return compare(BufferShim.from(actual.buffer), | ||
BufferShim.from(expected.buffer)) === 0; | ||
return compare(new Uint8Array(actual.buffer), | ||
new Uint8Array(expected.buffer)) === 0; | ||
@@ -279,2 +303,4 @@ // 7.5 For all other Object pairs, including Array objects, equivalence is | ||
// accounts for both named and indexed properties on Arrays. | ||
} else if (isBuffer(actual) !== isBuffer(expected)) { | ||
return false; | ||
} else { | ||
@@ -281,0 +307,0 @@ memos = memos || {actual: [], expected: []}; |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"homepage": "https://github.com/defunctzombie/commonjs-assert", | ||
@@ -16,8 +16,8 @@ "repository": { | ||
"dependencies": { | ||
"buffer-shims": "1.0.0", | ||
"util": "0.10.3" | ||
}, | ||
"devDependencies": { | ||
"zuul": "~3.9.0", | ||
"mocha": "~1.21.4" | ||
"mocha": "~1.21.4", | ||
"zuul": "~3.10.0", | ||
"zuul-ngrok": "^4.0.0" | ||
}, | ||
@@ -29,4 +29,5 @@ "license": "MIT", | ||
"test": "npm run test-node && npm run test-browser", | ||
"test-native": "TEST_NATIVE=true mocha --ui qunit test.js" | ||
"test-native": "TEST_NATIVE=true mocha --ui qunit test.js", | ||
"browser-local": "zuul --no-coverage --local 8000 -- test.js" | ||
} | ||
} |
15
test.js
@@ -168,2 +168,12 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
test('assert.deepEqual - Buffers', function () { | ||
assert.doesNotThrow(makeBlock(assert.deepEqual, new Buffer([1, 2, 3]), new Buffer([1, 2, 3]))); | ||
if (typeof global.Uint8Array === 'function') { | ||
assert.throws(makeBlock(assert.deepEqual, new Buffer([1, 2, 3]), new Uint8Array([1, 2, 3]))); | ||
} | ||
if (typeof global.Uint16Array === 'function') { | ||
assert.doesNotThrow(makeBlock(assert.deepEqual, new Uint16Array([1, 2, 3]), new Uint16Array([1, 2, 3]))); | ||
} | ||
}); | ||
function thrower(errorConstructor) { | ||
@@ -298,2 +308,7 @@ throw new errorConstructor('test'); | ||
testAssertionMessage([1, 2, 3], '[ 1, 2, 3 ]'); | ||
testAssertionMessage(new Buffer([1, 2, 3]), '<Buffer 01 02 03>'); | ||
if (typeof global.Uint8Array === 'function' && Object.getOwnPropertyNames( new Uint8Array([])).length === 0) { | ||
// todo fix util.inspect | ||
testAssertionMessage(new Uint8Array([1, 2, 3]), '{ \'0\': 1, \'1\': 2, \'2\': 3 }'); | ||
} | ||
testAssertionMessage(/a/, '/a/'); | ||
@@ -300,0 +315,0 @@ testAssertionMessage(function f() {}, '[Function: f]'); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
34396
1
717
0
3
- Removedbuffer-shims@1.0.0
- Removedbuffer-shims@1.0.0(transitive)