summaryrefslogtreecommitdiffstats
path: root/node_modules/shell-quote/test
diff options
context:
space:
mode:
authorGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
committerGravatar Piotr Russ <mail@pruss.it> 2020-11-16 00:10:28 +0100
commite06ec920f7a5d784e674c4c4b4e6d1da3dc7391d (patch)
tree55713f725f77b44ebfec86e4eec3ce33e71458ca /node_modules/shell-quote/test
downloadwebsite_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.gz
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.tar.bz2
website_creator-e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d.zip
api, login, auth
Diffstat (limited to 'node_modules/shell-quote/test')
-rw-r--r--node_modules/shell-quote/test/comment.js14
-rw-r--r--node_modules/shell-quote/test/env.js41
-rw-r--r--node_modules/shell-quote/test/env_fn.js19
-rw-r--r--node_modules/shell-quote/test/op.js78
-rw-r--r--node_modules/shell-quote/test/parse.js23
-rw-r--r--node_modules/shell-quote/test/quote.js42
-rw-r--r--node_modules/shell-quote/test/set.js29
7 files changed, 246 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..bc6fbf2
--- /dev/null
+++ b/node_modules/shell-quote/test/comment.js
@@ -0,0 +1,14 @@
+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..b3faeb0
--- /dev/null
+++ b/node_modules/shell-quote/test/env.js
@@ -0,0 +1,41 @@
+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('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..b9f3c20
--- /dev/null
+++ b/node_modules/shell-quote/test/env_fn.js
@@ -0,0 +1,19 @@
+var test = require('tape');
+var parse = require('../').parse;
+
+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' ]);
+
+ function getEnv (key) {
+ return 'xxx';
+ }
+
+ function getEnvObj (key) {
+ return { op: '@@' };
+ }
+});
diff --git a/node_modules/shell-quote/test/op.js b/node_modules/shell-quote/test/op.js
new file mode 100644
index 0000000..7aa9b49
--- /dev/null
+++ b/node_modules/shell-quote/test/op.js
@@ -0,0 +1,78 @@
+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('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..2df4419
--- /dev/null
+++ b/node_modules/shell-quote/test/parse.js
@@ -0,0 +1,23 @@
+var test = require('tape');
+var parse = require('../').parse;
+
+test('parse shell commands', function (t) {
+ 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.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..7c31f01
--- /dev/null
+++ b/node_modules/shell-quote/test/quote.js
@@ -0,0 +1,42 @@
+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.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()
+})
diff --git a/node_modules/shell-quote/test/set.js b/node_modules/shell-quote/test/set.js
new file mode 100644
index 0000000..ac45cf1
--- /dev/null
+++ b/node_modules/shell-quote/test/set.js
@@ -0,0 +1,29 @@
+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 (key) {
+ t.fail('should not have matched any keys');
+ }),
+ [ 'X=7 8 9', { op: ';' }, 'printx' ]
+ );
+
+ t.end();
+});