-
Notifications
You must be signed in to change notification settings - Fork 269
/
script-options-view-spec.js
80 lines (78 loc) · 2.37 KB
/
script-options-view-spec.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"use babel"
import ScriptOptionsView from "../lib/script-options-view"
describe("ScriptOptionsView", () => {
describe("splitArgs", () => {
;[
{
text: "",
expectedArgs: [],
description: "returns an empty array for empty string",
},
{
text: " \t\n",
expectedArgs: [],
description: "returns an empty array for just whitespace",
},
{
text: "arg1 arg2",
expectedArgs: ["arg1", "arg2"],
description: "splits arguments on whitespace",
},
{
text: "arg1=val1 arg2",
expectedArgs: ["arg1=val1", "arg2"],
description: "keeps argument values",
},
{
text: '"foo bar" arg2',
expectedArgs: ["foo bar", "arg2"],
description: "does not split quoted arguments on whitespace",
},
{
text: "'foo bar' arg2",
expectedArgs: ["foo bar", "arg2"],
description: "recognizes single quotes",
},
{
text: '"foo bar" "another string"',
expectedArgs: ["foo bar", "another string"],
description: "handles multiple quoted arguments",
},
{
text: "'foo bar' 'another string'",
expectedArgs: ["foo bar", "another string"],
description: "handles multiple single quoted arguments",
},
{
text: "\"foo bar\" 'another string'",
expectedArgs: ["foo bar", "another string"],
description: "handles multiple quoted arguments, with mixed single and double quotes",
},
{
text: 'arg1="foo bar"',
expectedArgs: ["arg1=foo bar"],
description: "strips quotes from argument values",
},
{
text: "arg1='foo bar'",
expectedArgs: ["arg1=foo bar"],
description: "strips single quotes from argument values",
},
{
text: "-e '(load \"{FILE_ACTIVE}\")'",
expectedArgs: ["-e", '(load "{FILE_ACTIVE}")'],
description: "keeps nested quotes intact",
},
{
text: 'we"ird way to inc"l"ude spaces in arg"s',
expectedArgs: ["weird way to include spaces in args"],
description: "supports multiple top level quotes",
},
].forEach(({ text, expectedArgs, description }) => {
it(description, () => {
const args = ScriptOptionsView.splitArgs(text)
expect(args).toEqual(expectedArgs)
})
})
})
})