test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. var test = require('tape')
  2. var Expand = require('./')
  3. test('default expands {} placeholders', function (t) {
  4. var expand = Expand()
  5. t.equal(typeof expand, 'function', 'is a function')
  6. t.equal(expand('{foo}/{bar}', {
  7. foo: 'BAR', bar: 'FOO'
  8. }), 'BAR/FOO')
  9. t.equal(expand('{foo}{foo}{foo}', {
  10. foo: 'FOO'
  11. }), 'FOOFOOFOO', 'expands one placeholder many times')
  12. t.end()
  13. })
  14. test('support for custom separators', function (t) {
  15. var expand = Expand({ sep: '[]' })
  16. t.equal(expand('[foo]/[bar]', {
  17. foo: 'BAR', bar: 'FOO'
  18. }), 'BAR/FOO')
  19. t.equal(expand('[foo][foo][foo]', {
  20. foo: 'FOO'
  21. }), 'FOOFOOFOO', 'expands one placeholder many times')
  22. t.end()
  23. })
  24. test('support for longer custom separators', function (t) {
  25. var expand = Expand({ sep: '[[]]' })
  26. t.equal(expand('[[foo]]/[[bar]]', {
  27. foo: 'BAR', bar: 'FOO'
  28. }), 'BAR/FOO')
  29. t.equal(expand('[[foo]][[foo]][[foo]]', {
  30. foo: 'FOO'
  31. }), 'FOOFOOFOO', 'expands one placeholder many times')
  32. t.end()
  33. })
  34. test('whitespace-insensitive', function (t) {
  35. var expand = Expand({ sep: '[]' })
  36. t.equal(expand('[ foo ]/[ bar ]', {
  37. foo: 'BAR', bar: 'FOO'
  38. }), 'BAR/FOO')
  39. t.equal(expand('[ foo ][ foo ][ foo]', {
  40. foo: 'FOO'
  41. }), 'FOOFOOFOO', 'expands one placeholder many times')
  42. t.end()
  43. })
  44. test('dollar escape', function (t) {
  45. var expand = Expand()
  46. t.equal(expand('before {foo} after', {
  47. foo: '$'
  48. }), 'before $ after')
  49. t.equal(expand('before {foo} after', {
  50. foo: '$&'
  51. }), 'before $& after')
  52. t.equal(expand('before {foo} after', {
  53. foo: '$`'
  54. }), 'before $` after')
  55. t.equal(expand('before {foo} after', {
  56. foo: '$\''
  57. }), 'before $\' after')
  58. t.equal(expand('before {foo} after', {
  59. foo: '$0'
  60. }), 'before $0 after')
  61. t.end()
  62. })