})
test('new buffer from string', function (t) {
- t.plan(1)
t.equal(
new B('hey', 'utf8').toString(),
'hey'
})
test('buffer toJSON()', function (t) {
- t.plan(1)
var data = [1, 2, 3, 4]
t.deepEqual(
new B(data).toJSON(),
})
test('buffer copy example', function (t) {
- t.plan(1)
-
- buf1 = new B(26)
- buf2 = new B(26)
+ 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
})
test('utf16le to utf16', function (t) {
- t.plan(1);
t.equal(
new B(new B('abcd', 'utf8').toString('utf16le'), 'utf16le').toString('utf8'),
'abcd'
- );
- t.end();
-});
+ )
+ t.end()
+})
test('utf16le to hex', function (t) {
- t.plan(1);
t.equal(
new B('abcd', 'utf16le').toString('hex'),
'6100620063006400'
- );
- t.end();
-});
+ )
+ t.end()
+})
test('ascii buffer to base64', function (t) {
t.equal(
})
test('concat() a varying number of buffers', function (t) {
- t.plan(5)
var zero = []
var one = [ new B('asdf') ]
var long = []
})
test('fill', function(t) {
- t.plan(1)
var b = new B(10)
b.fill(2)
t.equal(b.toString('hex'), '02020202020202020202')
})
test('copy() empty buffer with sourceEnd=0', function (t) {
- t.plan(1)
var source = new B([42])
var destination = new B([43])
source.copy(destination, 0, 0, 0)
})
test('copy() after slice()', function(t) {
- t.plan(1)
var source = new B(200)
var dest = new B(200)
var expected = new B(200)
source[i] = i
dest[i] = 0
}
-
+
source.slice(2).copy(dest)
source.copy(expected, 0, 2)
t.deepEqual(dest, expected)
})
test('base64 ignore whitespace', function(t) {
- t.plan(1)
var text = '\n YW9ldQ== '
var buf = new B(text, 'base64')
t.equal(buf.toString(), 'aoeu')
})
test('buffer.slice sets indexes', function (t) {
- t.plan(1)
t.equal((new B('hallo')).slice(0, 5).toString(), 'hallo')
t.end()
})
})
test('base64 strings without padding', function (t) {
- t.plan(1)
t.equal((new B('YW9ldQ', 'base64').toString()), 'aoeu')
t.end()
})
var test = require('tape')
test('indexes from a string', function(t) {
- t.plan(3)
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) {
- t.plan(3)
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('set then modify indexes from an array', function(t) {
- t.plan(4)
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()
})
var test = require('tape')
test('Buffer.isBuffer', function (t) {
- t.plan(3)
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)
var test = require('tape')
test('Buffer.isEncoding', function (t) {
- t.plan(3)
t.equal(B.isEncoding('HEX'), true)
t.equal(B.isEncoding('hex'), true)
t.equal(B.isEncoding('bad'), false)
var test = require('tape')
test('detect utf16 surrogate pairs', function(t) {
- t.plan(1)
var text = '\uD83D\uDE38' + '\uD83D\uDCAD' + '\uD83D\uDC4D'
var buf = new B(text)
t.equal(text, buf.toString())
})
test('throw on orphaned utf16 surrogate lead code point', function(t) {
- t.plan(1)
var text = '\uD83D\uDE38' + '\uD83D' + '\uD83D\uDC4D'
var err
try {
})
test('throw on orphaned utf16 surrogate trail code point', function(t) {
- t.plan(1)
var text = '\uD83D\uDE38' + '\uDCAD' + '\uD83D\uDC4D'
var err
try {