redeyed-incomplete.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict'
  2. var test = require('tape')
  3. var util = require('util')
  4. var redeyed = require('..')
  5. function inspect(obj) {
  6. return util.inspect(obj, false, 5, true)
  7. }
  8. test('adding custom asserts ... ', function(t) {
  9. t.constructor.prototype.assertSurrounds = function(code, opts, expected) {
  10. var optsi = inspect(opts)
  11. var result = redeyed(code, opts).code
  12. this.equals(result
  13. , expected
  14. , util.format('%s: %s => %s', optsi, inspect(code), inspect(expected))
  15. )
  16. return this
  17. }
  18. t.end()
  19. })
  20. test('incomplete statement', function(t) {
  21. t.test('\n# Keyword', function(t) {
  22. var keyconfig = { 'Keyword': { _default: '$:%' } }
  23. t.assertSurrounds('if(foo) { x', keyconfig, '$if%(foo) { x')
  24. t.assertSurrounds('class Foo { constructor(name)', keyconfig, '$class% Foo { constructor(name)')
  25. t.assertSurrounds('const x = ', keyconfig, '$const% x = ')
  26. t.assertSurrounds('function g() { yield', keyconfig, '$function% g() { $yield%')
  27. t.end()
  28. })
  29. t.end()
  30. })