You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.8 KiB

7 years ago
  1. var hasBinary = require('./');
  2. var assert = require('better-assert');
  3. var fs = require('fs');
  4. describe('has-binarydata', function(){
  5. it('should work with buffer', function(){
  6. assert(hasBinary(fs.readFileSync('./test.js')));
  7. });
  8. it('should work with an array that does not contain binary', function() {
  9. var arr = [1, 'cool', 2];
  10. assert(!hasBinary(arr));
  11. });
  12. it('should work with an array that contains a buffer', function() {
  13. var arr = [1, new Buffer('asdfasdf', 'utf8'), 2];
  14. assert(hasBinary(arr));
  15. });
  16. it('should work with an object that does not contain binary', function() {
  17. var ob = {a: 'a', b: [], c: 1234, toJSON: '{\"a\": \"a\"}'};
  18. assert(!hasBinary(ob));
  19. });
  20. it('should work with an object that contains a buffer', function() {
  21. var ob = {a: 'a', b: new Buffer('abc'), c: 1234, toJSON: '{\"a\": \"a\"}'};
  22. assert(hasBinary(ob));
  23. });
  24. it('should work with null', function() {
  25. assert(!hasBinary(null));
  26. });
  27. it('should work with undefined', function() {
  28. assert(!hasBinary(undefined));
  29. });
  30. it('should work with a complex object that contains undefined and no binary', function() {
  31. var ob = {
  32. x: ['a', 'b', 123],
  33. y: undefined,
  34. z: {a: 'x', b: 'y', c: 3, d: null},
  35. w: []
  36. };
  37. assert(!hasBinary(ob));
  38. });
  39. it('should work with a complex object that contains undefined and binary', function() {
  40. var ob = {
  41. x: ['a', 'b', 123],
  42. y: undefined,
  43. z: {a: 'x', b: 'y', c: 3, d: null},
  44. w: [],
  45. bin: new Buffer('xxx')
  46. };
  47. assert(hasBinary(ob));
  48. });
  49. if (global.ArrayBuffer) {
  50. it('should work with an ArrayBuffer', function() {
  51. assert(hasBinary(new ArrayBuffer()));
  52. });
  53. }
  54. if (global.Blob) {
  55. it('should work with a Blob', function() {
  56. assert(hasBinary(new Blob()));
  57. });
  58. }
  59. });