a5fb330c27be09b5507655ff0ee556b635644133.svn-base
1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
var test = require('tape')
var util = require('util')
var redeyed = require('..')
function inspect(obj) {
return util.inspect(obj, false, 5, true)
}
test('adding custom asserts ... ', function(t) {
t.constructor.prototype.assertSurrounds = function(code, opts, expected) {
var result = redeyed(code, opts).code
this.equals(result, expected, inspect(code) + ' => ' + inspect(expected))
return this
}
t.end()
})
test('\nbefore/after config, keywords', function(t) {
var opts001 = { Keyword: { _default: { _before: '*', _after: '&' } } }
t.test('\n# ' + inspect(opts001), function(t) {
t.assertSurrounds('this', opts001, '*this&')
t.assertSurrounds('if (a == 1) return', opts001, '*if& (a == 1) *return&')
t.assertSurrounds('var n = new Test();', opts001, '*var& n = *new& Test();')
t.end()
})
var opts002 = {
Keyword: {
'function': { _before: '^' }
, 'return': { _before: '(', _after: ')' }
, _default: { _before: '*', _after: '&' }
}
}
t.test('\n# ' + inspect(opts002), function(t) {
t.assertSurrounds(
[ 'function foo (bar) {'
, ' var a = 3;'
, ' return bar + a;'
, '}'
].join('\n')
, opts002
, [ '^function& foo (bar) {'
, ' *var& a = 3;'
, ' (return) bar + a;'
, '}'
].join('\n'))
t.end()
})
t.end()
})