redeyed-upcoming.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict'
  2. /* eslint-disable no-template-curly-in-string */
  3. var test = require('tape')
  4. var util = require('util')
  5. var 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. })