shell-test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var assert = require('chai').assert,
  2. shell = require('..').shell;
  3. /**
  4. * Mocha BDD interface.
  5. */
  6. /** @name describe @function */
  7. /** @name it @function */
  8. /** @name before @function */
  9. /** @name after @function */
  10. /** @name beforeEach @function */
  11. /** @name afterEach @function */
  12. describe('shell', function() {
  13. describe('escape()', function() {
  14. var escape = shell.escape;
  15. it('Should wrap values with spaces in double quotes', function() {
  16. assert.equal(escape('asd abc'), '"asd abc"');
  17. });
  18. it('Should escape double quote "', function() {
  19. assert.equal(escape('"asd'), '\\"asd');
  20. });
  21. it("Should escape single quote '", function() {
  22. assert.equal(escape("'asd"), "\\'asd");
  23. });
  24. it('Should escape backslash \\', function() {
  25. assert.equal(escape('\\asd'), '\\\\asd');
  26. });
  27. it('Should escape dollar $', function() {
  28. assert.equal(escape('$asd'), '\\$asd');
  29. });
  30. it('Should escape backtick `', function() {
  31. assert.equal(escape('`asd'), '\\`asd');
  32. });
  33. });
  34. describe('unescape()', function() {
  35. var unescape = shell.unescape;
  36. it('Should strip double quotes at the both ends', function() {
  37. assert.equal(unescape('"asd"'), 'asd');
  38. });
  39. it('Should not strip escaped double quotes at the both ends', function() {
  40. assert.equal(unescape('\\"asd\\"'), '"asd"');
  41. });
  42. });
  43. });