react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / buffer / test / constructor.js
80724 viewsvar B = require('../').Buffer1var test = require('tape')2if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false345test('new buffer from array', function (t) {6t.equal(7new B([1, 2, 3]).toString(),8'\u0001\u0002\u0003'9)10t.end()11})1213test('new buffer from array w/ negatives', function (t) {14t.equal(15new B([-1, -2, -3]).toString('hex'),16'fffefd'17)18t.end()19})2021test('new buffer from array with mixed signed input', function (t) {22t.equal(23new B([-255, 255, -128, 128, 512, -512, 511, -511]).toString('hex'),24'01ff80800000ff01'25)26t.end()27})2829test('new buffer from string', function (t) {30t.equal(31new B('hey', 'utf8').toString(),32'hey'33)34t.end()35})3637test('new buffer from buffer', function (t) {38var b1 = new B('asdf')39var b2 = new B(b1)40t.equal(b1.toString('hex'), b2.toString('hex'))41t.end()42})4344test('new buffer from Uint8Array', function (t) {45if (typeof Uint8Array !== 'undefined') {46var b1 = new Uint8Array([0, 1, 2, 3])47var b2 = new B(b1)48t.equal(b1.length, b2.length)49t.equal(b1[0], 0)50t.equal(b1[1], 1)51t.equal(b1[2], 2)52t.equal(b1[3], 3)53t.equal(b1[4], undefined)54}55t.end()56})5758test('new buffer from Uint16Array', function (t) {59if (typeof Uint16Array !== 'undefined') {60var b1 = new Uint16Array([0, 1, 2, 3])61var b2 = new B(b1)62t.equal(b1.length, b2.length)63t.equal(b1[0], 0)64t.equal(b1[1], 1)65t.equal(b1[2], 2)66t.equal(b1[3], 3)67t.equal(b1[4], undefined)68}69t.end()70})7172test('new buffer from Uint32Array', function (t) {73if (typeof Uint32Array !== 'undefined') {74var b1 = new Uint32Array([0, 1, 2, 3])75var b2 = new B(b1)76t.equal(b1.length, b2.length)77t.equal(b1[0], 0)78t.equal(b1[1], 1)79t.equal(b1[2], 2)80t.equal(b1[3], 3)81t.equal(b1[4], undefined)82}83t.end()84})8586test('new buffer from Int16Array', function (t) {87if (typeof Int16Array !== 'undefined') {88var b1 = new Int16Array([0, 1, 2, 3])89var b2 = new B(b1)90t.equal(b1.length, b2.length)91t.equal(b1[0], 0)92t.equal(b1[1], 1)93t.equal(b1[2], 2)94t.equal(b1[3], 3)95t.equal(b1[4], undefined)96}97t.end()98})99100test('new buffer from Int32Array', function (t) {101if (typeof Int32Array !== 'undefined') {102var b1 = new Int32Array([0, 1, 2, 3])103var b2 = new B(b1)104t.equal(b1.length, b2.length)105t.equal(b1[0], 0)106t.equal(b1[1], 1)107t.equal(b1[2], 2)108t.equal(b1[3], 3)109t.equal(b1[4], undefined)110}111t.end()112})113114test('new buffer from Float32Array', function (t) {115if (typeof Float32Array !== 'undefined') {116var b1 = new Float32Array([0, 1, 2, 3])117var b2 = new B(b1)118t.equal(b1.length, b2.length)119t.equal(b1[0], 0)120t.equal(b1[1], 1)121t.equal(b1[2], 2)122t.equal(b1[3], 3)123t.equal(b1[4], undefined)124}125t.end()126})127128test('new buffer from Float64Array', function (t) {129if (typeof Float64Array !== 'undefined') {130var b1 = new Float64Array([0, 1, 2, 3])131var b2 = new B(b1)132t.equal(b1.length, b2.length)133t.equal(b1[0], 0)134t.equal(b1[1], 1)135t.equal(b1[2], 2)136t.equal(b1[3], 3)137t.equal(b1[4], undefined)138}139t.end()140})141142test('new buffer from buffer.toJSON() output', function (t) {143if (typeof JSON === 'undefined') {144// ie6, ie7 lack support145t.end()146return147}148var buf = new B('test')149var json = JSON.stringify(buf)150var obj = JSON.parse(json)151var copy = new B(obj)152t.ok(buf.equals(copy))153t.end()154})155156157158