|
0 |
/* global describe it Blob */
|
0 | 1 |
|
1 | 2 |
var hasBinary = require('./');
|
2 | 3 |
var assert = require('better-assert');
|
3 | 4 |
var fs = require('fs');
|
4 | 5 |
|
5 | |
describe('has-binarydata', function(){
|
6 | |
|
7 | |
it('should work with buffer', function(){
|
|
6 |
describe('has-binarydata', function () {
|
|
7 |
it('should work with buffer', function () {
|
8 | 8 |
assert(hasBinary(fs.readFileSync('./test.js')));
|
9 | 9 |
});
|
10 | 10 |
|
11 | |
it('should work with an array that does not contain binary', function() {
|
|
11 |
it('should work with an array that does not contain binary', function () {
|
12 | 12 |
var arr = [1, 'cool', 2];
|
13 | 13 |
assert(!hasBinary(arr));
|
14 | 14 |
});
|
15 | 15 |
|
16 | |
it('should work with an array that contains a buffer', function() {
|
|
16 |
it('should work with an array that contains a buffer', function () {
|
17 | 17 |
var arr = [1, new Buffer('asdfasdf', 'utf8'), 2];
|
18 | 18 |
assert(hasBinary(arr));
|
19 | 19 |
});
|
20 | 20 |
|
21 | |
it('should work with an object that does not contain binary', function() {
|
22 | |
var ob = {a: 'a', b: [], c: 1234, toJSON: '{\"a\": \"a\"}'};
|
|
21 |
it('should work with an object that does not contain binary', function () {
|
|
22 |
var ob = {a: 'a', b: [], c: 1234, toJSON: '{"a": "a"}'};
|
23 | 23 |
assert(!hasBinary(ob));
|
24 | 24 |
});
|
25 | 25 |
|
26 | |
it('should work with an object that contains a buffer', function() {
|
27 | |
var ob = {a: 'a', b: new Buffer('abc'), c: 1234, toJSON: '{\"a\": \"a\"}'};
|
|
26 |
it('should work with an object that contains a buffer', function () {
|
|
27 |
var ob = {a: 'a', b: new Buffer('abc'), c: 1234, toJSON: '{"a": "a"}'};
|
28 | 28 |
assert(hasBinary(ob));
|
29 | 29 |
});
|
30 | 30 |
|
31 | |
it('should work with null', function() {
|
|
31 |
it('should work with an object whose toJSON() returns a buffer', function () {
|
|
32 |
var ob = {a: 'a', b: [], c: 1234, toJSON: function () { return new Buffer('abc'); }};
|
|
33 |
assert(hasBinary(ob));
|
|
34 |
});
|
|
35 |
|
|
36 |
it('should work with null', function () {
|
32 | 37 |
assert(!hasBinary(null));
|
33 | 38 |
});
|
34 | 39 |
|
35 | |
it('should work with undefined', function() {
|
|
40 |
it('should work with undefined', function () {
|
36 | 41 |
assert(!hasBinary(undefined));
|
37 | 42 |
});
|
38 | 43 |
|
39 | |
it('should work with a complex object that contains undefined and no binary', function() {
|
|
44 |
it('should work with a complex object that contains undefined and no binary', function () {
|
40 | 45 |
var ob = {
|
41 | 46 |
x: ['a', 'b', 123],
|
42 | 47 |
y: undefined,
|
|
46 | 51 |
assert(!hasBinary(ob));
|
47 | 52 |
});
|
48 | 53 |
|
49 | |
it('should work with a complex object that contains undefined and binary', function() {
|
|
54 |
it('should work with a complex object that contains undefined and binary', function () {
|
50 | 55 |
var ob = {
|
51 | 56 |
x: ['a', 'b', 123],
|
52 | 57 |
y: undefined,
|
|
58 | 63 |
});
|
59 | 64 |
|
60 | 65 |
if (global.ArrayBuffer) {
|
61 | |
it('should work with an ArrayBuffer', function() {
|
62 | |
assert(hasBinary(new ArrayBuffer()));
|
63 | |
});
|
|
66 |
it('should work with an ArrayBuffer', function () {
|
|
67 |
assert(hasBinary(new ArrayBuffer()));
|
|
68 |
});
|
64 | 69 |
}
|
65 | 70 |
|
66 | 71 |
if (global.Blob) {
|
67 | |
it('should work with a Blob', function() {
|
68 | |
assert(hasBinary(new Blob()));
|
69 | |
});
|
|
72 |
it('should work with a Blob', function () {
|
|
73 |
assert(hasBinary(new Blob()));
|
|
74 |
});
|
|
75 |
} else {
|
|
76 |
it('should not crash if global Blob is not a function', function () {
|
|
77 |
global.Blob = [ 1, 2, 3 ];
|
|
78 |
assert(!hasBinary(global.Blob));
|
|
79 |
});
|
70 | 80 |
}
|
71 | |
|
72 | 81 |
});
|