source: node_modules/expand-template/test.js@ 62b2964

finki-main main
Last change on this file since 62b2964 was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

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