quote.js 1.6 KB

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