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.1 KiB

4 years ago
  1. 'use strict';
  2. var test = require('tape');
  3. var debug = require('object-inspect');
  4. var forEach = require('foreach');
  5. var v = require('./values');
  6. var getSymbolDescription = require('../../helpers/getSymbolDescription');
  7. test('getSymbolDescription', function (t) {
  8. t.test('no symbols', { skip: v.hasSymbols }, function (st) {
  9. st['throws'](
  10. getSymbolDescription,
  11. SyntaxError,
  12. 'requires Symbol support'
  13. );
  14. st.end();
  15. });
  16. forEach(v.nonSymbolPrimitives.concat(v.objects), function (nonSymbol) {
  17. t['throws'](
  18. function () { getSymbolDescription(nonSymbol); },
  19. TypeError,
  20. debug(nonSymbol) + ' is not a Symbol'
  21. );
  22. });
  23. t.test('with symbols', { skip: !v.hasSymbols }, function (st) {
  24. forEach(
  25. [
  26. [Symbol(), undefined],
  27. [Symbol(undefined), undefined],
  28. [Symbol(null), 'null'],
  29. [Symbol(''), ''],
  30. [Symbol.iterator, 'Symbol.iterator'],
  31. [Symbol('foo'), 'foo']
  32. ],
  33. function (pair) {
  34. var sym = pair[0];
  35. var desc = pair[1];
  36. st.equal(getSymbolDescription(sym), desc, debug(sym) + ' yields ' + debug(desc));
  37. }
  38. );
  39. st.end();
  40. });
  41. t.end();
  42. });