redeyed-mixed.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 result = redeyed(code, opts).code
  11. this.equals(result, expected, inspect(code) + ' => ' + inspect(expected))
  12. return this
  13. }
  14. t.end()
  15. })
  16. test('\nmixed config, keywords', function(t) {
  17. var opts001 = {
  18. Keyword: {
  19. 'this': function(s) { return '_' + s }
  20. , 'if': { _before: '^' }
  21. , _default: '*:&'
  22. }
  23. }
  24. t.test('\n# ' + inspect(opts001), function(t) {
  25. t.assertSurrounds('if (this.hello) return "world";', opts001, '^if& (_this.hello) *return& "world";').end()
  26. })
  27. var opts002 = {
  28. Keyword: {
  29. 'this': function(s) { return '_' + s }
  30. , 'if': { _before: '^' }
  31. , 'return': ':)'
  32. , _default: ':&'
  33. }
  34. , _default: '*:&'
  35. }
  36. t.test('\n# ' + inspect(opts002), function(t) {
  37. t.assertSurrounds('if (this.hello) return "world";', opts002, '^if& (_this.hello) *return) "world";').end()
  38. })
  39. t.end()
  40. })