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.

50 lines
1.3 KiB

4 years ago
  1. "use strict";
  2. var test = require('tape');
  3. var is = require('./');
  4. test('works with primitives', function (t) {
  5. t.ok(is(), 'two absent args are the same');
  6. t.ok(is(undefined), 'undefined & one absent arg are the same');
  7. t.ok(is(undefined, undefined), 'undefined is undefined');
  8. t.ok(is(null, null), 'null is null');
  9. t.ok(is(true, true), 'true is true');
  10. t.ok(is(false, false), 'false is false');
  11. t.notOk(is(true, false), 'true is not false');
  12. t.end();
  13. });
  14. test('works with NaN', function (t) {
  15. t.ok(is(NaN, NaN), 'NaN is NaN');
  16. t.end();
  17. });
  18. test('differentiates zeroes', function (t) {
  19. t.ok(is(0, 0), '+0 is +0');
  20. t.ok(is(-0, -0), '-0 is -0');
  21. t.notOk(is(0, -0), '+0 is not -0');
  22. t.end();
  23. });
  24. test('nonzero numbers', function (t) {
  25. t.ok(is(Infinity, Infinity), 'infinity is infinity');
  26. t.ok(is(-Infinity, -Infinity), 'infinity is infinity');
  27. t.ok(is(42, 42), '42 is 42');
  28. t.notOk(is(42, -42), '42 is not -42');
  29. t.end();
  30. });
  31. test('strings', function (t) {
  32. t.ok(is('', ''), 'empty string is empty string');
  33. t.ok(is('foo', 'foo'), 'string is string');
  34. t.notOk(is('foo', 'bar'), 'string is not different string');
  35. t.end();
  36. });
  37. test('objects', function (t) {
  38. var obj = {};
  39. t.ok(is(obj, obj), 'object is same object');
  40. t.notOk(is(obj, {}), 'object is not different object');
  41. t.end();
  42. });