quote.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.end();
  25. });
  26. test('quote ops', function (t) {
  27. t.equal(quote(['a', { op: '|' }, 'b']), 'a \\| b');
  28. t.equal(
  29. quote(['a', { op: '&&' }, 'b', { op: ';' }, 'c']),
  30. 'a \\&\\& b \\; c'
  31. );
  32. t.end();
  33. });
  34. test('quote windows paths', { skip: 'breaking change, disabled until 2.x' }, function (t) {
  35. var path = 'C:\\projects\\node-shell-quote\\index.js';
  36. t.equal(quote([path, 'b', 'c d']), 'C:\\projects\\node-shell-quote\\index.js b \'c d\'');
  37. t.end();
  38. });
  39. test("chars for windows paths don't break out", function (t) {
  40. var x = '`:\\a\\b';
  41. t.equal(quote([x]), '\\`\\:\\\\a\\\\b');
  42. t.end();
  43. });