quote.js 1.5 KB

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