react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / buffer / test / basic.js
80724 viewsvar B = require('../').Buffer1var test = require('tape')2if (process.env.OBJECT_IMPL) B.TYPED_ARRAY_SUPPORT = false34test('convert to Uint8Array in modern browsers', function (t) {5if (B.TYPED_ARRAY_SUPPORT) {6var buf = new B([1, 2])7var uint8array = new Uint8Array(buf.buffer)8t.ok(uint8array instanceof Uint8Array)9t.equal(uint8array[0], 1)10t.equal(uint8array[1], 2)11} else {12t.pass('object impl: skipping test')13}14t.end()15})1617test('indexes from a string', function (t) {18var buf = new B('abc')19t.equal(buf[0], 97)20t.equal(buf[1], 98)21t.equal(buf[2], 99)22t.end()23})2425test('indexes from an array', function (t) {26var buf = new B([ 97, 98, 99 ])27t.equal(buf[0], 97)28t.equal(buf[1], 98)29t.equal(buf[2], 99)30t.end()31})3233test('setting index value should modify buffer contents', function (t) {34var buf = new B([ 97, 98, 99 ])35t.equal(buf[2], 99)36t.equal(buf.toString(), 'abc')3738buf[2] += 1039t.equal(buf[2], 109)40t.equal(buf.toString(), 'abm')41t.end()42})4344test('storing negative number should cast to unsigned', function (t) {45var buf = new B(1)4647if (B.TYPED_ARRAY_SUPPORT) {48// This does not work with the object implementation -- nothing we can do!49buf[0] = -350t.equal(buf[0], 253)51}5253buf = new B(1)54buf.writeInt8(-3, 0)55t.equal(buf[0], 253)5657t.end()58})5960// TODO: test write negative with616263