File: fix-cmd-win-slashes.js

package info (click to toggle)
node-yarnpkg 1.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 92,980 kB
  • sloc: sh: 323; makefile: 19
file content (46 lines) | stat: -rw-r--r-- 1,846 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* @flow */
import {fixCmdWinSlashes} from '../../src/util/fix-cmd-win-slashes.js';

const cmdCases = [
  ['fixes just slashed command', 'some/command', 'some\\command'],
  ['fixes slashed command in double quotes', '"./some/command/more"', '".\\some\\command\\more"'],
  ['slashed command in single quotes', "'./some/command/more'", "'.\\some\\command\\more'"],
  [
    'fixes slashed command with slashed param',
    './some/command/more slashed/param',
    '.\\some\\command\\more slashed/param',
  ],
  [
    'fixes slashed command in single quotes with two slashed params',
    "'./some/command/more' justparam slashed/param --param slashed/param2",
    "'.\\some\\command\\more' justparam slashed/param --param slashed/param2",
  ],
  [
    'fixes two slashed commands (&&) with two slashed params',
    "'./some/command/more' justparam slashed/param &&  ../another/command with/slashed/param",
    "'.\\some\\command\\more' justparam slashed/param &&  ..\\another\\command with/slashed/param",
  ],
  [
    'fixes three slashed commands (&&) with two slashed params',
    "'./some/command/more' justparam slashed/param &&" +
      '  "../another/command" with/slashed/param | ./another/more/command with/slashed/param',
    "'.\\some\\command\\more' justparam slashed/param &&" +
      '  "..\\another\\command" with/slashed/param | .\\another\\more\\command with/slashed/param',
  ],
  [
    'does not change nested command (inside the quotes)',
    'command -c bash "slashed/nested/cmd && nested/bin/some"',
    'command -c bash "slashed/nested/cmd && nested/bin/some"',
  ],
];

describe('fixCmdWinSlashes', () => {
  cmdCases.forEach(cmdCase => {
    const name = cmdCase[0];
    const original = cmdCase[1];
    const fixed = cmdCase[2];
    it(name, () => {
      expect(fixCmdWinSlashes(original)).toEqual(fixed);
    });
  });
});