redeyed-upcoming.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. /*jshint asi: true*/
  3. var test = require('tap').test
  4. , util = require('util')
  5. , redeyed = require('..')
  6. function inspect (obj) {
  7. return util.inspect(obj, false, 5, true)
  8. }
  9. test('adding custom asserts ... ', function (t) {
  10. t.constructor.prototype.assertSurrounds = function (code, opts, expected) {
  11. var optsi = inspect(opts);
  12. var result = redeyed(code, opts).code
  13. this.equals( result
  14. , expected
  15. , util.format('%s: %s => %s', optsi, inspect(code), inspect(expected))
  16. )
  17. return this;
  18. }
  19. t.end()
  20. })
  21. test('upcoming syntax: rest and spread properties', function (t) {
  22. t.test('\n# Punctuator', function (t) {
  23. var punctuator = { 'Punctuator': { _default: '$:%' } };
  24. t.assertSurrounds('{a,...b} = c', punctuator, '${%a$,%$...%b$}% $=% c')
  25. t.assertSurrounds('x={y,...z}', punctuator, 'x$=%${%y$,%$...%z$}%')
  26. t.assertSurrounds('x ** y', punctuator, 'x $**% y');
  27. t.assertSurrounds('x **= y', punctuator, 'x $**=% y');
  28. t.end()
  29. })
  30. t.test('\n# Identifier', function (t) {
  31. var identifier = { 'Identifier': { _default: '$:%' } };
  32. t.assertSurrounds('{a,...b} = c', identifier, '{$a%,...$b%} = $c%')
  33. t.assertSurrounds('x={y,...z}', identifier, '$x%={$y%,...$z%}')
  34. t.end()
  35. })
  36. t.end()
  37. })