arnaucube
arnaucube/raspberryGPIOhtmlserverPublic Self-hosted repository
raspberryGPIOhtmlserver/node_modules/has-binary/test.js
node_modules/has-binary/test.jsRaw
  1
  2var hasBinary = require('./');
  3var assert = require('better-assert');
  4var fs = require('fs');
  5
  6var start = new Date();
  7
  8describe('has-binarydata', function(){
  9
 10  it('should work with buffer', function(){
 11    assert(hasBinary(fs.readFileSync('./test.js')));
 12  });
 13
 14  it('should work with an array that does not contain binary', function() {
 15    var arr = [1, 'cool', 2];
 16    assert(!hasBinary(arr));
 17  });
 18
 19  it('should work with an array that contains a buffer', function() {
 20    var arr = [1, new Buffer('asdfasdf', 'utf8'), 2];
 21    assert(hasBinary(arr));
 22  });
 23
 24  it('should work with an object that does not contain binary', function() {
 25    var ob = {a: 'a', b: [], c: 1234};
 26    assert(!hasBinary(ob));
 27  });
 28
 29  it('should work with an object that contains a buffer', function() {
 30    var ob = {a: 'a', b: new Buffer('abc'), c: 1234};
 31    assert(hasBinary(ob));
 32  });
 33
 34  it('should work with null', function() {
 35    assert(!hasBinary(null));
 36  });
 37
 38  it('should work with undefined', function() {
 39    assert(!hasBinary(undefined));
 40  });
 41
 42  it('should work with a complex object that contains undefined and no binary', function() {
 43    var ob = {
 44      x: ['a', 'b', 123],
 45      y: undefined,
 46      z: {a: 'x', b: 'y', c: 3, d: null},
 47      w: []
 48    };
 49    assert(!hasBinary(ob));
 50  });
 51
 52  it('should work with a complex object that contains undefined and binary', function() {
 53    var ob = {
 54      x: ['a', 'b', 123],
 55      y: undefined,
 56      z: {a: 'x', b: 'y', c: 3, d: null},
 57      w: [],
 58      bin: new Buffer('xxx')
 59    };
 60    assert(hasBinary(ob));
 61  });
 62
 63  it('should handle a very large json object with no binary', function(done) {
 64    this.timeout();
 65    fs.readFile(__dirname + '/fixtures/big.json', function(err, data) {
 66      if (err) {
 67        console.log(err);
 68        assert(false);
 69      }
 70      data = JSON.parse(data);
 71      assert(!hasBinary(data));
 72      done();
 73    });
 74  });
 75
 76  it('should handle a very large json object with binary', function(done) {
 77    this.timeout();
 78    fs.readFile(__dirname + '/fixtures/big.json', function(err, data) {
 79      if (err) {
 80        console.log(err);
 81        assert(false);
 82      }
 83      var ob = JSON.parse(data);
 84      ob.bin = {bin: {bin: {bin: new Buffer('abc')}}};
 85      assert(hasBinary(ob));
 86      done();
 87    });
 88  });
 89
 90  if (global.ArrayBuffer) {
 91      it('should work with an ArrayBuffer', function() {
 92        assert(hasBinary(new ArrayBuffer()));
 93      });
 94  }
 95
 96  if (global.Blob) {
 97     it('should work with a Blob', function() {
 98        assert(hasBinary(new Blob()));
 99     });
100  }
101
102  it('should print the test time', function() {
103    var end = new Date();
104    var diff = end - start;
105    console.log('\ntest time: ' + diff + ' ms');
106  });
107
108});