| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var test = require('tape');
|
|---|
| 4 | var quote = require('../').quote;
|
|---|
| 5 |
|
|---|
| 6 | test('quote', function (t) {
|
|---|
| 7 | t.equal(quote(['a', 'b', 'c d']), 'a b \'c d\'');
|
|---|
| 8 | t.equal(
|
|---|
| 9 | quote(['a', 'b', "it's a \"neat thing\""]),
|
|---|
| 10 | 'a b "it\'s a \\"neat thing\\""'
|
|---|
| 11 | );
|
|---|
| 12 | t.equal(
|
|---|
| 13 | quote(['$', '`', '\'']),
|
|---|
| 14 | '\\$ \\` "\'"'
|
|---|
| 15 | );
|
|---|
| 16 | t.equal(quote([]), '');
|
|---|
| 17 | t.equal(quote(['a\nb']), "'a\nb'");
|
|---|
| 18 | t.equal(quote([' #(){}*|][!']), "' #(){}*|][!'");
|
|---|
| 19 | t.equal(quote(["'#(){}*|][!"]), '"\'#(){}*|][\\!"');
|
|---|
| 20 | t.equal(quote(['X#(){}*|][!']), 'X\\#\\(\\)\\{\\}\\*\\|\\]\\[\\!');
|
|---|
| 21 | t.equal(quote(['a\n#\nb']), "'a\n#\nb'");
|
|---|
| 22 | t.equal(quote(['><;{}']), '\\>\\<\\;\\{\\}');
|
|---|
| 23 | t.equal(quote(['a', 1, true, false]), 'a 1 true false');
|
|---|
| 24 | t.equal(quote(['a', 1, null, undefined]), 'a 1 null undefined');
|
|---|
| 25 | t.equal(quote(['a\\x']), "'a\\x'");
|
|---|
| 26 | t.equal(quote(['a"b']), '\'a"b\'');
|
|---|
| 27 | t.equal(quote(['"a"b"']), '\'"a"b"\'');
|
|---|
| 28 | t.equal(quote(['a\\"b']), '\'a\\"b\'');
|
|---|
| 29 | t.equal(quote(['a\\b']), '\'a\\b\'');
|
|---|
| 30 | t.end();
|
|---|
| 31 | });
|
|---|
| 32 |
|
|---|
| 33 | test('quote ops', function (t) {
|
|---|
| 34 | t.equal(quote(['a', { op: '|' }, 'b']), 'a \\| b');
|
|---|
| 35 | t.equal(
|
|---|
| 36 | quote(['a', { op: '&&' }, 'b', { op: ';' }, 'c']),
|
|---|
| 37 | 'a \\&\\& b \\; c'
|
|---|
| 38 | );
|
|---|
| 39 | t.end();
|
|---|
| 40 | });
|
|---|
| 41 |
|
|---|
| 42 | test('quote windows paths', { skip: 'breaking change, disabled until 2.x' }, function (t) {
|
|---|
| 43 | var path = 'C:\\projects\\node-shell-quote\\index.js';
|
|---|
| 44 |
|
|---|
| 45 | t.equal(quote([path, 'b', 'c d']), 'C:\\projects\\node-shell-quote\\index.js b \'c d\'');
|
|---|
| 46 |
|
|---|
| 47 | t.end();
|
|---|
| 48 | });
|
|---|
| 49 |
|
|---|
| 50 | test("chars for windows paths don't break out", function (t) {
|
|---|
| 51 | var x = '`:\\a\\b';
|
|---|
| 52 | t.equal(quote([x]), "'`:\\a\\b'");
|
|---|
| 53 | t.end();
|
|---|
| 54 | });
|
|---|
| 55 |
|
|---|
| 56 | test('empty strings', function (t) {
|
|---|
| 57 | t.equal(quote(['-x', '', 'y']), '-x \'\' y');
|
|---|
| 58 |
|
|---|
| 59 | t.end();
|
|---|
| 60 | });
|
|---|