-
-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathstrip-quotes.spec.ts
More file actions
37 lines (28 loc) · 1.21 KB
/
strip-quotes.spec.ts
File metadata and controls
37 lines (28 loc) · 1.21 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
import { expect, it } from 'vitest';
import { CommandInfo } from '../command.js';
import { StripQuotes } from './strip-quotes.js';
const parser = new StripQuotes();
const createCommandInfo = (command: string): CommandInfo => ({
command,
name: '',
});
it('returns command as is if no single/double quote at the beginning', () => {
const commandInfo = createCommandInfo('echo foo');
expect(parser.parse(commandInfo)).toEqual(commandInfo);
});
it('strips single quotes', () => {
const commandInfo = createCommandInfo("'echo foo'");
expect(parser.parse(commandInfo)).toEqual({ ...commandInfo, command: 'echo foo' });
});
it('strips double quotes', () => {
const commandInfo = createCommandInfo('"echo foo"');
expect(parser.parse(commandInfo)).toEqual({ ...commandInfo, command: 'echo foo' });
});
it('does not remove quotes if they are unbalanced', () => {
let commandInfo = createCommandInfo('"echo foo');
expect(parser.parse(commandInfo)).toEqual(commandInfo);
commandInfo = createCommandInfo("echo foo'");
expect(parser.parse(commandInfo)).toEqual(commandInfo);
commandInfo = createCommandInfo('"echo foo\'');
expect(parser.parse(commandInfo)).toEqual(commandInfo);
});