redeyed-mixed.js 1.2 KB

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