index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. var test = require('tape');
  3. var inspect = require('object-inspect');
  4. var forEach = require('for-each');
  5. var v = require('es-value-fixtures');
  6. var whichBoxedPrimitive = require('../');
  7. var objects = [
  8. /a/g,
  9. new Date(),
  10. function () {},
  11. [],
  12. {}
  13. ].concat(v.objects);
  14. test('isBoxedPrimitive', function (t) {
  15. t.test('unboxed primitives', function (st) {
  16. forEach(v.primitives, function (primitive) {
  17. st.equal(null, whichBoxedPrimitive(primitive), inspect(primitive) + ' is a primitive, but not a boxed primitive');
  18. });
  19. st.end();
  20. });
  21. t.test('boxed primitives', function (st) {
  22. forEach(v.primitives, function (primitive) {
  23. if (primitive != null) { // eslint-disable-line eqeqeq
  24. var boxed = Object(primitive);
  25. var expected = boxed.constructor.name;
  26. st.equal(typeof expected, 'string', 'expected is string');
  27. st.equal(whichBoxedPrimitive(boxed), expected, inspect(boxed) + ' is a boxed primitive: ' + expected);
  28. }
  29. });
  30. st.end();
  31. });
  32. t.test('non-primitive objects', function (st) {
  33. forEach(objects, function (object) {
  34. st.equal(undefined, whichBoxedPrimitive(object), inspect(object) + ' is not a primitive, boxed or otherwise');
  35. });
  36. st.end();
  37. });
  38. t.end();
  39. });