-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapi.variables.js
More file actions
19 lines (17 loc) · 1.15 KB
/
api.variables.js
File metadata and controls
19 lines (17 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'use strict';
require('mocha');
const assert = require('assert').strict;
const { render } = require('../lib/Parser');
describe('api - variables', () => {
it('should expose variables from the context', () => {
let data = { TM_LINE_NUMBER: 10, FILE_NAME: 'AbCdE.FgH', USERNAME: 'jonschlinkert' };
assert.equal(render('${TM_LINE_NUMBER/(10)/${1:+It is}/} line 10', data), 'It is line 10');
assert.equal(render('${TM_LINE_NUMBER/(10)/${1:?It is:It is not}/} line 10', data), 'It is line 10');
assert.equal(render('${TM_LINE_NUMBER/(11)/${1:?It is:It is not}/} line 11', data), 'It is not line 11');
assert.equal(render('${TM_LINE_NUMBER/(11)/${1:-It is not}/} line 11', data), 'It is not line 11');
assert.equal(render('before ${USERNAME/^(.*?)$/${1:/upcase}/} after', data), 'before JONSCHLINKERT after');
assert.equal(render('before ${FILE_NAME/^(.*?)\\.(.*?)$/${1:/upcase}${2:/downcase}/} after', data), 'before ABCDEfgh after');
assert.equal(render('before ${USERNAME/^(.*?)$/${1}/} after', data), 'before jonschlinkert after');
assert.equal(render('before ${USERNAME/^(.*?)$/$1/g} after', data), 'before jonschlinkert after');
});
});