-
-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathnormalize-cli-command.spec.ts
More file actions
52 lines (40 loc) · 1.73 KB
/
normalize-cli-command.spec.ts
File metadata and controls
52 lines (40 loc) · 1.73 KB
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
47
48
49
50
51
52
import { expect, it } from 'vitest';
import { normalizeCliCommand } from './normalize-cli-command.js';
it('strips outer CLI wrapper double quotes', () => {
expect(normalizeCliCommand('"echo foo"')).toBe('echo foo');
});
it('strips outer CLI wrapper single quotes', () => {
expect(normalizeCliCommand("'echo foo'")).toBe('echo foo');
});
it('strips quotes around a single wrapped token', () => {
expect(normalizeCliCommand('"echo"')).toBe('echo');
expect(normalizeCliCommand("'echo'")).toBe('echo');
});
it('preserves quotes in well-formed shell commands', () => {
expect(normalizeCliCommand('"/usr/local/bin/mytool" --flag "some value"')).toBe(
'"/usr/local/bin/mytool" --flag "some value"',
);
});
it('preserves well-formed shell commands with multiple quote sets', () => {
expect(
normalizeCliCommand('"/usr/local/bin/mytool" --flag "some value" --other "last arg"'),
).toBe('"/usr/local/bin/mytool" --flag "some value" --other "last arg"');
});
it('preserves single quotes in well-formed shell commands', () => {
expect(normalizeCliCommand("'printf' '%s %s' foo bar")).toBe("'printf' '%s %s' foo bar");
});
it('returns unquoted input unchanged', () => {
expect(normalizeCliCommand('echo foo')).toBe('echo foo');
});
it('returns an empty string unchanged', () => {
expect(normalizeCliCommand('')).toBe('');
});
it('leaves ambiguous input unchanged', () => {
expect(normalizeCliCommand('"echo foo')).toBe('"echo foo');
});
it('leaves input with an unclosed single quote unchanged', () => {
expect(normalizeCliCommand("echo foo'")).toBe("echo foo'");
});
it('leaves input with mismatched quote types unchanged', () => {
expect(normalizeCliCommand('"echo foo\'')).toBe('"echo foo\'');
});