source: frontend/node_modules/shell-quote/test/parse.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict';
2
3var test = require('tape');
4var parse = require('../').parse;
5
6test('parse shell commands', function (t) {
7 t.same(parse(''), [], 'parses an empty string');
8
9 t['throws'](
10 function () { parse('${}'); },
11 Error,
12 'empty substitution throws'
13 );
14 t['throws'](
15 function () { parse('${'); },
16 Error,
17 'incomplete substitution throws'
18 );
19
20 t.same(parse('a \'b\' "c"'), ['a', 'b', 'c']);
21 t.same(
22 parse('beep "boop" \'foo bar baz\' "it\'s \\"so\\" groovy"'),
23 ['beep', 'boop', 'foo bar baz', 'it\'s "so" groovy']
24 );
25 t.same(parse('a b\\ c d'), ['a', 'b c', 'd']);
26 t.same(parse('\\$beep bo\\`op'), ['$beep', 'bo`op']);
27 t.same(parse('echo "foo = \\"foo\\""'), ['echo', 'foo = "foo"']);
28 t.same(parse(''), []);
29 t.same(parse(' '), []);
30 t.same(parse('\t'), []);
31 t.same(parse('a"b c d"e'), ['ab c de']);
32 t.same(parse('a\\ b"c d"\\ e f'), ['a bc d e', 'f']);
33 t.same(parse('a\\ b"c d"\\ e\'f g\' h'), ['a bc d ef g', 'h']);
34 t.same(parse("x \"bl'a\"'h'"), ['x', "bl'ah"]);
35 t.same(parse("x bl^'a^'h'", {}, { escape: '^' }), ['x', "bl'a'h"]);
36 t.same(parse('abcH def', {}, { escape: 'H' }), ['abc def']);
37
38 t.deepEqual(parse('# abc def ghi'), [{ comment: ' abc def ghi' }], 'start-of-line comment content is unparsed');
39 t.deepEqual(parse('xyz # abc def ghi'), ['xyz', { comment: ' abc def ghi' }], 'comment content is unparsed');
40
41 t.deepEqual(parse('-x "" -y'), ['-x', '', '-y'], 'empty string is preserved');
42
43 t.end();
44});
Note: See TracBrowser for help on using the repository browser.