sdfsdfs
This commit is contained in:
150
node_modules/buffer/test/_polyfill.js
generated
vendored
Normal file
150
node_modules/buffer/test/_polyfill.js
generated
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
if (!Array.prototype.forEach) {
|
||||
|
||||
Array.prototype.forEach = function(callback, thisArg) {
|
||||
|
||||
var T, k;
|
||||
|
||||
if (this == null) {
|
||||
throw new TypeError(' this is null or not defined');
|
||||
}
|
||||
|
||||
// 1. Let O be the result of calling ToObject passing the |this| value as the argument.
|
||||
var O = Object(this);
|
||||
|
||||
// 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
|
||||
// 3. Let len be ToUint32(lenValue).
|
||||
var len = O.length >>> 0;
|
||||
|
||||
// 4. If IsCallable(callback) is false, throw a TypeError exception.
|
||||
// See: http://es5.github.com/#x9.11
|
||||
if (typeof callback !== "function") {
|
||||
throw new TypeError(callback + ' is not a function');
|
||||
}
|
||||
|
||||
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
if (arguments.length > 1) {
|
||||
T = thisArg;
|
||||
}
|
||||
|
||||
// 6. Let k be 0
|
||||
k = 0;
|
||||
|
||||
// 7. Repeat, while k < len
|
||||
while (k < len) {
|
||||
|
||||
var kValue;
|
||||
|
||||
// a. Let Pk be ToString(k).
|
||||
// This is implicit for LHS operands of the in operator
|
||||
// b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
|
||||
// This step can be combined with c
|
||||
// c. If kPresent is true, then
|
||||
if (k in O) {
|
||||
|
||||
// i. Let kValue be the result of calling the Get internal method of O with argument Pk.
|
||||
kValue = O[k];
|
||||
|
||||
// ii. Call the Call internal method of callback with T as the this value and
|
||||
// argument list containing kValue, k, and O.
|
||||
callback.call(T, kValue, k, O);
|
||||
}
|
||||
// d. Increase k by 1.
|
||||
k++;
|
||||
}
|
||||
// 8. return undefined
|
||||
};
|
||||
}
|
||||
|
||||
if (!Array.isArray) {
|
||||
Array.isArray = function(arg) {
|
||||
return Object.prototype.toString.call(arg) === '[object Array]';
|
||||
};
|
||||
}
|
||||
|
||||
if (!Array.prototype.map) {
|
||||
|
||||
Array.prototype.map = function(callback, thisArg) {
|
||||
|
||||
var T, A, k;
|
||||
|
||||
if (this == null) {
|
||||
throw new TypeError(' this is null or not defined');
|
||||
}
|
||||
|
||||
// 1. Let O be the result of calling ToObject passing the |this|
|
||||
// value as the argument.
|
||||
var O = Object(this);
|
||||
|
||||
// 2. Let lenValue be the result of calling the Get internal
|
||||
// method of O with the argument "length".
|
||||
// 3. Let len be ToUint32(lenValue).
|
||||
var len = O.length >>> 0;
|
||||
|
||||
// 4. If IsCallable(callback) is false, throw a TypeError exception.
|
||||
// See: http://es5.github.com/#x9.11
|
||||
if (typeof callback !== 'function') {
|
||||
throw new TypeError(callback + ' is not a function');
|
||||
}
|
||||
|
||||
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
if (arguments.length > 1) {
|
||||
T = thisArg;
|
||||
}
|
||||
|
||||
// 6. Let A be a new array created as if by the expression new Array(len)
|
||||
// where Array is the standard built-in constructor with that name and
|
||||
// len is the value of len.
|
||||
A = new Array(len);
|
||||
|
||||
// 7. Let k be 0
|
||||
k = 0;
|
||||
|
||||
// 8. Repeat, while k < len
|
||||
while (k < len) {
|
||||
|
||||
var kValue, mappedValue;
|
||||
|
||||
// a. Let Pk be ToString(k).
|
||||
// This is implicit for LHS operands of the in operator
|
||||
// b. Let kPresent be the result of calling the HasProperty internal
|
||||
// method of O with argument Pk.
|
||||
// This step can be combined with c
|
||||
// c. If kPresent is true, then
|
||||
if (k in O) {
|
||||
|
||||
// i. Let kValue be the result of calling the Get internal
|
||||
// method of O with argument Pk.
|
||||
kValue = O[k];
|
||||
|
||||
// ii. Let mappedValue be the result of calling the Call internal
|
||||
// method of callback with T as the this value and argument
|
||||
// list containing kValue, k, and O.
|
||||
mappedValue = callback.call(T, kValue, k, O);
|
||||
|
||||
// iii. Call the DefineOwnProperty internal method of A with arguments
|
||||
// Pk, Property Descriptor
|
||||
// { Value: mappedValue,
|
||||
// Writable: true,
|
||||
// Enumerable: true,
|
||||
// Configurable: true },
|
||||
// and false.
|
||||
|
||||
// In browsers that support Object.defineProperty, use the following:
|
||||
// Object.defineProperty(A, k, {
|
||||
// value: mappedValue,
|
||||
// writable: true,
|
||||
// enumerable: true,
|
||||
// configurable: true
|
||||
// });
|
||||
|
||||
// For best browser support, use the following:
|
||||
A[k] = mappedValue;
|
||||
}
|
||||
// d. Increase k by 1.
|
||||
k++;
|
||||
}
|
||||
|
||||
// 9. return A
|
||||
return A;
|
||||
};
|
||||
}
|
47
node_modules/buffer/test/base64.js
generated
vendored
Normal file
47
node_modules/buffer/test/base64.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
test('base64: ignore whitespace', function (t) {
|
||||
var text = '\n YW9ldQ== '
|
||||
var buf = new B(text, 'base64')
|
||||
t.equal(buf.toString(), 'aoeu')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('base64: strings without padding', function (t) {
|
||||
t.equal((new B('YW9ldQ', 'base64').toString()), 'aoeu')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('base64: newline in utf8 -- should not be an issue', function (t) {
|
||||
t.equal(
|
||||
new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK', 'base64').toString('utf8'),
|
||||
'---\ntitle: Three dashes marks the spot\ntags:\n'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('base64: newline in base64 -- should get stripped', function (t) {
|
||||
t.equal(
|
||||
new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\nICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt', 'base64').toString('utf8'),
|
||||
'---\ntitle: Three dashes marks the spot\ntags:\n - yaml\n - front-matter\n - dashes\nexpaned-'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('base64: tab characters in base64 - should get stripped', function (t) {
|
||||
t.equal(
|
||||
new B('LS0tCnRpdGxlOiBUaHJlZSBkYXNoZXMgbWFya3MgdGhlIHNwb3QKdGFnczoK\t\t\t\tICAtIHlhbWwKICAtIGZyb250LW1hdHRlcgogIC0gZGFzaGVzCmV4cGFuZWQt', 'base64').toString('utf8'),
|
||||
'---\ntitle: Three dashes marks the spot\ntags:\n - yaml\n - front-matter\n - dashes\nexpaned-'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('base64: invalid non-alphanumeric characters -- should be stripped', function (t) {
|
||||
t.equal(
|
||||
new B('!"#$%&\'()*,.:;<=>?@[\\]^`{|}~', 'base64').toString('utf8'),
|
||||
''
|
||||
)
|
||||
t.end()
|
||||
})
|
85
node_modules/buffer/test/basic.js
generated
vendored
Normal file
85
node_modules/buffer/test/basic.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
test('instanceof Buffer', function (t) {
|
||||
var buf = new B([1, 2])
|
||||
t.ok(buf instanceof B)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('convert to Uint8Array in modern browsers', function (t) {
|
||||
if (B.TYPED_ARRAY_SUPPORT) {
|
||||
var buf = new B([1, 2])
|
||||
var uint8array = new Uint8Array(buf.buffer)
|
||||
t.ok(uint8array instanceof Uint8Array)
|
||||
t.equal(uint8array[0], 1)
|
||||
t.equal(uint8array[1], 2)
|
||||
} else {
|
||||
t.pass('object impl: skipping test')
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('indexes from a string', function (t) {
|
||||
var buf = new B('abc')
|
||||
t.equal(buf[0], 97)
|
||||
t.equal(buf[1], 98)
|
||||
t.equal(buf[2], 99)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('indexes from an array', function (t) {
|
||||
var buf = new B([ 97, 98, 99 ])
|
||||
t.equal(buf[0], 97)
|
||||
t.equal(buf[1], 98)
|
||||
t.equal(buf[2], 99)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('setting index value should modify buffer contents', function (t) {
|
||||
var buf = new B([ 97, 98, 99 ])
|
||||
t.equal(buf[2], 99)
|
||||
t.equal(buf.toString(), 'abc')
|
||||
|
||||
buf[2] += 10
|
||||
t.equal(buf[2], 109)
|
||||
t.equal(buf.toString(), 'abm')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('storing negative number should cast to unsigned', function (t) {
|
||||
var buf = new B(1)
|
||||
|
||||
if (B.TYPED_ARRAY_SUPPORT) {
|
||||
// This does not work with the object implementation -- nothing we can do!
|
||||
buf[0] = -3
|
||||
t.equal(buf[0], 253)
|
||||
}
|
||||
|
||||
buf = new B(1)
|
||||
buf.writeInt8(-3, 0)
|
||||
t.equal(buf[0], 253)
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('test that memory is copied from array-like', function (t) {
|
||||
if (B.TYPED_ARRAY_SUPPORT) {
|
||||
var u = new Uint8Array(4)
|
||||
var b = new B(u)
|
||||
b[0] = 1
|
||||
b[1] = 2
|
||||
b[2] = 3
|
||||
b[3] = 4
|
||||
|
||||
t.equal(u[0], 0)
|
||||
t.equal(u[1], 0)
|
||||
t.equal(u[2], 0)
|
||||
t.equal(u[3], 0)
|
||||
} else {
|
||||
t.pass('object impl: skipping test')
|
||||
}
|
||||
|
||||
t.end()
|
||||
})
|
59
node_modules/buffer/test/compare.js
generated
vendored
Normal file
59
node_modules/buffer/test/compare.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
test('buffer.compare', function (t) {
|
||||
var b = new B(1).fill('a')
|
||||
var c = new B(1).fill('c')
|
||||
var d = new B(2).fill('aa')
|
||||
|
||||
t.equal(b.compare(c), -1)
|
||||
t.equal(c.compare(d), 1)
|
||||
t.equal(d.compare(b), 1)
|
||||
t.equal(b.compare(d), -1)
|
||||
|
||||
// static method
|
||||
t.equal(B.compare(b, c), -1)
|
||||
t.equal(B.compare(c, d), 1)
|
||||
t.equal(B.compare(d, b), 1)
|
||||
t.equal(B.compare(b, d), -1)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('buffer.compare argument validation', function (t) {
|
||||
t.throws(function () {
|
||||
var b = new B(1)
|
||||
B.compare(b, 'abc')
|
||||
})
|
||||
|
||||
t.throws(function () {
|
||||
var b = new B(1)
|
||||
B.compare('abc', b)
|
||||
})
|
||||
|
||||
t.throws(function () {
|
||||
var b = new B(1)
|
||||
b.compare('abc')
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('buffer.equals', function (t) {
|
||||
var b = new B(5).fill('abcdf')
|
||||
var c = new B(5).fill('abcdf')
|
||||
var d = new B(5).fill('abcde')
|
||||
var e = new B(6).fill('abcdef')
|
||||
|
||||
t.ok(b.equals(c))
|
||||
t.ok(!c.equals(d))
|
||||
t.ok(!d.equals(e))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('buffer.equals argument validation', function (t) {
|
||||
t.throws(function () {
|
||||
var b = new B(1)
|
||||
b.equals('abc')
|
||||
})
|
||||
t.end()
|
||||
})
|
193
node_modules/buffer/test/constructor.js
generated
vendored
Normal file
193
node_modules/buffer/test/constructor.js
generated
vendored
Normal file
@@ -0,0 +1,193 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
test('new buffer from array', function (t) {
|
||||
t.equal(
|
||||
new B([1, 2, 3]).toString(),
|
||||
'\u0001\u0002\u0003'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from array w/ negatives', function (t) {
|
||||
t.equal(
|
||||
new B([-1, -2, -3]).toString('hex'),
|
||||
'fffefd'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from array with mixed signed input', function (t) {
|
||||
t.equal(
|
||||
new B([-255, 255, -128, 128, 512, -512, 511, -511]).toString('hex'),
|
||||
'01ff80800000ff01'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from string', function (t) {
|
||||
t.equal(
|
||||
new B('hey', 'utf8').toString(),
|
||||
'hey'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from buffer', function (t) {
|
||||
var b1 = new B('asdf')
|
||||
var b2 = new B(b1)
|
||||
t.equal(b1.toString('hex'), b2.toString('hex'))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from ArrayBuffer', function (t) {
|
||||
if (typeof ArrayBuffer !== 'undefined') {
|
||||
var arraybuffer = new Uint8Array([0, 1, 2, 3]).buffer
|
||||
var b = new B(arraybuffer)
|
||||
t.equal(b.length, 4)
|
||||
t.equal(b[0], 0)
|
||||
t.equal(b[1], 1)
|
||||
t.equal(b[2], 2)
|
||||
t.equal(b[3], 3)
|
||||
t.equal(b[4], undefined)
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from ArrayBuffer, shares memory', function (t) {
|
||||
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
||||
var u = new Uint8Array([0, 1, 2, 3])
|
||||
var arraybuffer = u.buffer
|
||||
var b = new B(arraybuffer)
|
||||
t.equal(b.length, 4)
|
||||
t.equal(b[0], 0)
|
||||
t.equal(b[1], 1)
|
||||
t.equal(b[2], 2)
|
||||
t.equal(b[3], 3)
|
||||
t.equal(b[4], undefined)
|
||||
|
||||
// changing the Uint8Array (and thus the ArrayBuffer), changes the Buffer
|
||||
u[0] = 10
|
||||
t.equal(b[0], 10)
|
||||
u[1] = 11
|
||||
t.equal(b[1], 11)
|
||||
u[2] = 12
|
||||
t.equal(b[2], 12)
|
||||
u[3] = 13
|
||||
t.equal(b[3], 13)
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from Uint8Array', function (t) {
|
||||
if (typeof Uint8Array !== 'undefined') {
|
||||
var b1 = new Uint8Array([0, 1, 2, 3])
|
||||
var b2 = new B(b1)
|
||||
t.equal(b1.length, b2.length)
|
||||
t.equal(b1[0], 0)
|
||||
t.equal(b1[1], 1)
|
||||
t.equal(b1[2], 2)
|
||||
t.equal(b1[3], 3)
|
||||
t.equal(b1[4], undefined)
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from Uint16Array', function (t) {
|
||||
if (typeof Uint16Array !== 'undefined') {
|
||||
var b1 = new Uint16Array([0, 1, 2, 3])
|
||||
var b2 = new B(b1)
|
||||
t.equal(b1.length, b2.length)
|
||||
t.equal(b1[0], 0)
|
||||
t.equal(b1[1], 1)
|
||||
t.equal(b1[2], 2)
|
||||
t.equal(b1[3], 3)
|
||||
t.equal(b1[4], undefined)
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from Uint32Array', function (t) {
|
||||
if (typeof Uint32Array !== 'undefined') {
|
||||
var b1 = new Uint32Array([0, 1, 2, 3])
|
||||
var b2 = new B(b1)
|
||||
t.equal(b1.length, b2.length)
|
||||
t.equal(b1[0], 0)
|
||||
t.equal(b1[1], 1)
|
||||
t.equal(b1[2], 2)
|
||||
t.equal(b1[3], 3)
|
||||
t.equal(b1[4], undefined)
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from Int16Array', function (t) {
|
||||
if (typeof Int16Array !== 'undefined') {
|
||||
var b1 = new Int16Array([0, 1, 2, 3])
|
||||
var b2 = new B(b1)
|
||||
t.equal(b1.length, b2.length)
|
||||
t.equal(b1[0], 0)
|
||||
t.equal(b1[1], 1)
|
||||
t.equal(b1[2], 2)
|
||||
t.equal(b1[3], 3)
|
||||
t.equal(b1[4], undefined)
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from Int32Array', function (t) {
|
||||
if (typeof Int32Array !== 'undefined') {
|
||||
var b1 = new Int32Array([0, 1, 2, 3])
|
||||
var b2 = new B(b1)
|
||||
t.equal(b1.length, b2.length)
|
||||
t.equal(b1[0], 0)
|
||||
t.equal(b1[1], 1)
|
||||
t.equal(b1[2], 2)
|
||||
t.equal(b1[3], 3)
|
||||
t.equal(b1[4], undefined)
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from Float32Array', function (t) {
|
||||
if (typeof Float32Array !== 'undefined') {
|
||||
var b1 = new Float32Array([0, 1, 2, 3])
|
||||
var b2 = new B(b1)
|
||||
t.equal(b1.length, b2.length)
|
||||
t.equal(b1[0], 0)
|
||||
t.equal(b1[1], 1)
|
||||
t.equal(b1[2], 2)
|
||||
t.equal(b1[3], 3)
|
||||
t.equal(b1[4], undefined)
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from Float64Array', function (t) {
|
||||
if (typeof Float64Array !== 'undefined') {
|
||||
var b1 = new Float64Array([0, 1, 2, 3])
|
||||
var b2 = new B(b1)
|
||||
t.equal(b1.length, b2.length)
|
||||
t.equal(b1[0], 0)
|
||||
t.equal(b1[1], 1)
|
||||
t.equal(b1[2], 2)
|
||||
t.equal(b1[3], 3)
|
||||
t.equal(b1[4], undefined)
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('new buffer from buffer.toJSON() output', function (t) {
|
||||
if (typeof JSON === 'undefined') {
|
||||
// ie6, ie7 lack support
|
||||
t.end()
|
||||
return
|
||||
}
|
||||
var buf = new B('test')
|
||||
var json = JSON.stringify(buf)
|
||||
var obj = JSON.parse(json)
|
||||
var copy = new B(obj)
|
||||
t.ok(buf.equals(copy))
|
||||
t.end()
|
||||
})
|
132
node_modules/buffer/test/from-string.js
generated
vendored
Normal file
132
node_modules/buffer/test/from-string.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
test('detect utf16 surrogate pairs', function (t) {
|
||||
var text = '\uD83D\uDE38' + '\uD83D\uDCAD' + '\uD83D\uDC4D'
|
||||
var buf = new B(text)
|
||||
t.equal(text, buf.toString())
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('detect utf16 surrogate pairs over U+20000 until U+10FFFF', function (t) {
|
||||
var text = '\uD842\uDFB7' + '\uD93D\uDCAD' + '\uDBFF\uDFFF'
|
||||
var buf = new B(text)
|
||||
t.equal(text, buf.toString())
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('replace orphaned utf16 surrogate lead code point', function (t) {
|
||||
var text = '\uD83D\uDE38' + '\uD83D' + '\uD83D\uDC4D'
|
||||
var buf = new B(text)
|
||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d ]))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('replace orphaned utf16 surrogate trail code point', function (t) {
|
||||
var text = '\uD83D\uDE38' + '\uDCAD' + '\uD83D\uDC4D'
|
||||
var buf = new B(text)
|
||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d ]))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('do not write partial utf16 code units', function (t) {
|
||||
var f = new B([0, 0, 0, 0, 0])
|
||||
t.equal(f.length, 5)
|
||||
var size = f.write('あいうえお', 'utf16le')
|
||||
t.equal(size, 4)
|
||||
t.deepEqual(f, new B([0x42, 0x30, 0x44, 0x30, 0x00]))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('handle partial utf16 code points when encoding to utf8 the way node does', function (t) {
|
||||
var text = '\uD83D\uDE38' + '\uD83D\uDC4D'
|
||||
|
||||
var buf = new B(8)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xf0, 0x9f, 0x91, 0x8d ]))
|
||||
|
||||
buf = new B(7)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00, 0x00 ]))
|
||||
|
||||
buf = new B(6)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00 ]))
|
||||
|
||||
buf = new B(5)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00 ]))
|
||||
|
||||
buf = new B(4)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8 ]))
|
||||
|
||||
buf = new B(3)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x00, 0x00, 0x00 ]))
|
||||
|
||||
buf = new B(2)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x00, 0x00 ]))
|
||||
|
||||
buf = new B(1)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x00 ]))
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('handle invalid utf16 code points when encoding to utf8 the way node does', function (t) {
|
||||
var text = 'a' + '\uDE38\uD83D' + 'b'
|
||||
|
||||
var buf = new B(8)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd, 0x62 ]))
|
||||
|
||||
buf = new B(7)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd ]))
|
||||
|
||||
buf = new B(6)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0x00, 0x00 ]))
|
||||
|
||||
buf = new B(5)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0x00 ]))
|
||||
|
||||
buf = new B(4)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd ]))
|
||||
|
||||
buf = new B(3)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x61, 0x00, 0x00 ]))
|
||||
|
||||
buf = new B(2)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x61, 0x00 ]))
|
||||
|
||||
buf = new B(1)
|
||||
buf.fill(0)
|
||||
buf.write(text)
|
||||
t.deepEqual(buf, new B([ 0x61 ]))
|
||||
|
||||
t.end()
|
||||
})
|
22
node_modules/buffer/test/is-buffer.js
generated
vendored
Normal file
22
node_modules/buffer/test/is-buffer.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var isBuffer = require('is-buffer')
|
||||
var test = require('tape')
|
||||
|
||||
test('is-buffer tests', function (t) {
|
||||
t.ok(isBuffer(new B(4)), 'new Buffer(4)')
|
||||
|
||||
t.notOk(isBuffer(undefined), 'undefined')
|
||||
t.notOk(isBuffer(null), 'null')
|
||||
t.notOk(isBuffer(''), 'empty string')
|
||||
t.notOk(isBuffer(true), 'true')
|
||||
t.notOk(isBuffer(false), 'false')
|
||||
t.notOk(isBuffer(0), '0')
|
||||
t.notOk(isBuffer(1), '1')
|
||||
t.notOk(isBuffer(1.0), '1.0')
|
||||
t.notOk(isBuffer('string'), 'string')
|
||||
t.notOk(isBuffer({}), '{}')
|
||||
t.notOk(isBuffer(function foo () {}), 'function foo () {}')
|
||||
|
||||
t.end()
|
||||
})
|
127
node_modules/buffer/test/methods.js
generated
vendored
Normal file
127
node_modules/buffer/test/methods.js
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
test('buffer.toJSON', function (t) {
|
||||
var data = [1, 2, 3, 4]
|
||||
t.deepEqual(
|
||||
new B(data).toJSON(),
|
||||
{ type: 'Buffer', data: [ 1, 2, 3, 4 ] }
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('buffer.copy', function (t) {
|
||||
// copied from nodejs.org example
|
||||
var buf1 = new B(26)
|
||||
var buf2 = new B(26)
|
||||
|
||||
for (var i = 0; i < 26; i++) {
|
||||
buf1[i] = i + 97 // 97 is ASCII a
|
||||
buf2[i] = 33 // ASCII !
|
||||
}
|
||||
|
||||
buf1.copy(buf2, 8, 16, 20)
|
||||
|
||||
t.equal(
|
||||
buf2.toString('ascii', 0, 25),
|
||||
'!!!!!!!!qrst!!!!!!!!!!!!!'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('test offset returns are correct', function (t) {
|
||||
var b = new B(16)
|
||||
t.equal(4, b.writeUInt32LE(0, 0))
|
||||
t.equal(6, b.writeUInt16LE(0, 4))
|
||||
t.equal(7, b.writeUInt8(0, 6))
|
||||
t.equal(8, b.writeInt8(0, 7))
|
||||
t.equal(16, b.writeDoubleLE(0, 8))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('concat() a varying number of buffers', function (t) {
|
||||
var zero = []
|
||||
var one = [ new B('asdf') ]
|
||||
var long = []
|
||||
for (var i = 0; i < 10; i++) {
|
||||
long.push(new B('asdf'))
|
||||
}
|
||||
|
||||
var flatZero = B.concat(zero)
|
||||
var flatOne = B.concat(one)
|
||||
var flatLong = B.concat(long)
|
||||
var flatLongLen = B.concat(long, 40)
|
||||
|
||||
t.equal(flatZero.length, 0)
|
||||
t.equal(flatOne.toString(), 'asdf')
|
||||
t.deepEqual(flatOne, one[0])
|
||||
t.equal(flatLong.toString(), (new Array(10 + 1).join('asdf')))
|
||||
t.equal(flatLongLen.toString(), (new Array(10 + 1).join('asdf')))
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('fill', function (t) {
|
||||
var b = new B(10)
|
||||
b.fill(2)
|
||||
t.equal(b.toString('hex'), '02020202020202020202')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('fill (string)', function (t) {
|
||||
var b = new B(10)
|
||||
b.fill('abc')
|
||||
t.equal(b.toString(), 'abcabcabca')
|
||||
b.fill('է')
|
||||
t.equal(b.toString(), 'էէէէէ')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('copy() empty buffer with sourceEnd=0', function (t) {
|
||||
var source = new B([42])
|
||||
var destination = new B([43])
|
||||
source.copy(destination, 0, 0, 0)
|
||||
t.equal(destination.readUInt8(0), 43)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('copy() after slice()', function (t) {
|
||||
var source = new B(200)
|
||||
var dest = new B(200)
|
||||
var expected = new B(200)
|
||||
for (var i = 0; i < 200; i++) {
|
||||
source[i] = i
|
||||
dest[i] = 0
|
||||
}
|
||||
|
||||
source.slice(2).copy(dest)
|
||||
source.copy(expected, 0, 2)
|
||||
t.deepEqual(dest, expected)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('copy() ascending', function (t) {
|
||||
var b = new B('abcdefghij')
|
||||
b.copy(b, 0, 3, 10)
|
||||
t.equal(b.toString(), 'defghijhij')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('copy() descending', function (t) {
|
||||
var b = new B('abcdefghij')
|
||||
b.copy(b, 3, 0, 7)
|
||||
t.equal(b.toString(), 'abcabcdefg')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('buffer.slice sets indexes', function (t) {
|
||||
t.equal((new B('hallo')).slice(0, 5).toString(), 'hallo')
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('buffer.slice out of range', function (t) {
|
||||
t.plan(2)
|
||||
t.equal((new B('hallo')).slice(0, 10).toString(), 'hallo')
|
||||
t.equal((new B('hallo')).slice(10, 2).toString(), '')
|
||||
t.end()
|
||||
})
|
1501
node_modules/buffer/test/node/test-buffer-alloc.js
generated
vendored
Normal file
1501
node_modules/buffer/test/node/test-buffer-alloc.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
112
node_modules/buffer/test/node/test-buffer-arraybuffer.js
generated
vendored
Normal file
112
node_modules/buffer/test/node/test-buffer-arraybuffer.js
generated
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var Buffer = require('../../').Buffer;
|
||||
var LENGTH = 16;
|
||||
|
||||
var ab = new ArrayBuffer(LENGTH);
|
||||
var dv = new DataView(ab);
|
||||
var ui = new Uint8Array(ab);
|
||||
var buf = Buffer.from(ab);
|
||||
|
||||
|
||||
assert.ok(buf instanceof Buffer);
|
||||
// For backwards compatibility of old .parent property test that if buf is not
|
||||
// a slice then .parent should be undefined.
|
||||
assert.equal(buf.parent, undefined);
|
||||
assert.equal(buf.buffer, ab);
|
||||
assert.equal(buf.length, ab.byteLength);
|
||||
|
||||
|
||||
buf.fill(0xC);
|
||||
for (var i = 0; i < LENGTH; i++) {
|
||||
assert.equal(ui[i], 0xC);
|
||||
ui[i] = 0xF;
|
||||
assert.equal(buf[i], 0xF);
|
||||
}
|
||||
|
||||
buf.writeUInt32LE(0xF00, 0);
|
||||
buf.writeUInt32BE(0xB47, 4);
|
||||
buf.writeDoubleLE(3.1415, 8);
|
||||
|
||||
assert.equal(dv.getUint32(0, true), 0xF00);
|
||||
assert.equal(dv.getUint32(4), 0xB47);
|
||||
assert.equal(dv.getFloat64(8, true), 3.1415);
|
||||
|
||||
|
||||
// Now test protecting users from doing stupid things
|
||||
|
||||
assert.throws(function() {
|
||||
function AB() { }
|
||||
Object.setPrototypeOf(AB, ArrayBuffer);
|
||||
Object.setPrototypeOf(AB.prototype, ArrayBuffer.prototype);
|
||||
Buffer.from(new AB());
|
||||
}, TypeError);
|
||||
|
||||
// write{Double,Float}{LE,BE} with noAssert should not crash, cf. #3766
|
||||
var b = Buffer.allocUnsafe(1);
|
||||
b.writeFloatLE(11.11, 0, true);
|
||||
b.writeFloatBE(11.11, 0, true);
|
||||
b.writeDoubleLE(11.11, 0, true);
|
||||
b.writeDoubleBE(11.11, 0, true);
|
||||
|
||||
// Test the byteOffset and length arguments
|
||||
{
|
||||
var ab = new Uint8Array(5);
|
||||
ab[0] = 1;
|
||||
ab[1] = 2;
|
||||
ab[2] = 3;
|
||||
ab[3] = 4;
|
||||
ab[4] = 5;
|
||||
var buf = Buffer.from(ab.buffer, 1, 3);
|
||||
assert.equal(buf.length, 3);
|
||||
assert.equal(buf[0], 2);
|
||||
assert.equal(buf[1], 3);
|
||||
assert.equal(buf[2], 4);
|
||||
buf[0] = 9;
|
||||
assert.equal(ab[1], 9);
|
||||
|
||||
assert.throws(() => Buffer.from(ab.buffer, 6), (err) => {
|
||||
assert(err instanceof RangeError);
|
||||
assert(/'offset' is out of bounds/.test(err.message));
|
||||
return true;
|
||||
});
|
||||
assert.throws(() => Buffer.from(ab.buffer, 3, 6), (err) => {
|
||||
assert(err instanceof RangeError);
|
||||
assert(/'length' is out of bounds/.test(err.message));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// Test the deprecated Buffer() version also
|
||||
{
|
||||
var ab = new Uint8Array(5);
|
||||
ab[0] = 1;
|
||||
ab[1] = 2;
|
||||
ab[2] = 3;
|
||||
ab[3] = 4;
|
||||
ab[4] = 5;
|
||||
var buf = Buffer(ab.buffer, 1, 3);
|
||||
assert.equal(buf.length, 3);
|
||||
assert.equal(buf[0], 2);
|
||||
assert.equal(buf[1], 3);
|
||||
assert.equal(buf[2], 4);
|
||||
buf[0] = 9;
|
||||
assert.equal(ab[1], 9);
|
||||
|
||||
assert.throws(() => Buffer(ab.buffer, 6), (err) => {
|
||||
assert(err instanceof RangeError);
|
||||
assert(/'offset' is out of bounds/.test(err.message));
|
||||
return true;
|
||||
});
|
||||
assert.throws(() => Buffer(ab.buffer, 3, 6), (err) => {
|
||||
assert(err instanceof RangeError);
|
||||
assert(/'length' is out of bounds/.test(err.message));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
28
node_modules/buffer/test/node/test-buffer-ascii.js
generated
vendored
Normal file
28
node_modules/buffer/test/node/test-buffer-ascii.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
// ASCII conversion in node.js simply masks off the high bits,
|
||||
// it doesn't do transliteration.
|
||||
assert.equal(Buffer.from('hérité').toString('ascii'), 'hC)ritC)');
|
||||
|
||||
// 71 characters, 78 bytes. The ’ character is a triple-byte sequence.
|
||||
var input = 'C’est, graphiquement, la réunion d’un accent aigu ' +
|
||||
'et d’un accent grave.';
|
||||
|
||||
var expected = 'Cb\u0000\u0019est, graphiquement, la rC)union ' +
|
||||
'db\u0000\u0019un accent aigu et db\u0000\u0019un ' +
|
||||
'accent grave.';
|
||||
|
||||
var buf = Buffer.from(input);
|
||||
|
||||
for (var i = 0; i < expected.length; ++i) {
|
||||
assert.equal(buf.slice(i).toString('ascii'), expected.slice(i));
|
||||
|
||||
// Skip remainder of multi-byte sequence.
|
||||
if (input.charCodeAt(i) > 65535) ++i;
|
||||
if (input.charCodeAt(i) > 127) ++i;
|
||||
}
|
||||
|
18
node_modules/buffer/test/node/test-buffer-bad-overload.js
generated
vendored
Normal file
18
node_modules/buffer/test/node/test-buffer-bad-overload.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
assert.doesNotThrow(function() {
|
||||
Buffer.allocUnsafe(10);
|
||||
});
|
||||
|
||||
assert.throws(function() {
|
||||
Buffer.from(10, 'hex');
|
||||
});
|
||||
|
||||
assert.doesNotThrow(function() {
|
||||
Buffer.from('deadbeaf', 'hex');
|
||||
});
|
||||
|
46
node_modules/buffer/test/node/test-buffer-badhex.js
generated
vendored
Normal file
46
node_modules/buffer/test/node/test-buffer-badhex.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
// Test hex strings and bad hex strings
|
||||
{
|
||||
var buf1 = Buffer.alloc(4);
|
||||
assert.strictEqual(buf1.length, 4);
|
||||
assert.deepStrictEqual(buf1, new Buffer([0, 0, 0, 0]));
|
||||
assert.strictEqual(buf1.write('abcdxx', 0, 'hex'), 2);
|
||||
assert.deepStrictEqual(buf1, new Buffer([0xab, 0xcd, 0x00, 0x00]));
|
||||
assert.strictEqual(buf1.toString('hex'), 'abcd0000');
|
||||
assert.strictEqual(buf1.write('abcdef01', 0, 'hex'), 4);
|
||||
assert.deepStrictEqual(buf1, new Buffer([0xab, 0xcd, 0xef, 0x01]));
|
||||
assert.strictEqual(buf1.toString('hex'), 'abcdef01');
|
||||
|
||||
var buf2 = Buffer.from(buf1.toString('hex'), 'hex');
|
||||
assert.strictEqual(buf1.toString('hex'), buf2.toString('hex'));
|
||||
|
||||
var buf3 = Buffer.alloc(5);
|
||||
assert.strictEqual(buf3.write('abcdxx', 1, 'hex'), 2);
|
||||
assert.strictEqual(buf3.toString('hex'), '00abcd0000');
|
||||
|
||||
var buf4 = Buffer.alloc(4);
|
||||
assert.deepStrictEqual(buf4, new Buffer([0, 0, 0, 0]));
|
||||
assert.strictEqual(buf4.write('xxabcd', 0, 'hex'), 0);
|
||||
assert.deepStrictEqual(buf4, new Buffer([0, 0, 0, 0]));
|
||||
assert.strictEqual(buf4.write('xxab', 1, 'hex'), 0);
|
||||
assert.deepStrictEqual(buf4, new Buffer([0, 0, 0, 0]));
|
||||
assert.strictEqual(buf4.write('cdxxab', 0, 'hex'), 1);
|
||||
assert.deepStrictEqual(buf4, new Buffer([0xcd, 0, 0, 0]));
|
||||
|
||||
var buf5 = Buffer.alloc(256);
|
||||
for (var i = 0; i < 256; i++)
|
||||
buf5[i] = i;
|
||||
|
||||
var hex = buf5.toString('hex');
|
||||
assert.deepStrictEqual(Buffer.from(hex, 'hex'), buf5);
|
||||
|
||||
var badHex = hex.slice(0, 256) + 'xx' + hex.slice(256, 510);
|
||||
assert.deepStrictEqual(Buffer.from(badHex, 'hex'), buf5.slice(0, 128));
|
||||
}
|
||||
|
90
node_modules/buffer/test/node/test-buffer-bytelength.js
generated
vendored
Normal file
90
node_modules/buffer/test/node/test-buffer-bytelength.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var Buffer = require('../../').Buffer;
|
||||
var SlowBuffer = require('../../').SlowBuffer;
|
||||
|
||||
// coerce values to string
|
||||
assert.equal(Buffer.byteLength(32, 'latin1'), 2);
|
||||
assert.equal(Buffer.byteLength(NaN, 'utf8'), 3);
|
||||
assert.equal(Buffer.byteLength({}, 'latin1'), 15);
|
||||
assert.equal(Buffer.byteLength(), 9);
|
||||
|
||||
var buff = new Buffer(10);
|
||||
assert(ArrayBuffer.isView(buff));
|
||||
var slowbuff = new SlowBuffer(10);
|
||||
assert(ArrayBuffer.isView(slowbuff));
|
||||
|
||||
// buffer
|
||||
var incomplete = Buffer.from([0xe4, 0xb8, 0xad, 0xe6, 0x96]);
|
||||
assert.equal(Buffer.byteLength(incomplete), 5);
|
||||
var ascii = Buffer.from('abc');
|
||||
assert.equal(Buffer.byteLength(ascii), 3);
|
||||
|
||||
// ArrayBuffer
|
||||
var buffer = new ArrayBuffer(8);
|
||||
assert.equal(Buffer.byteLength(buffer), 8);
|
||||
|
||||
// TypedArray
|
||||
var int8 = new Int8Array(8);
|
||||
assert.equal(Buffer.byteLength(int8), 8);
|
||||
var uint8 = new Uint8Array(8);
|
||||
assert.equal(Buffer.byteLength(uint8), 8);
|
||||
var uintc8 = new Uint8ClampedArray(2);
|
||||
assert.equal(Buffer.byteLength(uintc8), 2);
|
||||
var int16 = new Int16Array(8);
|
||||
assert.equal(Buffer.byteLength(int16), 16);
|
||||
var uint16 = new Uint16Array(8);
|
||||
assert.equal(Buffer.byteLength(uint16), 16);
|
||||
var int32 = new Int32Array(8);
|
||||
assert.equal(Buffer.byteLength(int32), 32);
|
||||
var uint32 = new Uint32Array(8);
|
||||
assert.equal(Buffer.byteLength(uint32), 32);
|
||||
var float32 = new Float32Array(8);
|
||||
assert.equal(Buffer.byteLength(float32), 32);
|
||||
var float64 = new Float64Array(8);
|
||||
assert.equal(Buffer.byteLength(float64), 64);
|
||||
|
||||
// DataView
|
||||
var dv = new DataView(new ArrayBuffer(2));
|
||||
assert.equal(Buffer.byteLength(dv), 2);
|
||||
|
||||
// special case: zero length string
|
||||
assert.equal(Buffer.byteLength('', 'ascii'), 0);
|
||||
assert.equal(Buffer.byteLength('', 'HeX'), 0);
|
||||
|
||||
// utf8
|
||||
assert.equal(Buffer.byteLength('∑éllö wørl∂!', 'utf-8'), 19);
|
||||
assert.equal(Buffer.byteLength('κλμνξο', 'utf8'), 12);
|
||||
assert.equal(Buffer.byteLength('挵挶挷挸挹', 'utf-8'), 15);
|
||||
assert.equal(Buffer.byteLength('𠝹𠱓𠱸', 'UTF8'), 12);
|
||||
// without an encoding, utf8 should be assumed
|
||||
assert.equal(Buffer.byteLength('hey there'), 9);
|
||||
assert.equal(Buffer.byteLength('𠱸挶νξ#xx :)'), 17);
|
||||
assert.equal(Buffer.byteLength('hello world', ''), 11);
|
||||
// it should also be assumed with unrecognized encoding
|
||||
assert.equal(Buffer.byteLength('hello world', 'abc'), 11);
|
||||
assert.equal(Buffer.byteLength('ßœ∑≈', 'unkn0wn enc0ding'), 10);
|
||||
|
||||
// base64
|
||||
assert.equal(Buffer.byteLength('aGVsbG8gd29ybGQ=', 'base64'), 11);
|
||||
assert.equal(Buffer.byteLength('bm9kZS5qcyByb2NrcyE=', 'base64'), 14);
|
||||
assert.equal(Buffer.byteLength('aGkk', 'base64'), 3);
|
||||
assert.equal(Buffer.byteLength('bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw==',
|
||||
'base64'), 25);
|
||||
// special padding
|
||||
assert.equal(Buffer.byteLength('aaa=', 'base64'), 2);
|
||||
assert.equal(Buffer.byteLength('aaaa==', 'base64'), 3);
|
||||
|
||||
assert.equal(Buffer.byteLength('Il était tué'), 14);
|
||||
assert.equal(Buffer.byteLength('Il était tué', 'utf8'), 14);
|
||||
assert.equal(Buffer.byteLength('Il était tué', 'ascii'), 12);
|
||||
assert.equal(Buffer.byteLength('Il était tué', 'latin1'), 12);
|
||||
assert.equal(Buffer.byteLength('Il était tué', 'binary'), 12);
|
||||
['ucs2', 'ucs-2', 'utf16le', 'utf-16le'].forEach(function(encoding) {
|
||||
assert.equal(24, Buffer.byteLength('Il était tué', encoding));
|
||||
});
|
||||
|
66
node_modules/buffer/test/node/test-buffer-compare-offset.js
generated
vendored
Normal file
66
node_modules/buffer/test/node/test-buffer-compare-offset.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var a = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]);
|
||||
var b = Buffer.from([5, 6, 7, 8, 9, 0, 1, 2, 3, 4]);
|
||||
|
||||
assert.equal(-1, a.compare(b));
|
||||
|
||||
// Equivalent to a.compare(b).
|
||||
assert.equal(-1, a.compare(b, 0));
|
||||
assert.equal(-1, a.compare(b, '0'));
|
||||
|
||||
// Equivalent to a.compare(b).
|
||||
assert.equal(-1, a.compare(b, 0, undefined, 0));
|
||||
|
||||
// Zero-length targer, return 1
|
||||
assert.equal(1, a.compare(b, 0, 0, 0));
|
||||
assert.equal(1, a.compare(b, '0', '0', '0'));
|
||||
|
||||
// Equivalent to Buffer.compare(a, b.slice(6, 10))
|
||||
assert.equal(1, a.compare(b, 6, 10));
|
||||
|
||||
// Zero-length source, return -1
|
||||
assert.equal(-1, a.compare(b, 6, 10, 0, 0));
|
||||
|
||||
// Equivalent to Buffer.compare(a.slice(4), b.slice(0, 5))
|
||||
assert.equal(1, a.compare(b, 0, 5, 4));
|
||||
|
||||
// Equivalent to Buffer.compare(a.slice(1), b.slice(5))
|
||||
assert.equal(1, a.compare(b, 5, undefined, 1));
|
||||
|
||||
// Equivalent to Buffer.compare(a.slice(2), b.slice(2, 4))
|
||||
assert.equal(-1, a.compare(b, 2, 4, 2));
|
||||
|
||||
// Equivalent to Buffer.compare(a.slice(4), b.slice(0, 7))
|
||||
assert.equal(-1, a.compare(b, 0, 7, 4));
|
||||
|
||||
// Equivalent to Buffer.compare(a.slice(4, 6), b.slice(0, 7));
|
||||
assert.equal(-1, a.compare(b, 0, 7, 4, 6));
|
||||
|
||||
// zero length target
|
||||
assert.equal(1, a.compare(b, 0, null));
|
||||
|
||||
// coerces to targetEnd == 5
|
||||
assert.equal(-1, a.compare(b, 0, {valueOf: () => 5}));
|
||||
|
||||
// zero length target
|
||||
assert.equal(1, a.compare(b, Infinity, -Infinity));
|
||||
|
||||
// zero length target because default for targetEnd <= targetSource
|
||||
assert.equal(1, a.compare(b, '0xff'));
|
||||
|
||||
var oor = /out of range index/;
|
||||
|
||||
assert.throws(() => a.compare(b, 0, 100, 0), oor);
|
||||
assert.throws(() => a.compare(b, 0, 1, 0, 100), oor);
|
||||
assert.throws(() => a.compare(b, -1), oor);
|
||||
assert.throws(() => a.compare(b, 0, '0xff'), oor);
|
||||
assert.throws(() => a.compare(b, 0, Infinity), oor);
|
||||
assert.throws(() => a.compare(b, -Infinity, Infinity), oor);
|
||||
assert.throws(() => a.compare(), /Argument must be a Buffer/);
|
||||
|
40
node_modules/buffer/test/node/test-buffer-concat.js
generated
vendored
Normal file
40
node_modules/buffer/test/node/test-buffer-concat.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var zero = [];
|
||||
var one = [ Buffer.from('asdf') ];
|
||||
var long = [];
|
||||
for (var i = 0; i < 10; i++) long.push(Buffer.from('asdf'));
|
||||
|
||||
var flatZero = Buffer.concat(zero);
|
||||
var flatOne = Buffer.concat(one);
|
||||
var flatLong = Buffer.concat(long);
|
||||
var flatLongLen = Buffer.concat(long, 40);
|
||||
|
||||
assert(flatZero.length === 0);
|
||||
assert(flatOne.toString() === 'asdf');
|
||||
// A special case where concat used to return the first item,
|
||||
// if the length is one. This check is to make sure that we don't do that.
|
||||
assert(flatOne !== one[0]);
|
||||
assert(flatLong.toString() === (new Array(10 + 1).join('asdf')));
|
||||
assert(flatLongLen.toString() === (new Array(10 + 1).join('asdf')));
|
||||
|
||||
assertWrongList();
|
||||
assertWrongList(null);
|
||||
assertWrongList(Buffer.from('hello'));
|
||||
assertWrongList([42]);
|
||||
assertWrongList(['hello', 'world']);
|
||||
assertWrongList(['hello', Buffer.from('world')]);
|
||||
|
||||
function assertWrongList(value) {
|
||||
assert.throws(function() {
|
||||
Buffer.concat(value);
|
||||
}, function(err) {
|
||||
return err instanceof TypeError &&
|
||||
err.message === '"list" argument must be an Array of Buffers';
|
||||
});
|
||||
}
|
||||
|
272
node_modules/buffer/test/node/test-buffer-fill.js
generated
vendored
Normal file
272
node_modules/buffer/test/node/test-buffer-fill.js
generated
vendored
Normal file
@@ -0,0 +1,272 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var os = require('os');
|
||||
var SIZE = 28;
|
||||
|
||||
var buf1 = Buffer.allocUnsafe(SIZE);
|
||||
var buf2 = Buffer.allocUnsafe(SIZE);
|
||||
|
||||
|
||||
// Default encoding
|
||||
testBufs('abc');
|
||||
testBufs('\u0222aa');
|
||||
testBufs('a\u0234b\u0235c\u0236');
|
||||
testBufs('abc', 4);
|
||||
testBufs('abc', 5);
|
||||
testBufs('abc', SIZE);
|
||||
testBufs('\u0222aa', 2);
|
||||
testBufs('\u0222aa', 8);
|
||||
testBufs('a\u0234b\u0235c\u0236', 4);
|
||||
testBufs('a\u0234b\u0235c\u0236', 12);
|
||||
testBufs('abc', 4, -1);
|
||||
testBufs('abc', 4, 1);
|
||||
testBufs('abc', 5, 1);
|
||||
testBufs('\u0222aa', 2, -1);
|
||||
testBufs('\u0222aa', 8, 1);
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, -1);
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, 1);
|
||||
testBufs('a\u0234b\u0235c\u0236', 12, 1);
|
||||
|
||||
|
||||
// UTF8
|
||||
testBufs('abc', 'utf8');
|
||||
testBufs('\u0222aa', 'utf8');
|
||||
testBufs('a\u0234b\u0235c\u0236', 'utf8');
|
||||
testBufs('abc', 4, 'utf8');
|
||||
testBufs('abc', 5, 'utf8');
|
||||
testBufs('abc', SIZE, 'utf8');
|
||||
testBufs('\u0222aa', 2, 'utf8');
|
||||
testBufs('\u0222aa', 8, 'utf8');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, 'utf8');
|
||||
testBufs('a\u0234b\u0235c\u0236', 12, 'utf8');
|
||||
testBufs('abc', 4, -1, 'utf8');
|
||||
testBufs('abc', 4, 1, 'utf8');
|
||||
testBufs('abc', 5, 1, 'utf8');
|
||||
testBufs('\u0222aa', 2, -1, 'utf8');
|
||||
testBufs('\u0222aa', 8, 1, 'utf8');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, -1, 'utf8');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, 1, 'utf8');
|
||||
testBufs('a\u0234b\u0235c\u0236', 12, 1, 'utf8');
|
||||
assert.equal(Buffer.allocUnsafe(1).fill(0).fill('\u0222')[0], 0xc8);
|
||||
|
||||
|
||||
// BINARY
|
||||
testBufs('abc', 'binary');
|
||||
testBufs('\u0222aa', 'binary');
|
||||
testBufs('a\u0234b\u0235c\u0236', 'binary');
|
||||
testBufs('abc', 4, 'binary');
|
||||
testBufs('abc', 5, 'binary');
|
||||
testBufs('abc', SIZE, 'binary');
|
||||
testBufs('\u0222aa', 2, 'binary');
|
||||
testBufs('\u0222aa', 8, 'binary');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, 'binary');
|
||||
testBufs('a\u0234b\u0235c\u0236', 12, 'binary');
|
||||
testBufs('abc', 4, -1, 'binary');
|
||||
testBufs('abc', 4, 1, 'binary');
|
||||
testBufs('abc', 5, 1, 'binary');
|
||||
testBufs('\u0222aa', 2, -1, 'binary');
|
||||
testBufs('\u0222aa', 8, 1, 'binary');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, -1, 'binary');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, 1, 'binary');
|
||||
testBufs('a\u0234b\u0235c\u0236', 12, 1, 'binary');
|
||||
|
||||
|
||||
// LATIN1
|
||||
testBufs('abc', 'latin1');
|
||||
testBufs('\u0222aa', 'latin1');
|
||||
testBufs('a\u0234b\u0235c\u0236', 'latin1');
|
||||
testBufs('abc', 4, 'latin1');
|
||||
testBufs('abc', 5, 'latin1');
|
||||
testBufs('abc', SIZE, 'latin1');
|
||||
testBufs('\u0222aa', 2, 'latin1');
|
||||
testBufs('\u0222aa', 8, 'latin1');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, 'latin1');
|
||||
testBufs('a\u0234b\u0235c\u0236', 12, 'latin1');
|
||||
testBufs('abc', 4, -1, 'latin1');
|
||||
testBufs('abc', 4, 1, 'latin1');
|
||||
testBufs('abc', 5, 1, 'latin1');
|
||||
testBufs('\u0222aa', 2, -1, 'latin1');
|
||||
testBufs('\u0222aa', 8, 1, 'latin1');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, -1, 'latin1');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, 1, 'latin1');
|
||||
testBufs('a\u0234b\u0235c\u0236', 12, 1, 'latin1');
|
||||
|
||||
|
||||
// UCS2
|
||||
testBufs('abc', 'ucs2');
|
||||
testBufs('\u0222aa', 'ucs2');
|
||||
testBufs('a\u0234b\u0235c\u0236', 'ucs2');
|
||||
testBufs('abc', 4, 'ucs2');
|
||||
testBufs('abc', SIZE, 'ucs2');
|
||||
testBufs('\u0222aa', 2, 'ucs2');
|
||||
testBufs('\u0222aa', 8, 'ucs2');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, 'ucs2');
|
||||
testBufs('a\u0234b\u0235c\u0236', 12, 'ucs2');
|
||||
testBufs('abc', 4, -1, 'ucs2');
|
||||
testBufs('abc', 4, 1, 'ucs2');
|
||||
testBufs('abc', 5, 1, 'ucs2');
|
||||
testBufs('\u0222aa', 2, -1, 'ucs2');
|
||||
testBufs('\u0222aa', 8, 1, 'ucs2');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, -1, 'ucs2');
|
||||
testBufs('a\u0234b\u0235c\u0236', 4, 1, 'ucs2');
|
||||
testBufs('a\u0234b\u0235c\u0236', 12, 1, 'ucs2');
|
||||
assert.equal(Buffer.allocUnsafe(1).fill('\u0222', 'ucs2')[0],
|
||||
os.endianness() === 'LE' ? 0x22 : 0x02);
|
||||
|
||||
|
||||
// HEX
|
||||
testBufs('616263', 'hex');
|
||||
testBufs('c8a26161', 'hex');
|
||||
testBufs('61c8b462c8b563c8b6', 'hex');
|
||||
testBufs('616263', 4, 'hex');
|
||||
testBufs('616263', 5, 'hex');
|
||||
testBufs('616263', SIZE, 'hex');
|
||||
testBufs('c8a26161', 2, 'hex');
|
||||
testBufs('c8a26161', 8, 'hex');
|
||||
testBufs('61c8b462c8b563c8b6', 4, 'hex');
|
||||
testBufs('61c8b462c8b563c8b6', 12, 'hex');
|
||||
testBufs('616263', 4, -1, 'hex');
|
||||
testBufs('616263', 4, 1, 'hex');
|
||||
testBufs('616263', 5, 1, 'hex');
|
||||
testBufs('c8a26161', 2, -1, 'hex');
|
||||
testBufs('c8a26161', 8, 1, 'hex');
|
||||
testBufs('61c8b462c8b563c8b6', 4, -1, 'hex');
|
||||
testBufs('61c8b462c8b563c8b6', 4, 1, 'hex');
|
||||
testBufs('61c8b462c8b563c8b6', 12, 1, 'hex');
|
||||
// Make sure this operation doesn't go on forever
|
||||
buf1.fill('yKJh', 'hex');
|
||||
assert.throws(() => buf1.fill('\u0222', 'hex'));
|
||||
|
||||
|
||||
// BASE64
|
||||
testBufs('YWJj', 'ucs2');
|
||||
testBufs('yKJhYQ==', 'ucs2');
|
||||
testBufs('Yci0Ysi1Y8i2', 'ucs2');
|
||||
testBufs('YWJj', 4, 'ucs2');
|
||||
testBufs('YWJj', SIZE, 'ucs2');
|
||||
testBufs('yKJhYQ==', 2, 'ucs2');
|
||||
testBufs('yKJhYQ==', 8, 'ucs2');
|
||||
testBufs('Yci0Ysi1Y8i2', 4, 'ucs2');
|
||||
testBufs('Yci0Ysi1Y8i2', 12, 'ucs2');
|
||||
testBufs('YWJj', 4, -1, 'ucs2');
|
||||
testBufs('YWJj', 4, 1, 'ucs2');
|
||||
testBufs('YWJj', 5, 1, 'ucs2');
|
||||
testBufs('yKJhYQ==', 2, -1, 'ucs2');
|
||||
testBufs('yKJhYQ==', 8, 1, 'ucs2');
|
||||
testBufs('Yci0Ysi1Y8i2', 4, -1, 'ucs2');
|
||||
testBufs('Yci0Ysi1Y8i2', 4, 1, 'ucs2');
|
||||
testBufs('Yci0Ysi1Y8i2', 12, 1, 'ucs2');
|
||||
|
||||
|
||||
// Buffer
|
||||
function deepStrictEqualValues(buf, arr) {
|
||||
for (var [index, value] of buf.entries()) {
|
||||
assert.deepStrictEqual(value, arr[index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var buf2Fill = Buffer.allocUnsafe(1).fill(2);
|
||||
deepStrictEqualValues(genBuffer(4, [buf2Fill]), [2, 2, 2, 2]);
|
||||
deepStrictEqualValues(genBuffer(4, [buf2Fill, 1]), [0, 2, 2, 2]);
|
||||
deepStrictEqualValues(genBuffer(4, [buf2Fill, 1, 3]), [0, 2, 2, 0]);
|
||||
deepStrictEqualValues(genBuffer(4, [buf2Fill, 1, 1]), [0, 0, 0, 0]);
|
||||
deepStrictEqualValues(genBuffer(4, [buf2Fill, 1, -1]), [0, 0, 0, 0]);
|
||||
var hexBufFill = Buffer.allocUnsafe(2).fill(0).fill('0102', 'hex');
|
||||
deepStrictEqualValues(genBuffer(4, [hexBufFill]), [1, 2, 1, 2]);
|
||||
deepStrictEqualValues(genBuffer(4, [hexBufFill, 1]), [0, 1, 2, 1]);
|
||||
deepStrictEqualValues(genBuffer(4, [hexBufFill, 1, 3]), [0, 1, 2, 0]);
|
||||
deepStrictEqualValues(genBuffer(4, [hexBufFill, 1, 1]), [0, 0, 0, 0]);
|
||||
deepStrictEqualValues(genBuffer(4, [hexBufFill, 1, -1]), [0, 0, 0, 0]);
|
||||
|
||||
|
||||
// Check exceptions
|
||||
assert.throws(() => buf1.fill(0, -1));
|
||||
assert.throws(() => buf1.fill(0, 0, buf1.length + 1));
|
||||
assert.throws(() => buf1.fill('', -1));
|
||||
assert.throws(() => buf1.fill('', 0, buf1.length + 1));
|
||||
assert.throws(() => buf1.fill('a', 0, buf1.length, 'node rocks!'));
|
||||
assert.throws(() => buf1.fill('a', 0, 0, NaN));
|
||||
assert.throws(() => buf1.fill('a', 0, 0, null));
|
||||
assert.throws(() => buf1.fill('a', 0, 0, 'foo'));
|
||||
|
||||
|
||||
function genBuffer(size, args) {
|
||||
var b = Buffer.allocUnsafe(size);
|
||||
return b.fill(0).fill.apply(b, args);
|
||||
}
|
||||
|
||||
|
||||
function bufReset() {
|
||||
buf1.fill(0);
|
||||
buf2.fill(0);
|
||||
}
|
||||
|
||||
|
||||
// This is mostly accurate. Except write() won't write partial bytes to the
|
||||
// string while fill() blindly copies bytes into memory. To account for that an
|
||||
// error will be thrown if not all the data can be written, and the SIZE has
|
||||
// been massaged to work with the input characters.
|
||||
function writeToFill(string, offset, end, encoding) {
|
||||
if (typeof offset === 'string') {
|
||||
encoding = offset;
|
||||
offset = 0;
|
||||
end = buf2.length;
|
||||
} else if (typeof end === 'string') {
|
||||
encoding = end;
|
||||
end = buf2.length;
|
||||
} else if (end === undefined) {
|
||||
end = buf2.length;
|
||||
}
|
||||
|
||||
if (offset < 0 || end > buf2.length)
|
||||
throw new RangeError('Out of range index');
|
||||
|
||||
if (end <= offset)
|
||||
return buf2;
|
||||
|
||||
offset >>>= 0;
|
||||
end >>>= 0;
|
||||
assert(offset <= buf2.length);
|
||||
|
||||
// Convert "end" to "length" (which write understands).
|
||||
var length = end - offset < 0 ? 0 : end - offset;
|
||||
|
||||
var wasZero = false;
|
||||
do {
|
||||
var written = buf2.write(string, offset, length, encoding);
|
||||
offset += written;
|
||||
// Safety check in case write falls into infinite loop.
|
||||
if (written === 0) {
|
||||
if (wasZero)
|
||||
throw new Error('Could not write all data to Buffer');
|
||||
else
|
||||
wasZero = true;
|
||||
}
|
||||
} while (offset < buf2.length);
|
||||
|
||||
// Correction for UCS2 operations.
|
||||
if (os.endianness() === 'BE' && encoding === 'ucs2') {
|
||||
for (var i = 0; i < buf2.length; i += 2) {
|
||||
var tmp = buf2[i];
|
||||
buf2[i] = buf2[i + 1];
|
||||
buf2[i + 1] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return buf2;
|
||||
}
|
||||
|
||||
|
||||
function testBufs(string, offset, length, encoding) {
|
||||
bufReset();
|
||||
buf1.fill.apply(buf1, arguments);
|
||||
// Swap bytes on BE archs for ucs2 encoding.
|
||||
assert.deepStrictEqual(buf1.fill.apply(buf1, arguments),
|
||||
writeToFill.apply(null, arguments));
|
||||
}
|
||||
|
305
node_modules/buffer/test/node/test-buffer-includes.js
generated
vendored
Normal file
305
node_modules/buffer/test/node/test-buffer-includes.js
generated
vendored
Normal file
@@ -0,0 +1,305 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
var b = Buffer.from('abcdef');
|
||||
var buf_a = Buffer.from('a');
|
||||
var buf_bc = Buffer.from('bc');
|
||||
var buf_f = Buffer.from('f');
|
||||
var buf_z = Buffer.from('z');
|
||||
var buf_empty = Buffer.from('');
|
||||
|
||||
assert(b.includes('a'));
|
||||
assert(!b.includes('a', 1));
|
||||
assert(!b.includes('a', -1));
|
||||
assert(!b.includes('a', -4));
|
||||
assert(b.includes('a', -b.length));
|
||||
assert(b.includes('a', NaN));
|
||||
assert(b.includes('a', -Infinity));
|
||||
assert(!b.includes('a', Infinity));
|
||||
assert(b.includes('bc'));
|
||||
assert(!b.includes('bc', 2));
|
||||
assert(!b.includes('bc', -1));
|
||||
assert(!b.includes('bc', -3));
|
||||
assert(b.includes('bc', -5));
|
||||
assert(b.includes('bc', NaN));
|
||||
assert(b.includes('bc', -Infinity));
|
||||
assert(!b.includes('bc', Infinity));
|
||||
assert(b.includes('f'), b.length - 1);
|
||||
assert(!b.includes('z'));
|
||||
assert(!b.includes(''));
|
||||
assert(!b.includes('', 1));
|
||||
assert(!b.includes('', b.length + 1));
|
||||
assert(!b.includes('', Infinity));
|
||||
assert(b.includes(buf_a));
|
||||
assert(!b.includes(buf_a, 1));
|
||||
assert(!b.includes(buf_a, -1));
|
||||
assert(!b.includes(buf_a, -4));
|
||||
assert(b.includes(buf_a, -b.length));
|
||||
assert(b.includes(buf_a, NaN));
|
||||
assert(b.includes(buf_a, -Infinity));
|
||||
assert(!b.includes(buf_a, Infinity));
|
||||
assert(b.includes(buf_bc));
|
||||
assert(!b.includes(buf_bc, 2));
|
||||
assert(!b.includes(buf_bc, -1));
|
||||
assert(!b.includes(buf_bc, -3));
|
||||
assert(b.includes(buf_bc, -5));
|
||||
assert(b.includes(buf_bc, NaN));
|
||||
assert(b.includes(buf_bc, -Infinity));
|
||||
assert(!b.includes(buf_bc, Infinity));
|
||||
assert(b.includes(buf_f), b.length - 1);
|
||||
assert(!b.includes(buf_z));
|
||||
assert(!b.includes(buf_empty));
|
||||
assert(!b.includes(buf_empty, 1));
|
||||
assert(!b.includes(buf_empty, b.length + 1));
|
||||
assert(!b.includes(buf_empty, Infinity));
|
||||
assert(b.includes(0x61));
|
||||
assert(!b.includes(0x61, 1));
|
||||
assert(!b.includes(0x61, -1));
|
||||
assert(!b.includes(0x61, -4));
|
||||
assert(b.includes(0x61, -b.length));
|
||||
assert(b.includes(0x61, NaN));
|
||||
assert(b.includes(0x61, -Infinity));
|
||||
assert(!b.includes(0x61, Infinity));
|
||||
assert(!b.includes(0x0));
|
||||
|
||||
// test offsets
|
||||
assert(b.includes('d', 2));
|
||||
assert(b.includes('f', 5));
|
||||
assert(b.includes('f', -1));
|
||||
assert(!b.includes('f', 6));
|
||||
|
||||
assert(b.includes(Buffer.from('d'), 2));
|
||||
assert(b.includes(Buffer.from('f'), 5));
|
||||
assert(b.includes(Buffer.from('f'), -1));
|
||||
assert(!b.includes(Buffer.from('f'), 6));
|
||||
|
||||
assert(!Buffer.from('ff').includes(Buffer.from('f'), 1, 'ucs2'));
|
||||
|
||||
// test hex encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('hex'), 'hex')
|
||||
.includes('64', 0, 'hex'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('hex'), 'hex')
|
||||
.includes(Buffer.from('64', 'hex'), 0, 'hex'),
|
||||
true
|
||||
);
|
||||
|
||||
// test base64 encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('base64'), 'base64')
|
||||
.includes('ZA==', 0, 'base64'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('base64'), 'base64')
|
||||
.includes(Buffer.from('ZA==', 'base64'), 0, 'base64'),
|
||||
true
|
||||
);
|
||||
|
||||
// test ascii encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('ascii'), 'ascii')
|
||||
.includes('d', 0, 'ascii'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('ascii'), 'ascii')
|
||||
.includes(Buffer.from('d', 'ascii'), 0, 'ascii'),
|
||||
true
|
||||
);
|
||||
|
||||
// test latin1 encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('latin1'), 'latin1')
|
||||
.includes('d', 0, 'latin1'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('latin1'), 'latin1')
|
||||
.includes(Buffer.from('d', 'latin1'), 0, 'latin1'),
|
||||
true
|
||||
);
|
||||
|
||||
// test binary encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('binary'), 'binary')
|
||||
.includes('d', 0, 'binary'),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('binary'), 'binary')
|
||||
.includes(Buffer.from('d', 'binary'), 0, 'binary'),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
// test usc2 encoding
|
||||
var twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
|
||||
|
||||
assert(twoByteString.includes('\u0395', 4, 'ucs2'));
|
||||
assert(twoByteString.includes('\u03a3', -4, 'ucs2'));
|
||||
assert(twoByteString.includes('\u03a3', -6, 'ucs2'));
|
||||
assert(twoByteString.includes(
|
||||
Buffer.from('\u03a3', 'ucs2'), -6, 'ucs2'));
|
||||
assert(!twoByteString.includes('\u03a3', -2, 'ucs2'));
|
||||
|
||||
var mixedByteStringUcs2 =
|
||||
Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395', 'ucs2');
|
||||
assert(mixedByteStringUcs2.includes('bc', 0, 'ucs2'));
|
||||
assert(mixedByteStringUcs2.includes('\u03a3', 0, 'ucs2'));
|
||||
assert(!mixedByteStringUcs2.includes('\u0396', 0, 'ucs2'));
|
||||
|
||||
assert(
|
||||
6, mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2'));
|
||||
assert(
|
||||
10, mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'),
|
||||
0, 'ucs2'));
|
||||
assert(
|
||||
-1, mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'),
|
||||
0, 'ucs2'));
|
||||
|
||||
twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
|
||||
|
||||
// Test single char pattern
|
||||
assert(twoByteString.includes('\u039a', 0, 'ucs2'));
|
||||
assert(twoByteString.includes('\u0391', 0, 'ucs2'), 'Alpha');
|
||||
assert(twoByteString.includes('\u03a3', 0, 'ucs2'), 'First Sigma');
|
||||
assert(twoByteString.includes('\u03a3', 6, 'ucs2'), 'Second Sigma');
|
||||
assert(twoByteString.includes('\u0395', 0, 'ucs2'), 'Epsilon');
|
||||
assert(!twoByteString.includes('\u0392', 0, 'ucs2'), 'Not beta');
|
||||
|
||||
// Test multi-char pattern
|
||||
assert(twoByteString.includes('\u039a\u0391', 0, 'ucs2'), 'Lambda Alpha');
|
||||
assert(twoByteString.includes('\u0391\u03a3', 0, 'ucs2'), 'Alpha Sigma');
|
||||
assert(twoByteString.includes('\u03a3\u03a3', 0, 'ucs2'), 'Sigma Sigma');
|
||||
assert(twoByteString.includes('\u03a3\u0395', 0, 'ucs2'), 'Sigma Epsilon');
|
||||
|
||||
var mixedByteStringUtf8 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395');
|
||||
assert(mixedByteStringUtf8.includes('bc'));
|
||||
assert(mixedByteStringUtf8.includes('bc', 5));
|
||||
assert(mixedByteStringUtf8.includes('bc', -8));
|
||||
assert(mixedByteStringUtf8.includes('\u03a3'));
|
||||
assert(!mixedByteStringUtf8.includes('\u0396'));
|
||||
|
||||
|
||||
// Test complex string includes algorithms. Only trigger for long strings.
|
||||
// Long string that isn't a simple repeat of a shorter string.
|
||||
var longString = 'A';
|
||||
for (var i = 66; i < 76; i++) { // from 'B' to 'K'
|
||||
longString = longString + String.fromCharCode(i) + longString;
|
||||
}
|
||||
|
||||
var longBufferString = Buffer.from(longString);
|
||||
|
||||
// pattern of 15 chars, repeated every 16 chars in long
|
||||
var pattern = 'ABACABADABACABA';
|
||||
for (var i = 0; i < longBufferString.length - pattern.length; i += 7) {
|
||||
var includes = longBufferString.includes(pattern, i);
|
||||
assert(includes, 'Long ABACABA...-string at index ' + i);
|
||||
}
|
||||
assert(longBufferString.includes('AJABACA'), 'Long AJABACA, First J');
|
||||
assert(longBufferString.includes('AJABACA', 511), 'Long AJABACA, Second J');
|
||||
|
||||
pattern = 'JABACABADABACABA';
|
||||
assert(longBufferString.includes(pattern), 'Long JABACABA..., First J');
|
||||
assert(longBufferString.includes(pattern, 512), 'Long JABACABA..., Second J');
|
||||
|
||||
// Search for a non-ASCII string in a pure ASCII string.
|
||||
var asciiString = Buffer.from(
|
||||
'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf');
|
||||
assert(!asciiString.includes('\x2061'));
|
||||
assert(asciiString.includes('leb', 0));
|
||||
|
||||
// Search in string containing many non-ASCII chars.
|
||||
var allCodePoints = [];
|
||||
for (var i = 0; i < 65536; i++) allCodePoints[i] = i;
|
||||
var allCharsString = String.fromCharCode.apply(String, allCodePoints);
|
||||
var allCharsBufferUtf8 = Buffer.from(allCharsString);
|
||||
var allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2');
|
||||
|
||||
// Search for string long enough to trigger complex search with ASCII pattern
|
||||
// and UC16 subject.
|
||||
assert(!allCharsBufferUtf8.includes('notfound'));
|
||||
assert(!allCharsBufferUcs2.includes('notfound'));
|
||||
|
||||
// Find substrings in Utf8.
|
||||
var lengths = [1, 3, 15]; // Single char, simple and complex.
|
||||
var indices = [0x5, 0x60, 0x400, 0x680, 0x7ee, 0xFF02, 0x16610, 0x2f77b];
|
||||
for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
|
||||
for (var i = 0; i < indices.length; i++) {
|
||||
var index = indices[i];
|
||||
var length = lengths[lengthIndex];
|
||||
|
||||
if (index + length > 0x7F) {
|
||||
length = 2 * length;
|
||||
}
|
||||
|
||||
if (index + length > 0x7FF) {
|
||||
length = 3 * length;
|
||||
}
|
||||
|
||||
if (index + length > 0xFFFF) {
|
||||
length = 4 * length;
|
||||
}
|
||||
|
||||
var patternBufferUtf8 = allCharsBufferUtf8.slice(index, index + length);
|
||||
assert(index, allCharsBufferUtf8.includes(patternBufferUtf8));
|
||||
|
||||
var patternStringUtf8 = patternBufferUtf8.toString();
|
||||
assert(index, allCharsBufferUtf8.includes(patternStringUtf8));
|
||||
}
|
||||
}
|
||||
|
||||
// Find substrings in Usc2.
|
||||
lengths = [2, 4, 16]; // Single char, simple and complex.
|
||||
indices = [0x5, 0x65, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0];
|
||||
for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
|
||||
for (var i = 0; i < indices.length; i++) {
|
||||
var index = indices[i] * 2;
|
||||
var length = lengths[lengthIndex];
|
||||
|
||||
var patternBufferUcs2 =
|
||||
allCharsBufferUcs2.slice(index, index + length);
|
||||
assert(
|
||||
index, allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2'));
|
||||
|
||||
var patternStringUcs2 = patternBufferUcs2.toString('ucs2');
|
||||
assert(
|
||||
index, allCharsBufferUcs2.includes(patternStringUcs2, 0, 'ucs2'));
|
||||
}
|
||||
}
|
||||
|
||||
assert.throws(function() {
|
||||
b.includes(function() { });
|
||||
});
|
||||
assert.throws(function() {
|
||||
b.includes({});
|
||||
});
|
||||
assert.throws(function() {
|
||||
b.includes([]);
|
||||
});
|
||||
|
||||
// test truncation of Number arguments to uint8
|
||||
{
|
||||
var buf = Buffer.from('this is a test');
|
||||
assert.ok(buf.includes(0x6973));
|
||||
assert.ok(buf.includes(0x697320));
|
||||
assert.ok(buf.includes(0x69732069));
|
||||
assert.ok(buf.includes(0x697374657374));
|
||||
assert.ok(buf.includes(0x69737374));
|
||||
assert.ok(buf.includes(0x69737465));
|
||||
assert.ok(buf.includes(0x69737465));
|
||||
assert.ok(buf.includes(-140));
|
||||
assert.ok(buf.includes(-152));
|
||||
assert.ok(!buf.includes(0xff));
|
||||
assert.ok(!buf.includes(0xffff));
|
||||
}
|
||||
|
523
node_modules/buffer/test/node/test-buffer-indexof.js
generated
vendored
Normal file
523
node_modules/buffer/test/node/test-buffer-indexof.js
generated
vendored
Normal file
@@ -0,0 +1,523 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
var b = Buffer.from('abcdef');
|
||||
var buf_a = Buffer.from('a');
|
||||
var buf_bc = Buffer.from('bc');
|
||||
var buf_f = Buffer.from('f');
|
||||
var buf_z = Buffer.from('z');
|
||||
var buf_empty = Buffer.from('');
|
||||
|
||||
assert.equal(b.indexOf('a'), 0);
|
||||
assert.equal(b.indexOf('a', 1), -1);
|
||||
assert.equal(b.indexOf('a', -1), -1);
|
||||
assert.equal(b.indexOf('a', -4), -1);
|
||||
assert.equal(b.indexOf('a', -b.length), 0);
|
||||
assert.equal(b.indexOf('a', NaN), 0);
|
||||
assert.equal(b.indexOf('a', -Infinity), 0);
|
||||
assert.equal(b.indexOf('a', Infinity), -1);
|
||||
assert.equal(b.indexOf('bc'), 1);
|
||||
assert.equal(b.indexOf('bc', 2), -1);
|
||||
assert.equal(b.indexOf('bc', -1), -1);
|
||||
assert.equal(b.indexOf('bc', -3), -1);
|
||||
assert.equal(b.indexOf('bc', -5), 1);
|
||||
assert.equal(b.indexOf('bc', NaN), 1);
|
||||
assert.equal(b.indexOf('bc', -Infinity), 1);
|
||||
assert.equal(b.indexOf('bc', Infinity), -1);
|
||||
assert.equal(b.indexOf('f'), b.length - 1);
|
||||
assert.equal(b.indexOf('z'), -1);
|
||||
assert.equal(b.indexOf(''), -1);
|
||||
assert.equal(b.indexOf('', 1), -1);
|
||||
assert.equal(b.indexOf('', b.length + 1), -1);
|
||||
assert.equal(b.indexOf('', Infinity), -1);
|
||||
assert.equal(b.indexOf(buf_a), 0);
|
||||
assert.equal(b.indexOf(buf_a, 1), -1);
|
||||
assert.equal(b.indexOf(buf_a, -1), -1);
|
||||
assert.equal(b.indexOf(buf_a, -4), -1);
|
||||
assert.equal(b.indexOf(buf_a, -b.length), 0);
|
||||
assert.equal(b.indexOf(buf_a, NaN), 0);
|
||||
assert.equal(b.indexOf(buf_a, -Infinity), 0);
|
||||
assert.equal(b.indexOf(buf_a, Infinity), -1);
|
||||
assert.equal(b.indexOf(buf_bc), 1);
|
||||
assert.equal(b.indexOf(buf_bc, 2), -1);
|
||||
assert.equal(b.indexOf(buf_bc, -1), -1);
|
||||
assert.equal(b.indexOf(buf_bc, -3), -1);
|
||||
assert.equal(b.indexOf(buf_bc, -5), 1);
|
||||
assert.equal(b.indexOf(buf_bc, NaN), 1);
|
||||
assert.equal(b.indexOf(buf_bc, -Infinity), 1);
|
||||
assert.equal(b.indexOf(buf_bc, Infinity), -1);
|
||||
assert.equal(b.indexOf(buf_f), b.length - 1);
|
||||
assert.equal(b.indexOf(buf_z), -1);
|
||||
assert.equal(b.indexOf(buf_empty), -1);
|
||||
assert.equal(b.indexOf(buf_empty, 1), -1);
|
||||
assert.equal(b.indexOf(buf_empty, b.length + 1), -1);
|
||||
assert.equal(b.indexOf(buf_empty, Infinity), -1);
|
||||
assert.equal(b.indexOf(0x61), 0);
|
||||
assert.equal(b.indexOf(0x61, 1), -1);
|
||||
assert.equal(b.indexOf(0x61, -1), -1);
|
||||
assert.equal(b.indexOf(0x61, -4), -1);
|
||||
assert.equal(b.indexOf(0x61, -b.length), 0);
|
||||
assert.equal(b.indexOf(0x61, NaN), 0);
|
||||
assert.equal(b.indexOf(0x61, -Infinity), 0);
|
||||
assert.equal(b.indexOf(0x61, Infinity), -1);
|
||||
assert.equal(b.indexOf(0x0), -1);
|
||||
|
||||
// test offsets
|
||||
assert.equal(b.indexOf('d', 2), 3);
|
||||
assert.equal(b.indexOf('f', 5), 5);
|
||||
assert.equal(b.indexOf('f', -1), 5);
|
||||
assert.equal(b.indexOf('f', 6), -1);
|
||||
|
||||
assert.equal(b.indexOf(Buffer.from('d'), 2), 3);
|
||||
assert.equal(b.indexOf(Buffer.from('f'), 5), 5);
|
||||
assert.equal(b.indexOf(Buffer.from('f'), -1), 5);
|
||||
assert.equal(b.indexOf(Buffer.from('f'), 6), -1);
|
||||
|
||||
assert.equal(Buffer.from('ff').indexOf(Buffer.from('f'), 1, 'ucs2'), -1);
|
||||
|
||||
// test hex encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('hex'), 'hex')
|
||||
.indexOf('64', 0, 'hex'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('hex'), 'hex')
|
||||
.indexOf(Buffer.from('64', 'hex'), 0, 'hex'),
|
||||
3
|
||||
);
|
||||
|
||||
// test base64 encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('base64'), 'base64')
|
||||
.indexOf('ZA==', 0, 'base64'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('base64'), 'base64')
|
||||
.indexOf(Buffer.from('ZA==', 'base64'), 0, 'base64'),
|
||||
3
|
||||
);
|
||||
|
||||
// test ascii encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('ascii'), 'ascii')
|
||||
.indexOf('d', 0, 'ascii'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('ascii'), 'ascii')
|
||||
.indexOf(Buffer.from('d', 'ascii'), 0, 'ascii'),
|
||||
3
|
||||
);
|
||||
|
||||
// test latin1 encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('latin1'), 'latin1')
|
||||
.indexOf('d', 0, 'latin1'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('latin1'), 'latin1')
|
||||
.indexOf(Buffer.from('d', 'latin1'), 0, 'latin1'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('aa\u00e8aa', 'latin1')
|
||||
.indexOf('\u00e8', 'latin1'),
|
||||
2
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('\u00e8', 'latin1')
|
||||
.indexOf('\u00e8', 'latin1'),
|
||||
0
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('\u00e8', 'latin1')
|
||||
.indexOf(Buffer.from('\u00e8', 'latin1'), 'latin1'),
|
||||
0
|
||||
);
|
||||
|
||||
// test binary encoding
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('binary'), 'binary')
|
||||
.indexOf('d', 0, 'binary'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(b.toString('binary'), 'binary')
|
||||
.indexOf(Buffer.from('d', 'binary'), 0, 'binary'),
|
||||
3
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('aa\u00e8aa', 'binary')
|
||||
.indexOf('\u00e8', 'binary'),
|
||||
2
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('\u00e8', 'binary')
|
||||
.indexOf('\u00e8', 'binary'),
|
||||
0
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from('\u00e8', 'binary')
|
||||
.indexOf(Buffer.from('\u00e8', 'binary'), 'binary'),
|
||||
0
|
||||
);
|
||||
|
||||
|
||||
// test optional offset with passed encoding
|
||||
assert.equal(Buffer.from('aaaa0').indexOf('30', 'hex'), 4);
|
||||
assert.equal(Buffer.from('aaaa00a').indexOf('3030', 'hex'), 4);
|
||||
|
||||
{
|
||||
// test usc2 encoding
|
||||
var twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
|
||||
|
||||
assert.equal(8, twoByteString.indexOf('\u0395', 4, 'ucs2'));
|
||||
assert.equal(6, twoByteString.indexOf('\u03a3', -4, 'ucs2'));
|
||||
assert.equal(4, twoByteString.indexOf('\u03a3', -6, 'ucs2'));
|
||||
assert.equal(4, twoByteString.indexOf(
|
||||
Buffer.from('\u03a3', 'ucs2'), -6, 'ucs2'));
|
||||
assert.equal(-1, twoByteString.indexOf('\u03a3', -2, 'ucs2'));
|
||||
}
|
||||
|
||||
var mixedByteStringUcs2 =
|
||||
Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395', 'ucs2');
|
||||
assert.equal(6, mixedByteStringUcs2.indexOf('bc', 0, 'ucs2'));
|
||||
assert.equal(10, mixedByteStringUcs2.indexOf('\u03a3', 0, 'ucs2'));
|
||||
assert.equal(-1, mixedByteStringUcs2.indexOf('\u0396', 0, 'ucs2'));
|
||||
|
||||
assert.equal(
|
||||
6, mixedByteStringUcs2.indexOf(Buffer.from('bc', 'ucs2'), 0, 'ucs2'));
|
||||
assert.equal(
|
||||
10, mixedByteStringUcs2.indexOf(Buffer.from('\u03a3', 'ucs2'), 0, 'ucs2'));
|
||||
assert.equal(
|
||||
-1, mixedByteStringUcs2.indexOf(Buffer.from('\u0396', 'ucs2'), 0, 'ucs2'));
|
||||
|
||||
{
|
||||
var twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');
|
||||
|
||||
// Test single char pattern
|
||||
assert.equal(0, twoByteString.indexOf('\u039a', 0, 'ucs2'));
|
||||
assert.equal(2, twoByteString.indexOf('\u0391', 0, 'ucs2'), 'Alpha');
|
||||
assert.equal(4, twoByteString.indexOf('\u03a3', 0, 'ucs2'), 'First Sigma');
|
||||
assert.equal(6, twoByteString.indexOf('\u03a3', 6, 'ucs2'), 'Second Sigma');
|
||||
assert.equal(8, twoByteString.indexOf('\u0395', 0, 'ucs2'), 'Epsilon');
|
||||
assert.equal(-1, twoByteString.indexOf('\u0392', 0, 'ucs2'), 'Not beta');
|
||||
|
||||
// Test multi-char pattern
|
||||
assert.equal(
|
||||
0, twoByteString.indexOf('\u039a\u0391', 0, 'ucs2'), 'Lambda Alpha');
|
||||
assert.equal(
|
||||
2, twoByteString.indexOf('\u0391\u03a3', 0, 'ucs2'), 'Alpha Sigma');
|
||||
assert.equal(
|
||||
4, twoByteString.indexOf('\u03a3\u03a3', 0, 'ucs2'), 'Sigma Sigma');
|
||||
assert.equal(
|
||||
6, twoByteString.indexOf('\u03a3\u0395', 0, 'ucs2'), 'Sigma Epsilon');
|
||||
}
|
||||
|
||||
var mixedByteStringUtf8 = Buffer.from('\u039a\u0391abc\u03a3\u03a3\u0395');
|
||||
assert.equal(5, mixedByteStringUtf8.indexOf('bc'));
|
||||
assert.equal(5, mixedByteStringUtf8.indexOf('bc', 5));
|
||||
assert.equal(5, mixedByteStringUtf8.indexOf('bc', -8));
|
||||
assert.equal(7, mixedByteStringUtf8.indexOf('\u03a3'));
|
||||
assert.equal(-1, mixedByteStringUtf8.indexOf('\u0396'));
|
||||
|
||||
|
||||
// Test complex string indexOf algorithms. Only trigger for long strings.
|
||||
// Long string that isn't a simple repeat of a shorter string.
|
||||
var longString = 'A';
|
||||
for (var i = 66; i < 76; i++) { // from 'B' to 'K'
|
||||
longString = longString + String.fromCharCode(i) + longString;
|
||||
}
|
||||
|
||||
var longBufferString = Buffer.from(longString);
|
||||
|
||||
// pattern of 15 chars, repeated every 16 chars in long
|
||||
var pattern = 'ABACABADABACABA';
|
||||
for (var i = 0; i < longBufferString.length - pattern.length; i += 7) {
|
||||
var index = longBufferString.indexOf(pattern, i);
|
||||
assert.equal((i + 15) & ~0xf, index, 'Long ABACABA...-string at index ' + i);
|
||||
}
|
||||
assert.equal(510, longBufferString.indexOf('AJABACA'), 'Long AJABACA, First J');
|
||||
assert.equal(
|
||||
1534, longBufferString.indexOf('AJABACA', 511), 'Long AJABACA, Second J');
|
||||
|
||||
pattern = 'JABACABADABACABA';
|
||||
assert.equal(
|
||||
511, longBufferString.indexOf(pattern), 'Long JABACABA..., First J');
|
||||
assert.equal(
|
||||
1535, longBufferString.indexOf(pattern, 512), 'Long JABACABA..., Second J');
|
||||
|
||||
// Search for a non-ASCII string in a pure ASCII string.
|
||||
var asciiString = Buffer.from(
|
||||
'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf');
|
||||
assert.equal(-1, asciiString.indexOf('\x2061'));
|
||||
assert.equal(3, asciiString.indexOf('leb', 0));
|
||||
|
||||
// Search in string containing many non-ASCII chars.
|
||||
var allCodePoints = [];
|
||||
for (var i = 0; i < 65536; i++) allCodePoints[i] = i;
|
||||
var allCharsString = String.fromCharCode.apply(String, allCodePoints);
|
||||
var allCharsBufferUtf8 = Buffer.from(allCharsString);
|
||||
var allCharsBufferUcs2 = Buffer.from(allCharsString, 'ucs2');
|
||||
|
||||
// Search for string long enough to trigger complex search with ASCII pattern
|
||||
// and UC16 subject.
|
||||
assert.equal(-1, allCharsBufferUtf8.indexOf('notfound'));
|
||||
assert.equal(-1, allCharsBufferUcs2.indexOf('notfound'));
|
||||
|
||||
// Needle is longer than haystack, but only because it's encoded as UTF-16
|
||||
assert.strictEqual(Buffer.from('aaaa').indexOf('a'.repeat(4), 'ucs2'), -1);
|
||||
|
||||
assert.strictEqual(Buffer.from('aaaa').indexOf('a'.repeat(4), 'utf8'), 0);
|
||||
assert.strictEqual(Buffer.from('aaaa').indexOf('你好', 'ucs2'), -1);
|
||||
|
||||
// Haystack has odd length, but the needle is UCS2.
|
||||
// assert.strictEqual(Buffer.from('aaaaa').indexOf('b', 'ucs2'), -1);
|
||||
|
||||
{
|
||||
// Find substrings in Utf8.
|
||||
var lengths = [1, 3, 15]; // Single char, simple and complex.
|
||||
var indices = [0x5, 0x60, 0x400, 0x680, 0x7ee, 0xFF02, 0x16610, 0x2f77b];
|
||||
for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
|
||||
for (var i = 0; i < indices.length; i++) {
|
||||
var index = indices[i];
|
||||
var length = lengths[lengthIndex];
|
||||
|
||||
if (index + length > 0x7F) {
|
||||
length = 2 * length;
|
||||
}
|
||||
|
||||
if (index + length > 0x7FF) {
|
||||
length = 3 * length;
|
||||
}
|
||||
|
||||
if (index + length > 0xFFFF) {
|
||||
length = 4 * length;
|
||||
}
|
||||
|
||||
var patternBufferUtf8 = allCharsBufferUtf8.slice(index, index + length);
|
||||
assert.equal(index, allCharsBufferUtf8.indexOf(patternBufferUtf8));
|
||||
|
||||
var patternStringUtf8 = patternBufferUtf8.toString();
|
||||
assert.equal(index, allCharsBufferUtf8.indexOf(patternStringUtf8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Find substrings in Usc2.
|
||||
var lengths = [2, 4, 16]; // Single char, simple and complex.
|
||||
var indices = [0x5, 0x65, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0];
|
||||
for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
|
||||
for (var i = 0; i < indices.length; i++) {
|
||||
var index = indices[i] * 2;
|
||||
var length = lengths[lengthIndex];
|
||||
|
||||
var patternBufferUcs2 =
|
||||
allCharsBufferUcs2.slice(index, index + length);
|
||||
assert.equal(
|
||||
index, allCharsBufferUcs2.indexOf(patternBufferUcs2, 0, 'ucs2'));
|
||||
|
||||
var patternStringUcs2 = patternBufferUcs2.toString('ucs2');
|
||||
assert.equal(
|
||||
index, allCharsBufferUcs2.indexOf(patternStringUcs2, 0, 'ucs2'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.throws(function() {
|
||||
b.indexOf(function() { });
|
||||
});
|
||||
assert.throws(function() {
|
||||
b.indexOf({});
|
||||
});
|
||||
assert.throws(function() {
|
||||
b.indexOf([]);
|
||||
});
|
||||
|
||||
// All code for handling encodings is shared between Buffer.indexOf and
|
||||
// Buffer.lastIndexOf, so only testing the separate lastIndexOf semantics.
|
||||
|
||||
// Test lastIndexOf basic functionality; Buffer b contains 'abcdef'.
|
||||
// lastIndexOf string:
|
||||
assert.equal(b.lastIndexOf('a'), 0);
|
||||
assert.equal(b.lastIndexOf('a', 1), 0);
|
||||
assert.equal(b.lastIndexOf('b', 1), 1);
|
||||
assert.equal(b.lastIndexOf('c', 1), -1);
|
||||
assert.equal(b.lastIndexOf('a', -1), 0);
|
||||
assert.equal(b.lastIndexOf('a', -4), 0);
|
||||
assert.equal(b.lastIndexOf('a', -b.length), 0);
|
||||
assert.equal(b.lastIndexOf('a', -b.length - 1), -1);
|
||||
assert.equal(b.lastIndexOf('a', NaN), 0);
|
||||
assert.equal(b.lastIndexOf('a', -Infinity), -1);
|
||||
assert.equal(b.lastIndexOf('a', Infinity), 0);
|
||||
// lastIndexOf Buffer:
|
||||
assert.equal(b.lastIndexOf(buf_a), 0);
|
||||
assert.equal(b.lastIndexOf(buf_a, 1), 0);
|
||||
assert.equal(b.lastIndexOf(buf_a, -1), 0);
|
||||
assert.equal(b.lastIndexOf(buf_a, -4), 0);
|
||||
assert.equal(b.lastIndexOf(buf_a, -b.length), 0);
|
||||
assert.equal(b.lastIndexOf(buf_a, -b.length - 1), -1);
|
||||
assert.equal(b.lastIndexOf(buf_a, NaN), 0);
|
||||
assert.equal(b.lastIndexOf(buf_a, -Infinity), -1);
|
||||
assert.equal(b.lastIndexOf(buf_a, Infinity), 0);
|
||||
assert.equal(b.lastIndexOf(buf_bc), 1);
|
||||
assert.equal(b.lastIndexOf(buf_bc, 2), 1);
|
||||
assert.equal(b.lastIndexOf(buf_bc, -1), 1);
|
||||
assert.equal(b.lastIndexOf(buf_bc, -3), 1);
|
||||
assert.equal(b.lastIndexOf(buf_bc, -5), 1);
|
||||
assert.equal(b.lastIndexOf(buf_bc, -6), -1);
|
||||
assert.equal(b.lastIndexOf(buf_bc, NaN), 1);
|
||||
assert.equal(b.lastIndexOf(buf_bc, -Infinity), -1);
|
||||
assert.equal(b.lastIndexOf(buf_bc, Infinity), 1);
|
||||
assert.equal(b.lastIndexOf(buf_f), b.length - 1);
|
||||
assert.equal(b.lastIndexOf(buf_z), -1);
|
||||
assert.equal(b.lastIndexOf(buf_empty), -1);
|
||||
assert.equal(b.lastIndexOf(buf_empty, 1), -1);
|
||||
assert.equal(b.lastIndexOf(buf_empty, b.length + 1), -1);
|
||||
assert.equal(b.lastIndexOf(buf_empty, Infinity), -1);
|
||||
// lastIndexOf number:
|
||||
assert.equal(b.lastIndexOf(0x61), 0);
|
||||
assert.equal(b.lastIndexOf(0x61, 1), 0);
|
||||
assert.equal(b.lastIndexOf(0x61, -1), 0);
|
||||
assert.equal(b.lastIndexOf(0x61, -4), 0);
|
||||
assert.equal(b.lastIndexOf(0x61, -b.length), 0);
|
||||
assert.equal(b.lastIndexOf(0x61, -b.length - 1), -1);
|
||||
assert.equal(b.lastIndexOf(0x61, NaN), 0);
|
||||
assert.equal(b.lastIndexOf(0x61, -Infinity), -1);
|
||||
assert.equal(b.lastIndexOf(0x61, Infinity), 0);
|
||||
assert.equal(b.lastIndexOf(0x0), -1);
|
||||
|
||||
// Test weird offset arguments.
|
||||
// Behaviour should match String.lastIndexOf:
|
||||
assert.equal(b.lastIndexOf('b', 0), -1);
|
||||
assert.equal(b.lastIndexOf('b', undefined), 1);
|
||||
assert.equal(b.lastIndexOf('b', null), -1);
|
||||
assert.equal(b.lastIndexOf('b', {}), 1);
|
||||
assert.equal(b.lastIndexOf('b', []), -1);
|
||||
assert.equal(b.lastIndexOf('b', [2]), 1);
|
||||
|
||||
// Test needles longer than the haystack.
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'ucs2'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'utf8'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'latin1'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 'binary'), -1);
|
||||
assert.strictEqual(b.lastIndexOf(Buffer.from('aaaaaaaaaaaaaaa')), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 2, 'ucs2'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 3, 'utf8'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 5, 'latin1'), -1);
|
||||
assert.strictEqual(b.lastIndexOf('aaaaaaaaaaaaaaa', 5, 'binary'), -1);
|
||||
assert.strictEqual(b.lastIndexOf(Buffer.from('aaaaaaaaaaaaaaa'), 7), -1);
|
||||
|
||||
// 你好 expands to a total of 6 bytes using UTF-8 and 4 bytes using UTF-16
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 'ucs2'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 'utf8'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 'latin1'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 'binary'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf(Buffer.from('你好')), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 2, 'ucs2'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 3, 'utf8'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 5, 'latin1'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf('你好', 5, 'binary'), -1);
|
||||
assert.strictEqual(buf_bc.lastIndexOf(Buffer.from('你好'), 7), -1);
|
||||
|
||||
// Test lastIndexOf on a longer buffer:
|
||||
var bufferString = new Buffer('a man a plan a canal panama');
|
||||
assert.equal(15, bufferString.lastIndexOf('canal'));
|
||||
assert.equal(21, bufferString.lastIndexOf('panama'));
|
||||
assert.equal(0, bufferString.lastIndexOf('a man a plan a canal panama'));
|
||||
assert.equal(-1, bufferString.lastIndexOf('a man a plan a canal mexico'));
|
||||
assert.equal(-1, bufferString.lastIndexOf('a man a plan a canal mexico city'));
|
||||
assert.equal(-1, bufferString.lastIndexOf(Buffer.from('a'.repeat(1000))));
|
||||
assert.equal(0, bufferString.lastIndexOf('a man a plan', 4));
|
||||
assert.equal(13, bufferString.lastIndexOf('a '));
|
||||
assert.equal(13, bufferString.lastIndexOf('a ', 13));
|
||||
assert.equal(6, bufferString.lastIndexOf('a ', 12));
|
||||
assert.equal(0, bufferString.lastIndexOf('a ', 5));
|
||||
assert.equal(13, bufferString.lastIndexOf('a ', -1));
|
||||
assert.equal(0, bufferString.lastIndexOf('a ', -27));
|
||||
assert.equal(-1, bufferString.lastIndexOf('a ', -28));
|
||||
|
||||
// Test lastIndexOf for the case that the first character can be found,
|
||||
// but in a part of the buffer that does not make search to search
|
||||
// due do length constraints.
|
||||
var abInUCS2 = Buffer.from('ab', 'ucs2');
|
||||
assert.strictEqual(-1, Buffer.from('µaaaa¶bbbb', 'latin1').lastIndexOf('µ'));
|
||||
assert.strictEqual(-1, Buffer.from('µaaaa¶bbbb', 'binary').lastIndexOf('µ'));
|
||||
assert.strictEqual(-1, Buffer.from('bc').lastIndexOf('ab'));
|
||||
assert.strictEqual(-1, Buffer.from('abc').lastIndexOf('qa'));
|
||||
assert.strictEqual(-1, Buffer.from('abcdef').lastIndexOf('qabc'));
|
||||
assert.strictEqual(-1, Buffer.from('bc').lastIndexOf(Buffer.from('ab')));
|
||||
assert.strictEqual(-1, Buffer.from('bc', 'ucs2').lastIndexOf('ab', 'ucs2'));
|
||||
assert.strictEqual(-1, Buffer.from('bc', 'ucs2').lastIndexOf(abInUCS2));
|
||||
|
||||
assert.strictEqual(0, Buffer.from('abc').lastIndexOf('ab'));
|
||||
assert.strictEqual(0, Buffer.from('abc').lastIndexOf('ab', 1));
|
||||
assert.strictEqual(0, Buffer.from('abc').lastIndexOf('ab', 2));
|
||||
assert.strictEqual(0, Buffer.from('abc').lastIndexOf('ab', 3));
|
||||
|
||||
// The above tests test the LINEAR and SINGLE-CHAR strategies.
|
||||
// Now, we test the BOYER-MOORE-HORSPOOL strategy.
|
||||
// Test lastIndexOf on a long buffer w multiple matches:
|
||||
pattern = 'JABACABADABACABA';
|
||||
assert.equal(1535, longBufferString.lastIndexOf(pattern));
|
||||
assert.equal(1535, longBufferString.lastIndexOf(pattern, 1535));
|
||||
assert.equal(511, longBufferString.lastIndexOf(pattern, 1534));
|
||||
|
||||
// Finally, give it a really long input to trigger fallback from BMH to
|
||||
// regular BOYER-MOORE (which has better worst-case complexity).
|
||||
|
||||
// Generate a really long Thue-Morse sequence of 'yolo' and 'swag',
|
||||
// "yolo swag swag yolo swag yolo yolo swag" ..., goes on for about 5MB.
|
||||
// This is hard to search because it all looks similar, but never repeats.
|
||||
|
||||
// countBits returns the number of bits in the binary reprsentation of n.
|
||||
function countBits(n) {
|
||||
for (var count = 0; n > 0; count++) {
|
||||
n = n & (n - 1); // remove top bit
|
||||
}
|
||||
return count;
|
||||
}
|
||||
var parts = [];
|
||||
for (var i = 0; i < 1000000; i++) {
|
||||
parts.push((countBits(i) % 2 === 0) ? 'yolo' : 'swag');
|
||||
}
|
||||
var reallyLong = new Buffer(parts.join(' '));
|
||||
assert.equal('yolo swag swag yolo', reallyLong.slice(0, 19).toString());
|
||||
|
||||
// Expensive reverse searches. Stress test lastIndexOf:
|
||||
pattern = reallyLong.slice(0, 100000); // First 1/50th of the pattern.
|
||||
assert.equal(4751360, reallyLong.lastIndexOf(pattern));
|
||||
assert.equal(3932160, reallyLong.lastIndexOf(pattern, 4000000));
|
||||
assert.equal(2949120, reallyLong.lastIndexOf(pattern, 3000000));
|
||||
pattern = reallyLong.slice(100000, 200000); // Second 1/50th.
|
||||
assert.equal(4728480, reallyLong.lastIndexOf(pattern));
|
||||
pattern = reallyLong.slice(0, 1000000); // First 1/5th.
|
||||
assert.equal(3932160, reallyLong.lastIndexOf(pattern));
|
||||
pattern = reallyLong.slice(0, 2000000); // first 2/5ths.
|
||||
assert.equal(0, reallyLong.lastIndexOf(pattern));
|
||||
|
||||
// test truncation of Number arguments to uint8
|
||||
{
|
||||
var buf = Buffer.from('this is a test');
|
||||
assert.strictEqual(buf.indexOf(0x6973), 3);
|
||||
assert.strictEqual(buf.indexOf(0x697320), 4);
|
||||
assert.strictEqual(buf.indexOf(0x69732069), 2);
|
||||
assert.strictEqual(buf.indexOf(0x697374657374), 0);
|
||||
assert.strictEqual(buf.indexOf(0x69737374), 0);
|
||||
assert.strictEqual(buf.indexOf(0x69737465), 11);
|
||||
assert.strictEqual(buf.indexOf(0x69737465), 11);
|
||||
assert.strictEqual(buf.indexOf(-140), 0);
|
||||
assert.strictEqual(buf.indexOf(-152), 1);
|
||||
assert.strictEqual(buf.indexOf(0xff), -1);
|
||||
assert.strictEqual(buf.indexOf(0xffff), -1);
|
||||
}
|
||||
|
42
node_modules/buffer/test/node/test-buffer-inheritance.js
generated
vendored
Normal file
42
node_modules/buffer/test/node/test-buffer-inheritance.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
|
||||
function T(n) {
|
||||
var ui8 = new Uint8Array(n);
|
||||
Object.setPrototypeOf(ui8, T.prototype);
|
||||
return ui8;
|
||||
}
|
||||
Object.setPrototypeOf(T.prototype, Buffer.prototype);
|
||||
Object.setPrototypeOf(T, Buffer);
|
||||
|
||||
T.prototype.sum = function sum() {
|
||||
var cntr = 0;
|
||||
for (var i = 0; i < this.length; i++)
|
||||
cntr += this[i];
|
||||
return cntr;
|
||||
};
|
||||
|
||||
|
||||
var vals = [new T(4), T(4)];
|
||||
|
||||
vals.forEach(function(t) {
|
||||
assert.equal(t.constructor, T);
|
||||
assert.equal(Object.getPrototypeOf(t), T.prototype);
|
||||
assert.equal(Object.getPrototypeOf(Object.getPrototypeOf(t)),
|
||||
Buffer.prototype);
|
||||
|
||||
t.fill(5);
|
||||
var cntr = 0;
|
||||
for (var i = 0; i < t.length; i++)
|
||||
cntr += t[i];
|
||||
assert.equal(t.length * 5, cntr);
|
||||
|
||||
// Check this does not throw
|
||||
t.toString();
|
||||
});
|
||||
|
41
node_modules/buffer/test/node/test-buffer-inspect.js
generated
vendored
Normal file
41
node_modules/buffer/test/node/test-buffer-inspect.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var util = require('util');
|
||||
|
||||
var buffer = require('../../');
|
||||
|
||||
buffer.INSPECT_MAX_BYTES = 2;
|
||||
|
||||
var b = Buffer.allocUnsafe(4);
|
||||
b.fill('1234');
|
||||
|
||||
var s = buffer.SlowBuffer(4);
|
||||
s.fill('1234');
|
||||
|
||||
var expected = '<Buffer 31 32 ... >';
|
||||
|
||||
assert.strictEqual(util.inspect(b), expected);
|
||||
assert.strictEqual(util.inspect(s), expected);
|
||||
|
||||
b = Buffer.allocUnsafe(2);
|
||||
b.fill('12');
|
||||
|
||||
s = buffer.SlowBuffer(2);
|
||||
s.fill('12');
|
||||
|
||||
expected = '<Buffer 31 32>';
|
||||
|
||||
assert.strictEqual(util.inspect(b), expected);
|
||||
assert.strictEqual(util.inspect(s), expected);
|
||||
|
||||
buffer.INSPECT_MAX_BYTES = Infinity;
|
||||
|
||||
assert.doesNotThrow(function() {
|
||||
assert.strictEqual(util.inspect(b), expected);
|
||||
assert.strictEqual(util.inspect(s), expected);
|
||||
});
|
||||
|
65
node_modules/buffer/test/node/test-buffer-iterator.js
generated
vendored
Normal file
65
node_modules/buffer/test/node/test-buffer-iterator.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var buffer = Buffer.from([1, 2, 3, 4, 5]);
|
||||
var arr;
|
||||
var b;
|
||||
|
||||
// buffers should be iterable
|
||||
|
||||
arr = [];
|
||||
|
||||
for (b of buffer)
|
||||
arr.push(b);
|
||||
|
||||
assert.deepStrictEqual(arr, [1, 2, 3, 4, 5]);
|
||||
|
||||
|
||||
// buffer iterators should be iterable
|
||||
|
||||
arr = [];
|
||||
|
||||
for (b of buffer[Symbol.iterator]())
|
||||
arr.push(b);
|
||||
|
||||
assert.deepStrictEqual(arr, [1, 2, 3, 4, 5]);
|
||||
|
||||
|
||||
// buffer#values() should return iterator for values
|
||||
|
||||
arr = [];
|
||||
|
||||
for (b of buffer.values())
|
||||
arr.push(b);
|
||||
|
||||
assert.deepStrictEqual(arr, [1, 2, 3, 4, 5]);
|
||||
|
||||
|
||||
// buffer#keys() should return iterator for keys
|
||||
|
||||
arr = [];
|
||||
|
||||
for (b of buffer.keys())
|
||||
arr.push(b);
|
||||
|
||||
assert.deepStrictEqual(arr, [0, 1, 2, 3, 4]);
|
||||
|
||||
|
||||
// buffer#entries() should return iterator for entries
|
||||
|
||||
arr = [];
|
||||
|
||||
for (b of buffer.entries())
|
||||
arr.push(b);
|
||||
|
||||
assert.deepStrictEqual(arr, [
|
||||
[0, 1],
|
||||
[1, 2],
|
||||
[2, 3],
|
||||
[3, 4],
|
||||
[4, 5]
|
||||
]);
|
||||
|
27
node_modules/buffer/test/node/test-buffer-safe-unsafe.js
generated
vendored
Normal file
27
node_modules/buffer/test/node/test-buffer-safe-unsafe.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
var safe = Buffer.alloc(10);
|
||||
|
||||
function isZeroFilled(buf) {
|
||||
for (var n = 0; n < buf.length; n++)
|
||||
if (buf[n] !== 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
assert(isZeroFilled(safe));
|
||||
|
||||
// Test that unsafe allocations doesn't affect subsequent safe allocations
|
||||
Buffer.allocUnsafe(10);
|
||||
assert(isZeroFilled(new Float64Array(10)));
|
||||
|
||||
new Buffer(10);
|
||||
assert(isZeroFilled(new Float64Array(10)));
|
||||
|
||||
Buffer.allocUnsafe(10);
|
||||
assert(isZeroFilled(Buffer.alloc(10)));
|
||||
|
63
node_modules/buffer/test/node/test-buffer-slow.js
generated
vendored
Normal file
63
node_modules/buffer/test/node/test-buffer-slow.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
var buffer = require('../../');
|
||||
var Buffer = buffer.Buffer;
|
||||
var SlowBuffer = buffer.SlowBuffer;
|
||||
|
||||
var ones = [1, 1, 1, 1];
|
||||
|
||||
// should create a Buffer
|
||||
var sb = SlowBuffer(4);
|
||||
assert(sb instanceof Buffer);
|
||||
assert.strictEqual(sb.length, 4);
|
||||
sb.fill(1);
|
||||
for (var [key, value] of sb.entries()) {
|
||||
assert.deepStrictEqual(value, ones[key]);
|
||||
}
|
||||
|
||||
// underlying ArrayBuffer should have the same length
|
||||
assert.strictEqual(sb.buffer.byteLength, 4);
|
||||
|
||||
// should work without new
|
||||
sb = SlowBuffer(4);
|
||||
assert(sb instanceof Buffer);
|
||||
assert.strictEqual(sb.length, 4);
|
||||
sb.fill(1);
|
||||
for (var [key, value] of sb.entries()) {
|
||||
assert.deepStrictEqual(value, ones[key]);
|
||||
}
|
||||
|
||||
// should work with edge cases
|
||||
assert.strictEqual(SlowBuffer(0).length, 0);
|
||||
try {
|
||||
assert.strictEqual(
|
||||
SlowBuffer(buffer.kMaxLength).length, buffer.kMaxLength);
|
||||
} catch (e) {
|
||||
assert.equal(e.message, 'Array buffer allocation failed');
|
||||
}
|
||||
|
||||
// should work with number-coercible values
|
||||
assert.strictEqual(SlowBuffer('6').length, 6);
|
||||
assert.strictEqual(SlowBuffer(true).length, 1);
|
||||
|
||||
// should create zero-length buffer if parameter is not a number
|
||||
assert.strictEqual(SlowBuffer().length, 0);
|
||||
assert.strictEqual(SlowBuffer(NaN).length, 0);
|
||||
assert.strictEqual(SlowBuffer({}).length, 0);
|
||||
assert.strictEqual(SlowBuffer('string').length, 0);
|
||||
|
||||
// should throw with invalid length
|
||||
assert.throws(function() {
|
||||
SlowBuffer(Infinity);
|
||||
}, 'invalid Buffer length');
|
||||
assert.throws(function() {
|
||||
SlowBuffer(-1);
|
||||
}, 'invalid Buffer length');
|
||||
assert.throws(function() {
|
||||
SlowBuffer(buffer.kMaxLength + 1);
|
||||
}, 'invalid Buffer length');
|
||||
|
141
node_modules/buffer/test/node/test-buffer-swap.js
generated
vendored
Normal file
141
node_modules/buffer/test/node/test-buffer-swap.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
// Test buffers small enough to use the JS implementation
|
||||
var buf = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
|
||||
0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10]);
|
||||
|
||||
assert.strictEqual(buf, buf.swap16());
|
||||
assert.deepStrictEqual(buf, Buffer.from([0x02, 0x01, 0x04, 0x03, 0x06, 0x05,
|
||||
0x08, 0x07, 0x0a, 0x09, 0x0c, 0x0b,
|
||||
0x0e, 0x0d, 0x10, 0x0f]));
|
||||
buf.swap16(); // restore
|
||||
|
||||
assert.strictEqual(buf, buf.swap32());
|
||||
assert.deepStrictEqual(buf, Buffer.from([0x04, 0x03, 0x02, 0x01, 0x08, 0x07,
|
||||
0x06, 0x05, 0x0c, 0x0b, 0x0a, 0x09,
|
||||
0x10, 0x0f, 0x0e, 0x0d]));
|
||||
buf.swap32(); // restore
|
||||
|
||||
assert.strictEqual(buf, buf.swap64());
|
||||
assert.deepStrictEqual(buf, Buffer.from([0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
|
||||
0x02, 0x01, 0x10, 0x0f, 0x0e, 0x0d,
|
||||
0x0c, 0x0b, 0x0a, 0x09]));
|
||||
|
||||
// Operates in-place
|
||||
var buf3 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7]);
|
||||
buf3.slice(1, 5).swap32();
|
||||
assert.deepStrictEqual(buf3, Buffer.from([0x1, 0x5, 0x4, 0x3, 0x2, 0x6, 0x7]));
|
||||
|
||||
buf3.slice(1, 5).swap16();
|
||||
assert.deepStrictEqual(buf3, Buffer.from([0x1, 0x4, 0x5, 0x2, 0x3, 0x6, 0x7]));
|
||||
|
||||
var buf3_64 = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
|
||||
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10]);
|
||||
buf3_64.slice(2, 18).swap64();
|
||||
assert.deepStrictEqual(buf3_64, Buffer.from([0x01, 0x02, 0x0a, 0x09, 0x08, 0x07,
|
||||
0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
|
||||
0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b,
|
||||
0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
|
||||
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
|
||||
0x0f, 0x10]));
|
||||
|
||||
// Force use of native code (Buffer size above threshold limit for js impl)
|
||||
var buf4A = new Uint32Array(256).fill(0x04030201);
|
||||
var buf4 = Buffer.from(buf4A.buffer, buf4A.byteOffset);
|
||||
var buf5A = new Uint32Array(256).fill(0x03040102);
|
||||
var buf5 = Buffer.from(buf5A.buffer, buf5A.byteOffset);
|
||||
|
||||
buf4.swap16();
|
||||
assert.deepStrictEqual(buf4, buf5);
|
||||
|
||||
var buf6A = new Uint32Array(256).fill(0x04030201);
|
||||
var buf6 = Buffer.from(buf6A.buffer);
|
||||
var bu7A = new Uint32Array(256).fill(0x01020304);
|
||||
var buf7 = Buffer.from(bu7A.buffer, bu7A.byteOffset);
|
||||
|
||||
buf6.swap32();
|
||||
assert.deepStrictEqual(buf6, buf7);
|
||||
|
||||
var buf8A = new Uint8Array(256 * 8);
|
||||
var buf9A = new Uint8Array(256 * 8);
|
||||
for (var i = 0; i < buf8A.length; i++) {
|
||||
buf8A[i] = i % 8;
|
||||
buf9A[buf9A.length - i - 1] = i % 8;
|
||||
}
|
||||
var buf8 = Buffer.from(buf8A.buffer, buf8A.byteOffset);
|
||||
var buf9 = Buffer.from(buf9A.buffer, buf9A.byteOffset);
|
||||
|
||||
buf8.swap64();
|
||||
assert.deepStrictEqual(buf8, buf9);
|
||||
|
||||
// Test native code with buffers that are not memory-aligned
|
||||
var buf10A = new Uint8Array(256 * 8);
|
||||
var buf11A = new Uint8Array(256 * 8 - 2);
|
||||
for (var i = 0; i < buf10A.length; i++) {
|
||||
buf10A[i] = i % 2;
|
||||
}
|
||||
for (var i = 1; i < buf11A.length; i++) {
|
||||
buf11A[buf11A.length - i] = (i + 1) % 2;
|
||||
}
|
||||
var buf10 = Buffer.from(buf10A.buffer, buf10A.byteOffset);
|
||||
// 0|1 0|1 0|1...
|
||||
var buf11 = Buffer.from(buf11A.buffer, buf11A.byteOffset);
|
||||
// 0|0 1|0 1|0...
|
||||
|
||||
buf10.slice(1, buf10.length - 1).swap16();
|
||||
assert.deepStrictEqual(buf10.slice(0, buf11.length), buf11);
|
||||
|
||||
|
||||
var buf12A = new Uint8Array(256 * 8);
|
||||
var buf13A = new Uint8Array(256 * 8 - 4);
|
||||
for (var i = 0; i < buf12A.length; i++) {
|
||||
buf12A[i] = i % 4;
|
||||
}
|
||||
for (var i = 1; i < buf13A.length; i++) {
|
||||
buf13A[buf13A.length - i] = (i + 1) % 4;
|
||||
}
|
||||
var buf12 = Buffer.from(buf12A.buffer, buf12A.byteOffset);
|
||||
// 0|1 2 3 0|1 2 3...
|
||||
var buf13 = Buffer.from(buf13A.buffer, buf13A.byteOffset);
|
||||
// 0|0 3 2 1|0 3 2...
|
||||
|
||||
buf12.slice(1, buf12.length - 3).swap32();
|
||||
assert.deepStrictEqual(buf12.slice(0, buf13.length), buf13);
|
||||
|
||||
|
||||
var buf14A = new Uint8Array(256 * 8);
|
||||
var buf15A = new Uint8Array(256 * 8 - 8);
|
||||
for (var i = 0; i < buf14A.length; i++) {
|
||||
buf14A[i] = i % 8;
|
||||
}
|
||||
for (var i = 1; i < buf15A.length; i++) {
|
||||
buf15A[buf15A.length - i] = (i + 1) % 8;
|
||||
}
|
||||
var buf14 = Buffer.from(buf14A.buffer, buf14A.byteOffset);
|
||||
// 0|1 2 3 4 5 6 7 0|1 2 3 4...
|
||||
var buf15 = Buffer.from(buf15A.buffer, buf15A.byteOffset);
|
||||
// 0|0 7 6 5 4 3 2 1|0 7 6 5...
|
||||
|
||||
buf14.slice(1, buf14.length - 7).swap64();
|
||||
assert.deepStrictEqual(buf14.slice(0, buf15.length), buf15);
|
||||
|
||||
// Length assertions
|
||||
var re16 = /Buffer size must be a multiple of 16-bits/;
|
||||
var re32 = /Buffer size must be a multiple of 32-bits/;
|
||||
var re64 = /Buffer size must be a multiple of 64-bits/;
|
||||
|
||||
assert.throws(() => Buffer.from(buf3).swap16(), re16);
|
||||
assert.throws(() => Buffer.alloc(1025).swap16(), re16);
|
||||
assert.throws(() => Buffer.from(buf3).swap32(), re32);
|
||||
assert.throws(() => buf3.slice(1, 3).swap32(), re32);
|
||||
assert.throws(() => Buffer.alloc(1025).swap32(), re32);
|
||||
assert.throws(() => buf3.slice(1, 3).swap64(), re64);
|
||||
assert.throws(() => Buffer.alloc(1025).swap64(), re64);
|
||||
|
35
node_modules/buffer/test/node/test-buffer-zero-fill-cli.js
generated
vendored
Normal file
35
node_modules/buffer/test/node/test-buffer-zero-fill-cli.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
// Flags: --zero-fill-buffers
|
||||
|
||||
// when using --zero-fill-buffers, every Buffer and SlowBuffer
|
||||
// instance must be zero filled upon creation
|
||||
|
||||
|
||||
var SlowBuffer = require('../../').SlowBuffer;
|
||||
var assert = require('assert');
|
||||
|
||||
function isZeroFilled(buf) {
|
||||
for (var n = 0; n < buf.length; n++)
|
||||
if (buf[n] > 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// This can be somewhat unreliable because the
|
||||
// allocated memory might just already happen to
|
||||
// contain all zeroes. The test is run multiple
|
||||
// times to improve the reliability.
|
||||
for (var i = 0; i < 50; i++) {
|
||||
var bufs = [
|
||||
Buffer.alloc(20),
|
||||
Buffer.allocUnsafe(20),
|
||||
SlowBuffer(20),
|
||||
Buffer(20),
|
||||
new SlowBuffer(20)
|
||||
];
|
||||
for (var buf of bufs) {
|
||||
assert(isZeroFilled(buf));
|
||||
}
|
||||
}
|
||||
|
22
node_modules/buffer/test/node/test-buffer-zero-fill-reset.js
generated
vendored
Normal file
22
node_modules/buffer/test/node/test-buffer-zero-fill-reset.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
var Buffer = require('../../').Buffer;
|
||||
|
||||
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
|
||||
function testUint8Array(ui) {
|
||||
var length = ui.length;
|
||||
for (var i = 0; i < length; i++)
|
||||
if (ui[i] !== 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
for (var i = 0; i < 100; i++) {
|
||||
Buffer.alloc(0);
|
||||
var ui = new Uint8Array(65);
|
||||
assert.ok(testUint8Array(ui), 'Uint8Array is not zero-filled');
|
||||
}
|
||||
|
1534
node_modules/buffer/test/node/test-buffer.js
generated
vendored
Normal file
1534
node_modules/buffer/test/node/test-buffer.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
37
node_modules/buffer/test/slice.js
generated
vendored
Normal file
37
node_modules/buffer/test/slice.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
test('modifying buffer created by .slice() modifies original memory', function (t) {
|
||||
if (!B.TYPED_ARRAY_SUPPORT) return t.end()
|
||||
|
||||
var buf1 = new B(26)
|
||||
for (var i = 0; i < 26; i++) {
|
||||
buf1[i] = i + 97 // 97 is ASCII a
|
||||
}
|
||||
|
||||
var buf2 = buf1.slice(0, 3)
|
||||
t.equal(buf2.toString('ascii', 0, buf2.length), 'abc')
|
||||
|
||||
buf2[0] = '!'.charCodeAt(0)
|
||||
t.equal(buf1.toString('ascii', 0, buf2.length), '!bc')
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('modifying parent buffer modifies .slice() buffer\'s memory', function (t) {
|
||||
if (!B.TYPED_ARRAY_SUPPORT) return t.end()
|
||||
|
||||
var buf1 = new B(26)
|
||||
for (var i = 0; i < 26; i++) {
|
||||
buf1[i] = i + 97 // 97 is ASCII a
|
||||
}
|
||||
|
||||
var buf2 = buf1.slice(0, 3)
|
||||
t.equal(buf2.toString('ascii', 0, buf2.length), 'abc')
|
||||
|
||||
buf1[0] = '!'.charCodeAt(0)
|
||||
t.equal(buf2.toString('ascii', 0, buf2.length), '!bc')
|
||||
|
||||
t.end()
|
||||
})
|
17
node_modules/buffer/test/static.js
generated
vendored
Normal file
17
node_modules/buffer/test/static.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
test('Buffer.isEncoding', function (t) {
|
||||
t.equal(B.isEncoding('HEX'), true)
|
||||
t.equal(B.isEncoding('hex'), true)
|
||||
t.equal(B.isEncoding('bad'), false)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('Buffer.isBuffer', function (t) {
|
||||
t.equal(B.isBuffer(new B('hey', 'utf8')), true)
|
||||
t.equal(B.isBuffer(new B([1, 2, 3], 'utf8')), true)
|
||||
t.equal(B.isBuffer('hey'), false)
|
||||
t.end()
|
||||
})
|
233
node_modules/buffer/test/to-string.js
generated
vendored
Normal file
233
node_modules/buffer/test/to-string.js
generated
vendored
Normal file
@@ -0,0 +1,233 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
test('utf8 buffer to base64', function (t) {
|
||||
t.equal(
|
||||
new B('Ձאab', 'utf8').toString('base64'),
|
||||
'1YHXkGFi'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf8 buffer to hex', function (t) {
|
||||
t.equal(
|
||||
new B('Ձאab', 'utf8').toString('hex'),
|
||||
'd581d7906162'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf8 to utf8', function (t) {
|
||||
t.equal(
|
||||
new B('öäüõÖÄÜÕ', 'utf8').toString('utf8'),
|
||||
'öäüõÖÄÜÕ'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf16le to utf16', function (t) {
|
||||
t.equal(
|
||||
new B(new B('abcd', 'utf8').toString('utf16le'), 'utf16le').toString('utf8'),
|
||||
'abcd'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf16le to hex', function (t) {
|
||||
t.equal(
|
||||
new B('abcd', 'utf16le').toString('hex'),
|
||||
'6100620063006400'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('ascii buffer to base64', function (t) {
|
||||
t.equal(
|
||||
new B('123456!@#$%^', 'ascii').toString('base64'),
|
||||
'MTIzNDU2IUAjJCVe'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('ascii buffer to hex', function (t) {
|
||||
t.equal(
|
||||
new B('123456!@#$%^', 'ascii').toString('hex'),
|
||||
'31323334353621402324255e'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('base64 buffer to utf8', function (t) {
|
||||
t.equal(
|
||||
new B('1YHXkGFi', 'base64').toString('utf8'),
|
||||
'Ձאab'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('hex buffer to utf8', function (t) {
|
||||
t.equal(
|
||||
new B('d581d7906162', 'hex').toString('utf8'),
|
||||
'Ձאab'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('base64 buffer to ascii', function (t) {
|
||||
t.equal(
|
||||
new B('MTIzNDU2IUAjJCVe', 'base64').toString('ascii'),
|
||||
'123456!@#$%^'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('hex buffer to ascii', function (t) {
|
||||
t.equal(
|
||||
new B('31323334353621402324255e', 'hex').toString('ascii'),
|
||||
'123456!@#$%^'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('base64 buffer to binary', function (t) {
|
||||
t.equal(
|
||||
new B('MTIzNDU2IUAjJCVe', 'base64').toString('binary'),
|
||||
'123456!@#$%^'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('hex buffer to binary', function (t) {
|
||||
t.equal(
|
||||
new B('31323334353621402324255e', 'hex').toString('binary'),
|
||||
'123456!@#$%^'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf8 to binary', function (t) {
|
||||
/* jshint -W100 */
|
||||
t.equal(
|
||||
new B('öäüõÖÄÜÕ', 'utf8').toString('binary'),
|
||||
'öäüõÃÃÃÃ'
|
||||
)
|
||||
/* jshint +W100 */
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf8 replacement chars (1 byte sequence)', function (t) {
|
||||
t.equal(
|
||||
new B([ 0x80 ]).toString(),
|
||||
'\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0x7F ]).toString(),
|
||||
'\u007F'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf8 replacement chars (2 byte sequences)', function (t) {
|
||||
t.equal(
|
||||
new B([ 0xC7 ]).toString(),
|
||||
'\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xC7, 0xB1 ]).toString(),
|
||||
'\u01F1'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xC0, 0xB1 ]).toString(),
|
||||
'\uFFFD\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xC1, 0xB1 ]).toString(),
|
||||
'\uFFFD\uFFFD'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf8 replacement chars (3 byte sequences)', function (t) {
|
||||
t.equal(
|
||||
new B([ 0xE0 ]).toString(),
|
||||
'\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xE0, 0xAC ]).toString(),
|
||||
'\uFFFD\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xE0, 0xAC, 0xB9 ]).toString(),
|
||||
'\u0B39'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf8 replacement chars (4 byte sequences)', function (t) {
|
||||
t.equal(
|
||||
new B([ 0xF4 ]).toString(),
|
||||
'\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xF4, 0x8F ]).toString(),
|
||||
'\uFFFD\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xF4, 0x8F, 0x80 ]).toString(),
|
||||
'\uFFFD\uFFFD\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xF4, 0x8F, 0x80, 0x84 ]).toString(),
|
||||
'\uDBFC\uDC04'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xFF ]).toString(),
|
||||
'\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xFF, 0x8F, 0x80, 0x84 ]).toString(),
|
||||
'\uFFFD\uFFFD\uFFFD\uFFFD'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf8 replacement chars on 256 random bytes', function (t) {
|
||||
t.equal(
|
||||
new B([ 152, 130, 206, 23, 243, 238, 197, 44, 27, 86, 208, 36, 163, 184, 164, 21, 94, 242, 178, 46, 25, 26, 253, 178, 72, 147, 207, 112, 236, 68, 179, 190, 29, 83, 239, 147, 125, 55, 143, 19, 157, 68, 157, 58, 212, 224, 150, 39, 128, 24, 94, 225, 120, 121, 75, 192, 112, 19, 184, 142, 203, 36, 43, 85, 26, 147, 227, 139, 242, 186, 57, 78, 11, 102, 136, 117, 180, 210, 241, 92, 3, 215, 54, 167, 249, 1, 44, 225, 146, 86, 2, 42, 68, 21, 47, 238, 204, 153, 216, 252, 183, 66, 222, 255, 15, 202, 16, 51, 134, 1, 17, 19, 209, 76, 238, 38, 76, 19, 7, 103, 249, 5, 107, 137, 64, 62, 170, 57, 16, 85, 179, 193, 97, 86, 166, 196, 36, 148, 138, 193, 210, 69, 187, 38, 242, 97, 195, 219, 252, 244, 38, 1, 197, 18, 31, 246, 53, 47, 134, 52, 105, 72, 43, 239, 128, 203, 73, 93, 199, 75, 222, 220, 166, 34, 63, 236, 11, 212, 76, 243, 171, 110, 78, 39, 205, 204, 6, 177, 233, 212, 243, 0, 33, 41, 122, 118, 92, 252, 0, 157, 108, 120, 70, 137, 100, 223, 243, 171, 232, 66, 126, 111, 142, 33, 3, 39, 117, 27, 107, 54, 1, 217, 227, 132, 13, 166, 3, 73, 53, 127, 225, 236, 134, 219, 98, 214, 125, 148, 24, 64, 142, 111, 231, 194, 42, 150, 185, 10, 182, 163, 244, 19, 4, 59, 135, 16 ]).toString(),
|
||||
'\uFFFD\uFFFD\uFFFD\u0017\uFFFD\uFFFD\uFFFD\u002C\u001B\u0056\uFFFD\u0024\uFFFD\uFFFD\uFFFD\u0015\u005E\uFFFD\uFFFD\u002E\u0019\u001A\uFFFD\uFFFD\u0048\uFFFD\uFFFD\u0070\uFFFD\u0044\uFFFD\uFFFD\u001D\u0053\uFFFD\uFFFD\u007D\u0037\uFFFD\u0013\uFFFD\u0044\uFFFD\u003A\uFFFD\uFFFD\uFFFD\u0027\uFFFD\u0018\u005E\uFFFD\u0078\u0079\u004B\uFFFD\u0070\u0013\uFFFD\uFFFD\uFFFD\u0024\u002B\u0055\u001A\uFFFD\uFFFD\uFFFD\uFFFD\uFFFD\u0039\u004E\u000B\u0066\uFFFD\u0075\uFFFD\uFFFD\uFFFD\u005C\u0003\uFFFD\u0036\uFFFD\uFFFD\u0001\u002C\uFFFD\uFFFD\u0056\u0002\u002A\u0044\u0015\u002F\uFFFD\u0319\uFFFD\uFFFD\uFFFD\u0042\uFFFD\uFFFD\u000F\uFFFD\u0010\u0033\uFFFD\u0001\u0011\u0013\uFFFD\u004C\uFFFD\u0026\u004C\u0013\u0007\u0067\uFFFD\u0005\u006B\uFFFD\u0040\u003E\uFFFD\u0039\u0010\u0055\uFFFD\uFFFD\u0061\u0056\uFFFD\uFFFD\u0024\uFFFD\uFFFD\uFFFD\uFFFD\u0045\uFFFD\u0026\uFFFD\u0061\uFFFD\uFFFD\uFFFD\uFFFD\u0026\u0001\uFFFD\u0012\u001F\uFFFD\u0035\u002F\uFFFD\u0034\u0069\u0048\u002B\uFFFD\uFFFD\uFFFD\u0049\u005D\uFFFD\u004B\uFFFD\u0726\u0022\u003F\uFFFD\u000B\uFFFD\u004C\uFFFD\uFFFD\u006E\u004E\u0027\uFFFD\uFFFD\u0006\uFFFD\uFFFD\uFFFD\uFFFD\u0000\u0021\u0029\u007A\u0076\u005C\uFFFD\u0000\uFFFD\u006C\u0078\u0046\uFFFD\u0064\uFFFD\uFFFD\uFFFD\uFFFD\u0042\u007E\u006F\uFFFD\u0021\u0003\u0027\u0075\u001B\u006B\u0036\u0001\uFFFD\uFFFD\uFFFD\u000D\uFFFD\u0003\u0049\u0035\u007F\uFFFD\uFFFD\uFFFD\uFFFD\u0062\uFFFD\u007D\uFFFD\u0018\u0040\uFFFD\u006F\uFFFD\uFFFD\u002A\uFFFD\uFFFD\u000A\uFFFD\uFFFD\uFFFD\u0013\u0004\u003B\uFFFD\u0010'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf8 replacement chars for anything in the surrogate pair range', function (t) {
|
||||
t.equal(
|
||||
new B([ 0xED, 0x9F, 0xBF ]).toString(),
|
||||
'\uD7FF'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xED, 0xA0, 0x80 ]).toString(),
|
||||
'\uFFFD\uFFFD\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xED, 0xBE, 0x8B ]).toString(),
|
||||
'\uFFFD\uFFFD\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xED, 0xBF, 0xBF ]).toString(),
|
||||
'\uFFFD\uFFFD\uFFFD'
|
||||
)
|
||||
t.equal(
|
||||
new B([ 0xEE, 0x80, 0x80 ]).toString(),
|
||||
'\uE000'
|
||||
)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('utf8 don\'t replace the replacement char', function (t) {
|
||||
t.equal(
|
||||
new B('\uFFFD').toString(),
|
||||
'\uFFFD'
|
||||
)
|
||||
t.end()
|
||||
})
|
131
node_modules/buffer/test/write.js
generated
vendored
Normal file
131
node_modules/buffer/test/write.js
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
var isnan = require('is-nan')
|
||||
|
||||
test('buffer.write string should get parsed as number', function (t) {
|
||||
var b = new B(64)
|
||||
b.writeUInt16LE('1003', 0)
|
||||
t.equal(b.readUInt16LE(0), 1003)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('buffer.writeUInt8 a fractional number will get Math.floored', function (t) {
|
||||
// Some extra work is necessary to make this test pass with the Object implementation
|
||||
|
||||
var b = new B(1)
|
||||
b.writeInt8(5.5, 0)
|
||||
t.equal(b[0], 5)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('writeUint8 with a negative number throws', function (t) {
|
||||
var buf = new B(1)
|
||||
|
||||
t.throws(function () {
|
||||
buf.writeUInt8(-3, 0)
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('hex of write{Uint,Int}{8,16,32}{LE,BE}', function (t) {
|
||||
t.plan(2 * (2 * 2 * 2 + 2))
|
||||
var hex = [
|
||||
'03', '0300', '0003', '03000000', '00000003',
|
||||
'fd', 'fdff', 'fffd', 'fdffffff', 'fffffffd'
|
||||
]
|
||||
var reads = [ 3, 3, 3, 3, 3, -3, -3, -3, -3, -3 ]
|
||||
var xs = ['UInt', 'Int']
|
||||
var ys = [8, 16, 32]
|
||||
for (var i = 0; i < xs.length; i++) {
|
||||
var x = xs[i]
|
||||
for (var j = 0; j < ys.length; j++) {
|
||||
var y = ys[j]
|
||||
var endianesses = (y === 8) ? [''] : ['LE', 'BE']
|
||||
for (var k = 0; k < endianesses.length; k++) {
|
||||
var z = endianesses[k]
|
||||
|
||||
var v1 = new B(y / 8)
|
||||
var writefn = 'write' + x + y + z
|
||||
var val = (x === 'Int') ? -3 : 3
|
||||
v1[writefn](val, 0)
|
||||
t.equal(
|
||||
v1.toString('hex'),
|
||||
hex.shift()
|
||||
)
|
||||
var readfn = 'read' + x + y + z
|
||||
t.equal(
|
||||
v1[readfn](0),
|
||||
reads.shift()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('hex of write{Uint,Int}{8,16,32}{LE,BE} with overflow', function (t) {
|
||||
if (!B.TYPED_ARRAY_SUPPORT) {
|
||||
t.pass('object impl: skipping overflow test')
|
||||
t.end()
|
||||
return
|
||||
}
|
||||
|
||||
t.plan(3 * (2 * 2 * 2 + 2))
|
||||
var hex = [
|
||||
'', '03', '00', '030000', '000000',
|
||||
'', 'fd', 'ff', 'fdffff', 'ffffff'
|
||||
]
|
||||
var reads = [
|
||||
undefined, 3, 0, NaN, 0,
|
||||
undefined, 253, -256, 16777213, -256
|
||||
]
|
||||
var xs = ['UInt', 'Int']
|
||||
var ys = [8, 16, 32]
|
||||
for (var i = 0; i < xs.length; i++) {
|
||||
var x = xs[i]
|
||||
for (var j = 0; j < ys.length; j++) {
|
||||
var y = ys[j]
|
||||
var endianesses = (y === 8) ? [''] : ['LE', 'BE']
|
||||
for (var k = 0; k < endianesses.length; k++) {
|
||||
var z = endianesses[k]
|
||||
|
||||
var v1 = new B(y / 8 - 1)
|
||||
var next = new B(4)
|
||||
next.writeUInt32BE(0, 0)
|
||||
var writefn = 'write' + x + y + z
|
||||
var val = (x === 'Int') ? -3 : 3
|
||||
v1[writefn](val, 0, true)
|
||||
t.equal(
|
||||
v1.toString('hex'),
|
||||
hex.shift()
|
||||
)
|
||||
// check that nothing leaked to next buffer.
|
||||
t.equal(next.readUInt32BE(0), 0)
|
||||
// check that no bytes are read from next buffer.
|
||||
next.writeInt32BE(~0, 0)
|
||||
var readfn = 'read' + x + y + z
|
||||
var r = reads.shift()
|
||||
if (isnan(r)) t.pass('equal')
|
||||
else t.equal(v1[readfn](0, true), r)
|
||||
}
|
||||
}
|
||||
}
|
||||
t.end()
|
||||
})
|
||||
test('large values do not improperly roll over (ref #80)', function (t) {
|
||||
var nums = [-25589992, -633756690, -898146932]
|
||||
var out = new B(12)
|
||||
out.fill(0)
|
||||
out.writeInt32BE(nums[0], 0)
|
||||
var newNum = out.readInt32BE(0)
|
||||
t.equal(nums[0], newNum)
|
||||
out.writeInt32BE(nums[1], 4)
|
||||
newNum = out.readInt32BE(4)
|
||||
t.equal(nums[1], newNum)
|
||||
out.writeInt32BE(nums[2], 8)
|
||||
newNum = out.readInt32BE(8)
|
||||
t.equal(nums[2], newNum)
|
||||
t.end()
|
||||
})
|
45
node_modules/buffer/test/write_infinity.js
generated
vendored
Normal file
45
node_modules/buffer/test/write_infinity.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
if (process.env.OBJECT_IMPL) global.TYPED_ARRAY_SUPPORT = false
|
||||
var B = require('../').Buffer
|
||||
var test = require('tape')
|
||||
|
||||
test('write/read Infinity as a float', function (t) {
|
||||
var buf = new B(4)
|
||||
t.equal(buf.writeFloatBE(Infinity, 0), 4)
|
||||
t.equal(buf.readFloatBE(0), Infinity)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('write/read -Infinity as a float', function (t) {
|
||||
var buf = new B(4)
|
||||
t.equal(buf.writeFloatBE(-Infinity, 0), 4)
|
||||
t.equal(buf.readFloatBE(0), -Infinity)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('write/read Infinity as a double', function (t) {
|
||||
var buf = new B(8)
|
||||
t.equal(buf.writeDoubleBE(Infinity, 0), 8)
|
||||
t.equal(buf.readDoubleBE(0), Infinity)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('write/read -Infinity as a double', function (t) {
|
||||
var buf = new B(8)
|
||||
t.equal(buf.writeDoubleBE(-Infinity, 0), 8)
|
||||
t.equal(buf.readDoubleBE(0), -Infinity)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('write/read float greater than max', function (t) {
|
||||
var buf = new B(4)
|
||||
t.equal(buf.writeFloatBE(4e38, 0), 4)
|
||||
t.equal(buf.readFloatBE(0), Infinity)
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('write/read float less than min', function (t) {
|
||||
var buf = new B(4)
|
||||
t.equal(buf.writeFloatBE(-4e40, 0), 4)
|
||||
t.equal(buf.readFloatBE(0), -Infinity)
|
||||
t.end()
|
||||
})
|
Reference in New Issue
Block a user