source: frontend/node_modules/shell-quote/test/env.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3var test = require('tape');
4var parse = require('../').parse;
5
6test('expand environment variables', function (t) {
7 t.same(parse('a $XYZ c', { XYZ: 'b' }), ['a', 'b', 'c']);
8 t.same(parse('a${XYZ}c', { XYZ: 'b' }), ['abc']);
9 t.same(parse('a${XYZ}c $XYZ', { XYZ: 'b' }), ['abc', 'b']);
10 t.same(parse('"-$X-$Y-"', { X: 'a', Y: 'b' }), ['-a-b-']);
11 t.same(parse("'-$X-$Y-'", { X: 'a', Y: 'b' }), ['-$X-$Y-']);
12 t.same(parse('qrs"$zzz"wxy', { zzz: 'tuv' }), ['qrstuvwxy']);
13 t.same(parse("qrs'$zzz'wxy", { zzz: 'tuv' }), ['qrs$zzzwxy']);
14 t.same(parse('qrs${zzz}wxy'), ['qrswxy']);
15 t.same(parse('qrs$wxy $'), ['qrs', '$']);
16 t.same(parse('grep "xy$"'), ['grep', 'xy$']);
17 t.same(parse('ab$x', { x: 'c' }), ['abc']);
18 t.same(parse('ab\\$x', { x: 'c' }), ['ab$x']);
19 t.same(parse('ab${x}def', { x: 'c' }), ['abcdef']);
20 t.same(parse('ab\\${x}def', { x: 'c' }), ['ab${x}def']);
21 t.same(parse('"ab\\${x}def"', { x: 'c' }), ['ab${x}def']);
22
23 t.end();
24});
25
26test('expand environment variables within here-strings', function (t) {
27 t.same(parse('a <<< $x', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']);
28 t.same(parse('a <<< ${x}', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']);
29 t.same(parse('a <<< "$x"', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']);
30 t.same(parse('a <<< "${x}"', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']);
31
32 t.end();
33});
34
35test('environment variables with metacharacters', function (t) {
36 t.same(parse('a $XYZ c', { XYZ: '"b"' }), ['a', '"b"', 'c']);
37 t.same(parse('a $XYZ c', { XYZ: '$X', X: 5 }), ['a', '$X', 'c']);
38 t.same(parse('a"$XYZ"c', { XYZ: "'xyz'" }), ["a'xyz'c"]);
39
40 t.end();
41});
42
43test('special shell parameters', function (t) {
44 var chars = '*@#?-$!0_'.split('');
45 t.plan(chars.length);
46
47 chars.forEach(function (c) {
48 var env = {};
49 env[c] = 'xxx';
50 t.same(parse('a $' + c + ' c', env), ['a', 'xxx', 'c']);
51 });
52});
Note: See TracBrowser for help on using the repository browser.