diff options
Diffstat (limited to 'node_modules/shell-quote/test')
| -rw-r--r-- | node_modules/shell-quote/test/comment.js | 16 | ||||
| -rw-r--r-- | node_modules/shell-quote/test/env.js | 52 | ||||
| -rw-r--r-- | node_modules/shell-quote/test/env_fn.js | 21 | ||||
| -rw-r--r-- | node_modules/shell-quote/test/op.js | 102 | ||||
| -rw-r--r-- | node_modules/shell-quote/test/parse.js | 44 | ||||
| -rw-r--r-- | node_modules/shell-quote/test/quote.js | 60 | ||||
| -rw-r--r-- | node_modules/shell-quote/test/set.js | 31 |
7 files changed, 326 insertions, 0 deletions
diff --git a/node_modules/shell-quote/test/comment.js b/node_modules/shell-quote/test/comment.js new file mode 100644 index 0000000..fb15d5c --- /dev/null +++ b/node_modules/shell-quote/test/comment.js @@ -0,0 +1,16 @@ +'use strict'; + +var test = require('tape'); +var parse = require('../').parse; + +test('comment', function (t) { + t.same(parse('beep#boop'), ['beep', { comment: 'boop' }]); + t.same(parse('beep #boop'), ['beep', { comment: 'boop' }]); + t.same(parse('beep # boop'), ['beep', { comment: ' boop' }]); + t.same(parse('beep # > boop'), ['beep', { comment: ' > boop' }]); + t.same(parse('beep # "> boop"'), ['beep', { comment: ' "> boop"' }]); + t.same(parse('beep "#"'), ['beep', '#']); + t.same(parse('beep #"#"#'), ['beep', { comment: '"#"#' }]); + t.same(parse('beep > boop # > foo'), ['beep', { op: '>' }, 'boop', { comment: ' > foo' }]); + t.end(); +}); diff --git a/node_modules/shell-quote/test/env.js b/node_modules/shell-quote/test/env.js new file mode 100644 index 0000000..4cc0a51 --- /dev/null +++ b/node_modules/shell-quote/test/env.js @@ -0,0 +1,52 @@ +'use strict'; + +var test = require('tape'); +var parse = require('../').parse; + +test('expand environment variables', function (t) { + t.same(parse('a $XYZ c', { XYZ: 'b' }), ['a', 'b', 'c']); + t.same(parse('a${XYZ}c', { XYZ: 'b' }), ['abc']); + t.same(parse('a${XYZ}c $XYZ', { XYZ: 'b' }), ['abc', 'b']); + t.same(parse('"-$X-$Y-"', { X: 'a', Y: 'b' }), ['-a-b-']); + t.same(parse("'-$X-$Y-'", { X: 'a', Y: 'b' }), ['-$X-$Y-']); + t.same(parse('qrs"$zzz"wxy', { zzz: 'tuv' }), ['qrstuvwxy']); + t.same(parse("qrs'$zzz'wxy", { zzz: 'tuv' }), ['qrs$zzzwxy']); + t.same(parse('qrs${zzz}wxy'), ['qrswxy']); + t.same(parse('qrs$wxy $'), ['qrs', '$']); + t.same(parse('grep "xy$"'), ['grep', 'xy$']); + t.same(parse('ab$x', { x: 'c' }), ['abc']); + t.same(parse('ab\\$x', { x: 'c' }), ['ab$x']); + t.same(parse('ab${x}def', { x: 'c' }), ['abcdef']); + t.same(parse('ab\\${x}def', { x: 'c' }), ['ab${x}def']); + t.same(parse('"ab\\${x}def"', { x: 'c' }), ['ab${x}def']); + + t.end(); +}); + +test('expand environment variables within here-strings', function (t) { + t.same(parse('a <<< $x', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']); + t.same(parse('a <<< ${x}', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']); + t.same(parse('a <<< "$x"', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']); + t.same(parse('a <<< "${x}"', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']); + + t.end(); +}); + +test('environment variables with metacharacters', function (t) { + t.same(parse('a $XYZ c', { XYZ: '"b"' }), ['a', '"b"', 'c']); + t.same(parse('a $XYZ c', { XYZ: '$X', X: 5 }), ['a', '$X', 'c']); + t.same(parse('a"$XYZ"c', { XYZ: "'xyz'" }), ["a'xyz'c"]); + + t.end(); +}); + +test('special shell parameters', function (t) { + var chars = '*@#?-$!0_'.split(''); + t.plan(chars.length); + + chars.forEach(function (c) { + var env = {}; + env[c] = 'xxx'; + t.same(parse('a $' + c + ' c', env), ['a', 'xxx', 'c']); + }); +}); diff --git a/node_modules/shell-quote/test/env_fn.js b/node_modules/shell-quote/test/env_fn.js new file mode 100644 index 0000000..968e912 --- /dev/null +++ b/node_modules/shell-quote/test/env_fn.js @@ -0,0 +1,21 @@ +'use strict'; + +var test = require('tape'); +var parse = require('../').parse; + +function getEnv() { + return 'xxx'; +} + +function getEnvObj() { + return { op: '@@' }; +} + +test('functional env expansion', function (t) { + t.plan(4); + + t.same(parse('a $XYZ c', getEnv), ['a', 'xxx', 'c']); + t.same(parse('a $XYZ c', getEnvObj), ['a', { op: '@@' }, 'c']); + t.same(parse('a${XYZ}c', getEnvObj), ['a', { op: '@@' }, 'c']); + t.same(parse('"a $XYZ c"', getEnvObj), ['a ', { op: '@@' }, ' c']); +}); diff --git a/node_modules/shell-quote/test/op.js b/node_modules/shell-quote/test/op.js new file mode 100644 index 0000000..38d3757 --- /dev/null +++ b/node_modules/shell-quote/test/op.js @@ -0,0 +1,102 @@ +'use strict'; + +var test = require('tape'); +var parse = require('../').parse; + +test('single operators', function (t) { + t.same(parse('beep | boop'), ['beep', { op: '|' }, 'boop']); + t.same(parse('beep|boop'), ['beep', { op: '|' }, 'boop']); + t.same(parse('beep \\| boop'), ['beep', '|', 'boop']); + t.same(parse('beep "|boop"'), ['beep', '|boop']); + + t.same(parse('echo zing &'), ['echo', 'zing', { op: '&' }]); + t.same(parse('echo zing&'), ['echo', 'zing', { op: '&' }]); + t.same(parse('echo zing\\&'), ['echo', 'zing&']); + t.same(parse('echo "zing\\&"'), ['echo', 'zing\\&']); + + t.same(parse('beep;boop'), ['beep', { op: ';' }, 'boop']); + t.same(parse('(beep;boop)'), [ + { op: '(' }, 'beep', { op: ';' }, 'boop', { op: ')' } + ]); + + t.same(parse('beep>boop'), ['beep', { op: '>' }, 'boop']); + t.same(parse('beep 2>boop'), ['beep', '2', { op: '>' }, 'boop']); + t.same(parse('beep<boop'), ['beep', { op: '<' }, 'boop']); + + t.end(); +}); + +test('double operators', function (t) { + t.same(parse('beep || boop'), ['beep', { op: '||' }, 'boop']); + t.same(parse('beep||boop'), ['beep', { op: '||' }, 'boop']); + t.same(parse('beep ||boop'), ['beep', { op: '||' }, 'boop']); + t.same(parse('beep|| boop'), ['beep', { op: '||' }, 'boop']); + t.same(parse('beep || boop'), ['beep', { op: '||' }, 'boop']); + + t.same(parse('beep && boop'), ['beep', { op: '&&' }, 'boop']); + t.same( + parse('beep && boop || byte'), + ['beep', { op: '&&' }, 'boop', { op: '||' }, 'byte'] + ); + t.same( + parse('beep&&boop||byte'), + ['beep', { op: '&&' }, 'boop', { op: '||' }, 'byte'] + ); + t.same( + parse('beep\\&\\&boop||byte'), + ['beep&&boop', { op: '||' }, 'byte'] + ); + t.same( + parse('beep\\&&boop||byte'), + ['beep&', { op: '&' }, 'boop', { op: '||' }, 'byte'] + ); + t.same( + parse('beep;;boop|&byte>>blip'), + ['beep', { op: ';;' }, 'boop', { op: '|&' }, 'byte', { op: '>>' }, 'blip'] + ); + + t.same(parse('beep 2>&1'), ['beep', '2', { op: '>&' }, '1']); + + t.same( + parse('beep<(boop)'), + ['beep', { op: '<(' }, 'boop', { op: ')' }] + ); + t.same( + parse('beep<<(boop)'), + ['beep', { op: '<' }, { op: '<(' }, 'boop', { op: ')' }] + ); + + t.end(); +}); + +test('duplicating input file descriptors', function (t) { + // duplicating stdout to file descriptor 3 + t.same(parse('beep 3<&1'), ['beep', '3', { op: '<&' }, '1']); + + // duplicating stdout to file descriptor 0, i.e. stdin + t.same(parse('beep <&1'), ['beep', { op: '<&' }, '1']); + + // closes stdin + t.same(parse('beep <&-'), ['beep', { op: '<&' }, '-']); + + t.end(); +}); + +test('here strings', function (t) { + t.same(parse('cat <<< "hello world"'), ['cat', { op: '<<<' }, 'hello world']); + t.same(parse('cat <<< hello'), ['cat', { op: '<<<' }, 'hello']); + t.same(parse('cat<<<hello'), ['cat', { op: '<<<' }, 'hello']); + t.same(parse('cat<<<"hello world"'), ['cat', { op: '<<<' }, 'hello world']); + + t.end(); +}); + +test('glob patterns', function (t) { + t.same( + parse('tap test/*.test.js'), + ['tap', { op: 'glob', pattern: 'test/*.test.js' }] + ); + + t.same(parse('tap "test/*.test.js"'), ['tap', 'test/*.test.js']); + t.end(); +}); diff --git a/node_modules/shell-quote/test/parse.js b/node_modules/shell-quote/test/parse.js new file mode 100644 index 0000000..e6c36b1 --- /dev/null +++ b/node_modules/shell-quote/test/parse.js @@ -0,0 +1,44 @@ +'use strict'; + +var test = require('tape'); +var parse = require('../').parse; + +test('parse shell commands', function (t) { + t.same(parse(''), [], 'parses an empty string'); + + t['throws']( + function () { parse('${}'); }, + Error, + 'empty substitution throws' + ); + t['throws']( + function () { parse('${'); }, + Error, + 'incomplete substitution throws' + ); + + t.same(parse('a \'b\' "c"'), ['a', 'b', 'c']); + t.same( + parse('beep "boop" \'foo bar baz\' "it\'s \\"so\\" groovy"'), + ['beep', 'boop', 'foo bar baz', 'it\'s "so" groovy'] + ); + t.same(parse('a b\\ c d'), ['a', 'b c', 'd']); + t.same(parse('\\$beep bo\\`op'), ['$beep', 'bo`op']); + t.same(parse('echo "foo = \\"foo\\""'), ['echo', 'foo = "foo"']); + t.same(parse(''), []); + t.same(parse(' '), []); + t.same(parse('\t'), []); + t.same(parse('a"b c d"e'), ['ab c de']); + t.same(parse('a\\ b"c d"\\ e f'), ['a bc d e', 'f']); + t.same(parse('a\\ b"c d"\\ e\'f g\' h'), ['a bc d ef g', 'h']); + t.same(parse("x \"bl'a\"'h'"), ['x', "bl'ah"]); + t.same(parse("x bl^'a^'h'", {}, { escape: '^' }), ['x', "bl'a'h"]); + t.same(parse('abcH def', {}, { escape: 'H' }), ['abc def']); + + t.deepEqual(parse('# abc def ghi'), [{ comment: ' abc def ghi' }], 'start-of-line comment content is unparsed'); + t.deepEqual(parse('xyz # abc def ghi'), ['xyz', { comment: ' abc def ghi' }], 'comment content is unparsed'); + + t.deepEqual(parse('-x "" -y'), ['-x', '', '-y'], 'empty string is preserved'); + + t.end(); +}); diff --git a/node_modules/shell-quote/test/quote.js b/node_modules/shell-quote/test/quote.js new file mode 100644 index 0000000..814707f --- /dev/null +++ b/node_modules/shell-quote/test/quote.js @@ -0,0 +1,60 @@ +'use strict'; + +var test = require('tape'); +var quote = require('../').quote; + +test('quote', function (t) { + t.equal(quote(['a', 'b', 'c d']), 'a b \'c d\''); + t.equal( + quote(['a', 'b', "it's a \"neat thing\""]), + 'a b "it\'s a \\"neat thing\\""' + ); + t.equal( + quote(['$', '`', '\'']), + '\\$ \\` "\'"' + ); + t.equal(quote([]), ''); + t.equal(quote(['a\nb']), "'a\nb'"); + t.equal(quote([' #(){}*|][!']), "' #(){}*|][!'"); + t.equal(quote(["'#(){}*|][!"]), '"\'#(){}*|][\\!"'); + t.equal(quote(['X#(){}*|][!']), 'X\\#\\(\\)\\{\\}\\*\\|\\]\\[\\!'); + t.equal(quote(['a\n#\nb']), "'a\n#\nb'"); + t.equal(quote(['><;{}']), '\\>\\<\\;\\{\\}'); + t.equal(quote(['a', 1, true, false]), 'a 1 true false'); + t.equal(quote(['a', 1, null, undefined]), 'a 1 null undefined'); + t.equal(quote(['a\\x']), "'a\\x'"); + t.equal(quote(['a"b']), '\'a"b\''); + t.equal(quote(['"a"b"']), '\'"a"b"\''); + t.equal(quote(['a\\"b']), '\'a\\"b\''); + t.equal(quote(['a\\b']), '\'a\\b\''); + t.end(); +}); + +test('quote ops', function (t) { + t.equal(quote(['a', { op: '|' }, 'b']), 'a \\| b'); + t.equal( + quote(['a', { op: '&&' }, 'b', { op: ';' }, 'c']), + 'a \\&\\& b \\; c' + ); + t.end(); +}); + +test('quote windows paths', { skip: 'breaking change, disabled until 2.x' }, function (t) { + var path = 'C:\\projects\\node-shell-quote\\index.js'; + + t.equal(quote([path, 'b', 'c d']), 'C:\\projects\\node-shell-quote\\index.js b \'c d\''); + + t.end(); +}); + +test("chars for windows paths don't break out", function (t) { + var x = '`:\\a\\b'; + t.equal(quote([x]), "'`:\\a\\b'"); + t.end(); +}); + +test('empty strings', function (t) { + t.equal(quote(['-x', '', 'y']), '-x \'\' y'); + + t.end(); +}); diff --git a/node_modules/shell-quote/test/set.js b/node_modules/shell-quote/test/set.js new file mode 100644 index 0000000..9694538 --- /dev/null +++ b/node_modules/shell-quote/test/set.js @@ -0,0 +1,31 @@ +'use strict'; + +var test = require('tape'); +var parse = require('../').parse; + +test('set env vars', function (t) { + t.same( + parse('ABC=444 x y z'), + ['ABC=444', 'x', 'y', 'z'] + ); + t.same( + parse('ABC=3\\ 4\\ 5 x y z'), + ['ABC=3 4 5', 'x', 'y', 'z'] + ); + t.same( + parse('X="7 8 9" printx'), + ['X=7 8 9', 'printx'] + ); + t.same( + parse('X="7 8 9"; printx'), + ['X=7 8 9', { op: ';' }, 'printx'] + ); + t.same( + parse('X="7 8 9"; printx', function () { + t.fail('should not have matched any keys'); + }), + ['X=7 8 9', { op: ';' }, 'printx'] + ); + + t.end(); +}); |
