cmp.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. var test = require('tape');
  2. var equal = require('../');
  3. var isArguments = require('../lib/is_arguments.js');
  4. var objectKeys = require('../lib/keys.js');
  5. test('equal', function (t) {
  6. t.ok(equal(
  7. { a : [ 2, 3 ], b : [ 4 ] },
  8. { a : [ 2, 3 ], b : [ 4 ] }
  9. ));
  10. t.end();
  11. });
  12. test('not equal', function (t) {
  13. t.notOk(equal(
  14. { x : 5, y : [6] },
  15. { x : 5, y : 6 }
  16. ));
  17. t.end();
  18. });
  19. test('nested nulls', function (t) {
  20. t.ok(equal([ null, null, null ], [ null, null, null ]));
  21. t.end();
  22. });
  23. test('strict equal', function (t) {
  24. t.notOk(equal(
  25. [ { a: 3 }, { b: 4 } ],
  26. [ { a: '3' }, { b: '4' } ],
  27. { strict: true }
  28. ));
  29. t.end();
  30. });
  31. test('non-objects', function (t) {
  32. t.ok(equal(3, 3));
  33. t.ok(equal('beep', 'beep'));
  34. t.ok(equal('3', 3));
  35. t.notOk(equal('3', 3, { strict: true }));
  36. t.notOk(equal('3', [3]));
  37. t.end();
  38. });
  39. test('arguments class', function (t) {
  40. t.ok(equal(
  41. (function(){return arguments})(1,2,3),
  42. (function(){return arguments})(1,2,3),
  43. "compares arguments"
  44. ));
  45. t.notOk(equal(
  46. (function(){return arguments})(1,2,3),
  47. [1,2,3],
  48. "differenciates array and arguments"
  49. ));
  50. t.end();
  51. });
  52. test('test the arguments shim', function (t) {
  53. t.ok(isArguments.supported((function(){return arguments})()));
  54. t.notOk(isArguments.supported([1,2,3]));
  55. t.ok(isArguments.unsupported((function(){return arguments})()));
  56. t.notOk(isArguments.unsupported([1,2,3]));
  57. t.end();
  58. });
  59. test('test the keys shim', function (t) {
  60. t.deepEqual(objectKeys.shim({ a: 1, b : 2 }), [ 'a', 'b' ]);
  61. t.end();
  62. });
  63. test('dates', function (t) {
  64. var d0 = new Date(1387585278000);
  65. var d1 = new Date('Fri Dec 20 2013 16:21:18 GMT-0800 (PST)');
  66. t.ok(equal(d0, d1));
  67. t.end();
  68. });
  69. test('buffers', function (t) {
  70. t.ok(equal(Buffer('xyz'), Buffer('xyz')));
  71. t.end();
  72. });
  73. test('booleans and arrays', function (t) {
  74. t.notOk(equal(true, []));
  75. t.end();
  76. })
  77. test('null == undefined', function (t) {
  78. t.ok(equal(null, undefined))
  79. t.notOk(equal(null, undefined, { strict: true }))
  80. t.end()
  81. })