redeyed-config-with-undefineds.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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('\n undefineds only', function(t) {
  21. t.assertSurrounds('1 + 2', { Numeric: { _default: undefined } }, '1 + 2')
  22. t.assertSurrounds('1 + 2', { Numeric: { _default: undefined }, _default: undefined }, '1 + 2')
  23. t.assertSurrounds(
  24. 'return true'
  25. , { 'Boolean': { 'true': undefined, 'false': undefined, _default: undefined }, _default: undefined }
  26. , 'return true'
  27. )
  28. t.end()
  29. })
  30. test('\n mixed', function(t) {
  31. t.assertSurrounds(
  32. 'return true || false'
  33. , { 'Boolean': { 'true': '&:', 'false': undefined, _default: undefined }, _default: undefined }
  34. , 'return &true || false'
  35. )
  36. t.assertSurrounds(
  37. 'return true || false'
  38. , { 'Boolean': { 'true': '&:', 'false': undefined, _default: ':?' }, _default: undefined }
  39. , 'return &true? || false?'
  40. )
  41. t.assertSurrounds(
  42. 'return true || false'
  43. , { 'Boolean': { 'true': '&:', 'false': undefined, _default: undefined }, _default: ':?' }
  44. , 'return &true? || false'
  45. )
  46. t.end()
  47. })