@futpib/parser 1.0.3 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +24 -0
- package/.github/workflows/main.yml +1 -0
- package/build/androidPackageParser.js +30 -32
- package/build/arbitraryDalvikBytecode.d.ts +3 -3
- package/build/arbitraryDalvikBytecode.js +33 -27
- package/build/arbitraryDalvikExecutable.js +55 -17
- package/build/arbitraryJava.d.ts +31 -0
- package/build/arbitraryJava.js +532 -0
- package/build/arbitraryJavaScript.d.ts +3 -0
- package/build/arbitraryJavaScript.js +263 -0
- package/build/arbitraryJavascript.d.ts +3 -0
- package/build/arbitraryJavascript.js +263 -0
- package/build/arbitraryZig.d.ts +3 -0
- package/build/arbitraryZig.js +240 -0
- package/build/arbitraryZipStream.d.ts +1 -1
- package/build/arrayParser.js +72 -13
- package/build/backsmali.d.ts +4 -3
- package/build/backsmali.js +26 -6
- package/build/bash.d.ts +89 -0
- package/build/bash.js +1 -0
- package/build/bashParser.d.ts +6 -0
- package/build/bashParser.js +335 -0
- package/build/bashParser.test.d.ts +1 -0
- package/build/bashParser.test.js +343 -0
- package/build/bashParserEdgeCases.test.d.ts +1 -0
- package/build/bashParserEdgeCases.test.js +117 -0
- package/build/dalvikBytecodeParser/addressConversion.d.ts +110 -0
- package/build/dalvikBytecodeParser/addressConversion.js +334 -0
- package/build/dalvikBytecodeParser/formatParsers.d.ts +7 -6
- package/build/dalvikBytecodeParser/formatParsers.js +13 -14
- package/build/dalvikBytecodeParser.d.ts +60 -31
- package/build/dalvikBytecodeParser.js +92 -35
- package/build/dalvikBytecodeParser.test-d.d.ts +1 -0
- package/build/dalvikBytecodeParser.test-d.js +268 -0
- package/build/dalvikBytecodeUnparser/formatUnparsers.d.ts +9 -8
- package/build/dalvikBytecodeUnparser/formatUnparsers.js +13 -12
- package/build/dalvikBytecodeUnparser.d.ts +2 -2
- package/build/dalvikBytecodeUnparser.js +23 -23
- package/build/dalvikBytecodeUnparser.test.js +7 -7
- package/build/dalvikExecutable.d.ts +3 -3
- package/build/dalvikExecutable.test-d.d.ts +1 -0
- package/build/dalvikExecutable.test-d.js +59 -0
- package/build/dalvikExecutableParser/typedNumbers.d.ts +18 -0
- package/build/dalvikExecutableParser/typedNumbers.js +3 -0
- package/build/dalvikExecutableParser.d.ts +2 -1
- package/build/dalvikExecutableParser.js +96 -77
- package/build/dalvikExecutableParser.test.js +24 -3
- package/build/dalvikExecutableParserAgainstSmaliParser.test.js +3 -0
- package/build/dalvikExecutableUnparser/poolScanners.d.ts +2 -2
- package/build/dalvikExecutableUnparser/sectionUnparsers.d.ts +3 -3
- package/build/dalvikExecutableUnparser/sectionUnparsers.js +26 -11
- package/build/dalvikExecutableUnparser.d.ts +2 -2
- package/build/dalvikExecutableUnparser.test.js +2 -1
- package/build/disjunctionParser.d.ts +5 -3
- package/build/disjunctionParser.js +79 -17
- package/build/disjunctionParser.test-d.d.ts +1 -0
- package/build/disjunctionParser.test-d.js +72 -0
- package/build/elementSwitchParser.d.ts +4 -0
- package/build/{exactElementSwitchParser.js → elementSwitchParser.js} +3 -4
- package/build/elementSwitchParser.test-d.d.ts +1 -0
- package/build/elementSwitchParser.test-d.js +44 -0
- package/build/exactSequenceParser.d.ts +4 -2
- package/build/exactSequenceParser.test-d.d.ts +1 -0
- package/build/exactSequenceParser.test-d.js +36 -0
- package/build/fetchCid.js +2 -66
- package/build/index.d.ts +25 -2
- package/build/index.js +23 -1
- package/build/index.test.js +16 -1
- package/build/inputReader.d.ts +10 -0
- package/build/inputReader.js +36 -0
- package/build/java.d.ts +502 -0
- package/build/java.js +2 -0
- package/build/javaKeyStoreParser.js +14 -17
- package/build/javaParser.d.ts +51 -0
- package/build/javaParser.js +1538 -0
- package/build/javaParser.test.d.ts +1 -0
- package/build/javaParser.test.js +1287 -0
- package/build/javaScript.d.ts +35 -0
- package/build/javaScript.js +1 -0
- package/build/javaScriptParser.d.ts +9 -0
- package/build/javaScriptParser.js +34 -0
- package/build/javaScriptUnparser.d.ts +3 -0
- package/build/javaScriptUnparser.js +4 -0
- package/build/javaScriptUnparser.test.d.ts +1 -0
- package/build/javaScriptUnparser.test.js +24 -0
- package/build/javaUnparser.d.ts +2 -0
- package/build/javaUnparser.js +519 -0
- package/build/javaUnparser.test.d.ts +1 -0
- package/build/javaUnparser.test.js +24 -0
- package/build/javascript.d.ts +35 -0
- package/build/javascript.js +1 -0
- package/build/javascriptParser.d.ts +9 -0
- package/build/javascriptParser.js +34 -0
- package/build/javascriptUnparser.d.ts +3 -0
- package/build/javascriptUnparser.js +4 -0
- package/build/javascriptUnparser.test.d.ts +1 -0
- package/build/javascriptUnparser.test.js +24 -0
- package/build/jsonParser.js +2 -12
- package/build/lazyMessageError.d.ts +3 -0
- package/build/lookaheadParser.js +60 -3
- package/build/negativeLookaheadParser.js +70 -11
- package/build/nonEmptyArrayParser.js +72 -13
- package/build/objectParser.d.ts +12 -0
- package/build/objectParser.js +31 -0
- package/build/objectParser.test-d.d.ts +1 -0
- package/build/objectParser.test-d.js +112 -0
- package/build/objectParser.test.d.ts +1 -0
- package/build/objectParser.test.js +55 -0
- package/build/optionalParser.js +69 -10
- package/build/parser.d.ts +4 -0
- package/build/parser.js +3 -1
- package/build/parser.test.js +114 -1
- package/build/parserConsumedSequenceParser.js +66 -7
- package/build/parserContext.d.ts +6 -0
- package/build/parserContext.js +20 -11
- package/build/parserError.d.ts +119 -27
- package/build/parserError.js +16 -8
- package/build/regexpParser.d.ts +2 -0
- package/build/regexpParser.js +101 -0
- package/build/regexpParser.test.d.ts +1 -0
- package/build/regexpParser.test.js +114 -0
- package/build/regularExpression.d.ts +63 -0
- package/build/regularExpression.js +1 -0
- package/build/regularExpressionParser.d.ts +3 -0
- package/build/regularExpressionParser.js +600 -0
- package/build/regularExpressionParser.test.d.ts +1 -0
- package/build/regularExpressionParser.test.js +89 -0
- package/build/separatedArrayParser.js +73 -14
- package/build/separatedNonEmptyArrayParser.js +73 -14
- package/build/sliceBoundedParser.js +62 -5
- package/build/smaliParser.d.ts +7 -7
- package/build/smaliParser.js +185 -268
- package/build/smaliParser.test.js +58 -0
- package/build/stringEscapes.d.ts +5 -0
- package/build/stringEscapes.js +244 -0
- package/build/symbolicExpression.d.ts +29 -0
- package/build/symbolicExpression.js +1 -0
- package/build/symbolicExpressionParser.d.ts +4 -0
- package/build/symbolicExpressionParser.js +123 -0
- package/build/symbolicExpressionParser.test.d.ts +1 -0
- package/build/symbolicExpressionParser.test.js +289 -0
- package/build/terminatedArrayParser.js +113 -38
- package/build/terminatedArrayParser.test.js +4 -2
- package/build/tupleParser.d.ts +7 -15
- package/build/tupleParser.js +1 -0
- package/build/unionParser.d.ts +5 -3
- package/build/unionParser.js +7 -2
- package/build/unionParser.test-d.d.ts +1 -0
- package/build/unionParser.test-d.js +72 -0
- package/build/unionParser.test.js +10 -11
- package/build/zig.d.ts +280 -0
- package/build/zig.js +2 -0
- package/build/zigParser.d.ts +3 -0
- package/build/zigParser.js +1119 -0
- package/build/zigParser.test.d.ts +1 -0
- package/build/zigParser.test.js +1590 -0
- package/build/zigUnparser.d.ts +2 -0
- package/build/zigUnparser.js +460 -0
- package/build/zigUnparser.test.d.ts +1 -0
- package/build/zigUnparser.test.js +24 -0
- package/build/zipParser.js +19 -32
- package/build/zipUnparser.js +19 -7
- package/build/zipUnparser.test.js +1 -1
- package/node_modules-@types/s-expression/index.d.ts +5 -0
- package/package.json +25 -6
- package/src/androidPackageParser.ts +33 -60
- package/src/arbitraryDalvikBytecode.ts +39 -31
- package/src/arbitraryDalvikExecutable.ts +65 -20
- package/src/arbitraryJava.ts +804 -0
- package/src/arbitraryJavaScript.ts +410 -0
- package/src/arbitraryZig.ts +380 -0
- package/src/arrayParser.ts +1 -3
- package/src/backsmali.ts +35 -4
- package/src/bash.ts +127 -0
- package/src/bashParser.test.ts +590 -0
- package/src/bashParser.ts +498 -0
- package/src/dalvikBytecodeParser/addressConversion.ts +496 -0
- package/src/dalvikBytecodeParser/formatParsers.ts +19 -29
- package/src/dalvikBytecodeParser.test-d.ts +310 -0
- package/src/dalvikBytecodeParser.ts +194 -69
- package/src/dalvikBytecodeUnparser/formatUnparsers.ts +27 -26
- package/src/dalvikBytecodeUnparser.test.ts +7 -7
- package/src/dalvikBytecodeUnparser.ts +31 -30
- package/src/dalvikExecutable.test-d.ts +132 -0
- package/src/dalvikExecutable.ts +3 -3
- package/src/dalvikExecutableParser/typedNumbers.ts +11 -0
- package/src/dalvikExecutableParser.test.ts +37 -3
- package/src/dalvikExecutableParser.test.ts.md +163 -2
- package/src/dalvikExecutableParser.test.ts.snap +0 -0
- package/src/dalvikExecutableParser.ts +121 -139
- package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +4 -0
- package/src/dalvikExecutableUnparser/poolScanners.ts +6 -6
- package/src/dalvikExecutableUnparser/sectionUnparsers.ts +38 -14
- package/src/dalvikExecutableUnparser.test.ts +3 -2
- package/src/dalvikExecutableUnparser.ts +4 -4
- package/src/disjunctionParser.test-d.ts +105 -0
- package/src/disjunctionParser.ts +18 -15
- package/src/elementSwitchParser.test-d.ts +74 -0
- package/src/elementSwitchParser.ts +51 -0
- package/src/exactSequenceParser.test-d.ts +43 -0
- package/src/exactSequenceParser.ts +13 -8
- package/src/fetchCid.ts +2 -76
- package/src/index.test.ts +22 -1
- package/src/index.ts +119 -2
- package/src/inputReader.ts +53 -0
- package/src/java.ts +708 -0
- package/src/javaKeyStoreParser.ts +18 -32
- package/src/javaParser.test.ts +1592 -0
- package/src/javaParser.ts +2640 -0
- package/src/javaScript.ts +36 -0
- package/src/javaScriptParser.ts +57 -0
- package/src/javaScriptUnparser.test.ts +37 -0
- package/src/javaScriptUnparser.ts +7 -0
- package/src/javaUnparser.test.ts +37 -0
- package/src/javaUnparser.ts +640 -0
- package/src/jsonParser.ts +6 -27
- package/src/lookaheadParser.ts +2 -6
- package/src/negativeLookaheadParser.ts +1 -3
- package/src/nonEmptyArrayParser.ts +1 -3
- package/src/objectParser.test-d.ts +152 -0
- package/src/objectParser.test.ts +71 -0
- package/src/objectParser.ts +69 -0
- package/src/optionalParser.ts +1 -3
- package/src/parser.test.ts +151 -4
- package/src/parser.ts +11 -1
- package/src/parserConsumedSequenceParser.ts +2 -4
- package/src/parserContext.ts +26 -11
- package/src/parserError.ts +17 -3
- package/src/regexpParser.test.ts +264 -0
- package/src/regexpParser.ts +126 -0
- package/src/regularExpression.ts +24 -0
- package/src/regularExpressionParser.test.ts +102 -0
- package/src/regularExpressionParser.ts +920 -0
- package/src/separatedArrayParser.ts +1 -3
- package/src/separatedNonEmptyArrayParser.ts +1 -3
- package/src/sliceBoundedParser.test.ts +2 -2
- package/src/sliceBoundedParser.ts +15 -19
- package/src/smaliParser.test.ts +64 -0
- package/src/smaliParser.test.ts.md +12 -12
- package/src/smaliParser.test.ts.snap +0 -0
- package/src/smaliParser.ts +246 -534
- package/src/stringEscapes.ts +253 -0
- package/src/symbolicExpression.ts +17 -0
- package/src/symbolicExpressionParser.test.ts +466 -0
- package/src/symbolicExpressionParser.ts +190 -0
- package/src/terminatedArrayParser.test.ts +9 -6
- package/src/terminatedArrayParser.ts +25 -29
- package/src/tupleParser.ts +21 -18
- package/src/unionParser.test-d.ts +105 -0
- package/src/unionParser.test.ts +18 -17
- package/src/unionParser.ts +28 -16
- package/src/zig.ts +411 -0
- package/src/zigParser.test.ts +1693 -0
- package/src/zigParser.ts +1745 -0
- package/src/zigUnparser.test.ts +37 -0
- package/src/zigUnparser.ts +615 -0
- package/src/zipParser.ts +20 -56
- package/src/zipUnparser.test.ts +1 -1
- package/src/zipUnparser.ts +22 -7
- package/tsconfig.json +2 -2
- package/build/exactElementSwitchParser.d.ts +0 -3
- package/src/exactElementSwitchParser.ts +0 -41
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { runParser, runParserWithRemainingInput } from './parser.js';
|
|
3
|
+
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
4
|
+
import { bashScriptParser, bashWordParser, bashSimpleCommandParser } from './bashParser.js';
|
|
5
|
+
|
|
6
|
+
test('simple command parser - single word', async t => {
|
|
7
|
+
const result = await runParser(
|
|
8
|
+
bashSimpleCommandParser,
|
|
9
|
+
'cmd',
|
|
10
|
+
stringParserInputCompanion,
|
|
11
|
+
{ errorStack: true },
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
t.is(result.type, 'simple');
|
|
15
|
+
t.deepEqual(result.name, { parts: [{ type: 'literal', value: 'cmd' }] });
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('simple command parser - two words', async t => {
|
|
19
|
+
const result = await runParser(
|
|
20
|
+
bashSimpleCommandParser,
|
|
21
|
+
'echo hello',
|
|
22
|
+
stringParserInputCompanion,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
t.is(result.type, 'simple');
|
|
26
|
+
t.deepEqual(result.name, { parts: [{ type: 'literal', value: 'echo' }] });
|
|
27
|
+
t.is(result.args.length, 1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('word parser - simple literal', async t => {
|
|
31
|
+
const result = await runParser(
|
|
32
|
+
bashWordParser,
|
|
33
|
+
'hello',
|
|
34
|
+
stringParserInputCompanion,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
t.deepEqual(result, {
|
|
38
|
+
parts: [{ type: 'literal', value: 'hello' }],
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('word parser - variable', async t => {
|
|
43
|
+
const result = await runParser(
|
|
44
|
+
bashWordParser,
|
|
45
|
+
'$HOME',
|
|
46
|
+
stringParserInputCompanion,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
t.deepEqual(result, {
|
|
50
|
+
parts: [{ type: 'variable', name: 'HOME' }],
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('simple command', async t => {
|
|
55
|
+
const result = await runParser(
|
|
56
|
+
bashScriptParser,
|
|
57
|
+
'echo hello',
|
|
58
|
+
stringParserInputCompanion,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
t.deepEqual(result, {
|
|
62
|
+
type: 'list',
|
|
63
|
+
entries: [{
|
|
64
|
+
pipeline: {
|
|
65
|
+
type: 'pipeline',
|
|
66
|
+
negated: false,
|
|
67
|
+
commands: [{
|
|
68
|
+
type: 'simple',
|
|
69
|
+
name: { parts: [{ type: 'literal', value: 'echo' }] },
|
|
70
|
+
args: [{ parts: [{ type: 'literal', value: 'hello' }] }],
|
|
71
|
+
redirects: [],
|
|
72
|
+
assignments: [],
|
|
73
|
+
}],
|
|
74
|
+
},
|
|
75
|
+
separator: undefined,
|
|
76
|
+
}],
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('simple command with multiple args', async t => {
|
|
81
|
+
const result = await runParser(
|
|
82
|
+
bashScriptParser,
|
|
83
|
+
'echo hello world',
|
|
84
|
+
stringParserInputCompanion,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
t.is(result.entries[0].pipeline.commands[0].type, 'simple');
|
|
88
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
89
|
+
if (cmd.type === 'simple') {
|
|
90
|
+
t.is(cmd.args.length, 2);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('pipeline', async t => {
|
|
95
|
+
const result = await runParser(
|
|
96
|
+
bashScriptParser,
|
|
97
|
+
'cat file | grep pattern',
|
|
98
|
+
stringParserInputCompanion,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
t.is(result.entries[0].pipeline.commands.length, 2);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('redirect output', async t => {
|
|
105
|
+
const result = await runParser(
|
|
106
|
+
bashScriptParser,
|
|
107
|
+
'echo foo > file',
|
|
108
|
+
stringParserInputCompanion,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
112
|
+
if (cmd.type === 'simple') {
|
|
113
|
+
t.is(cmd.redirects.length, 1);
|
|
114
|
+
t.is(cmd.redirects[0].operator, '>');
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('redirect with fd', async t => {
|
|
119
|
+
const result = await runParser(
|
|
120
|
+
bashScriptParser,
|
|
121
|
+
'cmd 2>&1',
|
|
122
|
+
stringParserInputCompanion,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
126
|
+
if (cmd.type === 'simple') {
|
|
127
|
+
t.is(cmd.redirects.length, 1);
|
|
128
|
+
t.is(cmd.redirects[0].fd, 2);
|
|
129
|
+
t.is(cmd.redirects[0].operator, '>&');
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('single quoted string', async t => {
|
|
134
|
+
const result = await runParser(
|
|
135
|
+
bashScriptParser,
|
|
136
|
+
"echo 'hello world'",
|
|
137
|
+
stringParserInputCompanion,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
141
|
+
if (cmd.type === 'simple') {
|
|
142
|
+
t.deepEqual(cmd.args[0], {
|
|
143
|
+
parts: [{ type: 'singleQuoted', value: 'hello world' }],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('double quoted string with variable', async t => {
|
|
149
|
+
const result = await runParser(
|
|
150
|
+
bashScriptParser,
|
|
151
|
+
'echo "hello $name"',
|
|
152
|
+
stringParserInputCompanion,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
156
|
+
if (cmd.type === 'simple') {
|
|
157
|
+
t.deepEqual(cmd.args[0], {
|
|
158
|
+
parts: [{
|
|
159
|
+
type: 'doubleQuoted',
|
|
160
|
+
parts: [
|
|
161
|
+
{ type: 'literal', value: 'hello ' },
|
|
162
|
+
{ type: 'variable', name: 'name' },
|
|
163
|
+
],
|
|
164
|
+
}],
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('double quoted string with trailing dollar', async t => {
|
|
170
|
+
const result = await runParser(
|
|
171
|
+
bashScriptParser,
|
|
172
|
+
'echo "hello$"',
|
|
173
|
+
stringParserInputCompanion,
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
177
|
+
if (cmd.type === 'simple') {
|
|
178
|
+
t.deepEqual(cmd.args[0], {
|
|
179
|
+
parts: [{
|
|
180
|
+
type: 'doubleQuoted',
|
|
181
|
+
parts: [
|
|
182
|
+
{ type: 'literal', value: 'hello' },
|
|
183
|
+
{ type: 'literal', value: '$' },
|
|
184
|
+
],
|
|
185
|
+
}],
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('double quoted string with only dollar', async t => {
|
|
191
|
+
const result = await runParser(
|
|
192
|
+
bashScriptParser,
|
|
193
|
+
'echo "$"',
|
|
194
|
+
stringParserInputCompanion,
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
198
|
+
if (cmd.type === 'simple') {
|
|
199
|
+
t.deepEqual(cmd.args[0], {
|
|
200
|
+
parts: [{
|
|
201
|
+
type: 'doubleQuoted',
|
|
202
|
+
parts: [
|
|
203
|
+
{ type: 'literal', value: '$' },
|
|
204
|
+
],
|
|
205
|
+
}],
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test('grep with dollar anchor in double quotes', async t => {
|
|
211
|
+
const result = await runParser(
|
|
212
|
+
bashScriptParser,
|
|
213
|
+
'grep "\\.ts$"',
|
|
214
|
+
stringParserInputCompanion,
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
218
|
+
if (cmd.type === 'simple') {
|
|
219
|
+
t.deepEqual(cmd.args[0], {
|
|
220
|
+
parts: [{
|
|
221
|
+
type: 'doubleQuoted',
|
|
222
|
+
parts: [
|
|
223
|
+
{ type: 'literal', value: '\\' },
|
|
224
|
+
{ type: 'literal', value: '.ts' },
|
|
225
|
+
{ type: 'literal', value: '$' },
|
|
226
|
+
],
|
|
227
|
+
}],
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('pipeline with dollar anchor in double quoted grep pattern', async t => {
|
|
233
|
+
const result = await runParser(
|
|
234
|
+
bashScriptParser,
|
|
235
|
+
'ls -la /home | grep "\\.ts$" | grep -v "\\.test\\.ts"',
|
|
236
|
+
stringParserInputCompanion,
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
t.is(result.entries[0].pipeline.commands.length, 3);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test('simple variable', async t => {
|
|
243
|
+
const result = await runParser(
|
|
244
|
+
bashScriptParser,
|
|
245
|
+
'echo $HOME',
|
|
246
|
+
stringParserInputCompanion,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
250
|
+
if (cmd.type === 'simple') {
|
|
251
|
+
t.deepEqual(cmd.args[0], {
|
|
252
|
+
parts: [{ type: 'variable', name: 'HOME' }],
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test('command substitution', async t => {
|
|
258
|
+
const result = await runParser(
|
|
259
|
+
bashScriptParser,
|
|
260
|
+
'echo $(pwd)',
|
|
261
|
+
stringParserInputCompanion,
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
265
|
+
if (cmd.type === 'simple') {
|
|
266
|
+
t.is(cmd.args[0].parts[0].type, 'commandSubstitution');
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test('backtick substitution', async t => {
|
|
271
|
+
const result = await runParser(
|
|
272
|
+
bashScriptParser,
|
|
273
|
+
'echo `pwd`',
|
|
274
|
+
stringParserInputCompanion,
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
278
|
+
if (cmd.type === 'simple') {
|
|
279
|
+
t.is(cmd.args[0].parts[0].type, 'backtickSubstitution');
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
test('subshell', async t => {
|
|
284
|
+
const result = await runParser(
|
|
285
|
+
bashScriptParser,
|
|
286
|
+
'(cd dir; pwd)',
|
|
287
|
+
stringParserInputCompanion,
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
t.is(result.entries[0].pipeline.commands[0].type, 'subshell');
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test('brace group', async t => {
|
|
294
|
+
const result = await runParser(
|
|
295
|
+
bashScriptParser,
|
|
296
|
+
'{ echo hello; }',
|
|
297
|
+
stringParserInputCompanion,
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
t.is(result.entries[0].pipeline.commands[0].type, 'braceGroup');
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('command list with &&', async t => {
|
|
304
|
+
const result = await runParser(
|
|
305
|
+
bashScriptParser,
|
|
306
|
+
'cmd1 && cmd2',
|
|
307
|
+
stringParserInputCompanion,
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
t.is(result.entries.length, 2);
|
|
311
|
+
t.is(result.entries[0].separator, '&&');
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test('command list with ||', async t => {
|
|
315
|
+
const result = await runParser(
|
|
316
|
+
bashScriptParser,
|
|
317
|
+
'cmd1 || cmd2',
|
|
318
|
+
stringParserInputCompanion,
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
t.is(result.entries.length, 2);
|
|
322
|
+
t.is(result.entries[0].separator, '||');
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
test('command list with ;', async t => {
|
|
326
|
+
const result = await runParser(
|
|
327
|
+
bashScriptParser,
|
|
328
|
+
'cmd1; cmd2',
|
|
329
|
+
stringParserInputCompanion,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
t.is(result.entries.length, 2);
|
|
333
|
+
t.is(result.entries[0].separator, ';');
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test('background command', async t => {
|
|
337
|
+
const result = await runParser(
|
|
338
|
+
bashScriptParser,
|
|
339
|
+
'cmd &',
|
|
340
|
+
stringParserInputCompanion,
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
t.is(result.entries[0].separator, '&');
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test('assignment', async t => {
|
|
347
|
+
const result = await runParser(
|
|
348
|
+
bashScriptParser,
|
|
349
|
+
'VAR=value cmd',
|
|
350
|
+
stringParserInputCompanion,
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
354
|
+
if (cmd.type === 'simple') {
|
|
355
|
+
t.is(cmd.assignments.length, 1);
|
|
356
|
+
t.is(cmd.assignments[0].name, 'VAR');
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
test('negated pipeline', async t => {
|
|
361
|
+
const result = await runParser(
|
|
362
|
+
bashScriptParser,
|
|
363
|
+
'! cmd',
|
|
364
|
+
stringParserInputCompanion,
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
t.is(result.entries[0].pipeline.negated, true);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test('complex pipeline with redirects', async t => {
|
|
371
|
+
const result = await runParser(
|
|
372
|
+
bashScriptParser,
|
|
373
|
+
'cat file 2>/dev/null | grep pattern | sort > output',
|
|
374
|
+
stringParserInputCompanion,
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
t.is(result.entries[0].pipeline.commands.length, 3);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test('[[ treated as command name', async t => {
|
|
381
|
+
const result = await runParser(
|
|
382
|
+
bashScriptParser,
|
|
383
|
+
'[[ -f file ]]',
|
|
384
|
+
stringParserInputCompanion,
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
388
|
+
if (cmd.type === 'simple') {
|
|
389
|
+
t.deepEqual(cmd.name, { parts: [{ type: 'literal', value: '[[' }] });
|
|
390
|
+
t.is(cmd.args.length, 3); // -f, file, ]]
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
// Braced variable expansion: ${VAR}
|
|
395
|
+
test('braced variable expansion', async t => {
|
|
396
|
+
const result = await runParser(
|
|
397
|
+
bashScriptParser,
|
|
398
|
+
'echo ${HOME}',
|
|
399
|
+
stringParserInputCompanion,
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
403
|
+
if (cmd.type === 'simple') {
|
|
404
|
+
t.is(cmd.args[0].parts[0].type, 'variableBraced');
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
// Braced variable with default: ${VAR:-default}
|
|
409
|
+
test('braced variable with default value', async t => {
|
|
410
|
+
const result = await runParser(
|
|
411
|
+
bashScriptParser,
|
|
412
|
+
'echo ${VAR:-default}',
|
|
413
|
+
stringParserInputCompanion,
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
417
|
+
if (cmd.type === 'simple') {
|
|
418
|
+
t.is(cmd.args[0].parts[0].type, 'variableBraced');
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
// Arithmetic expansion: $((1+2))
|
|
423
|
+
test('arithmetic expansion', async t => {
|
|
424
|
+
const result = await runParser(
|
|
425
|
+
bashScriptParser,
|
|
426
|
+
'echo $((1+2))',
|
|
427
|
+
stringParserInputCompanion,
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
431
|
+
if (cmd.type === 'simple') {
|
|
432
|
+
t.is(cmd.args[0].parts[0].type, 'arithmeticExpansion');
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// Bare $ at end of unquoted word
|
|
437
|
+
test('bare dollar at end of unquoted word', async t => {
|
|
438
|
+
const result = await runParser(
|
|
439
|
+
bashScriptParser,
|
|
440
|
+
'echo foo$',
|
|
441
|
+
stringParserInputCompanion,
|
|
442
|
+
);
|
|
443
|
+
|
|
444
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
445
|
+
if (cmd.type === 'simple') {
|
|
446
|
+
t.deepEqual(cmd.args[0], {
|
|
447
|
+
parts: [
|
|
448
|
+
{ type: 'literal', value: 'foo' },
|
|
449
|
+
{ type: 'literal', value: '$' },
|
|
450
|
+
],
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// Bare $ as its own unquoted word
|
|
456
|
+
test('bare dollar as standalone unquoted word', async t => {
|
|
457
|
+
const result = await runParser(
|
|
458
|
+
bashScriptParser,
|
|
459
|
+
'echo $',
|
|
460
|
+
stringParserInputCompanion,
|
|
461
|
+
);
|
|
462
|
+
|
|
463
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
464
|
+
if (cmd.type === 'simple') {
|
|
465
|
+
t.deepEqual(cmd.args[0], {
|
|
466
|
+
parts: [
|
|
467
|
+
{ type: 'literal', value: '$' },
|
|
468
|
+
],
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// Comment after command
|
|
474
|
+
test('comment after command', async t => {
|
|
475
|
+
const result = await runParser(
|
|
476
|
+
bashScriptParser,
|
|
477
|
+
'echo hello # this is a comment',
|
|
478
|
+
stringParserInputCompanion,
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
482
|
+
if (cmd.type === 'simple') {
|
|
483
|
+
t.is(cmd.args.length, 1);
|
|
484
|
+
t.deepEqual(cmd.args[0], {
|
|
485
|
+
parts: [{ type: 'literal', value: 'hello' }],
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
// ANSI-C quoting: $'...'
|
|
491
|
+
test('ansi-c quoting', async t => {
|
|
492
|
+
const result = await runParser(
|
|
493
|
+
bashScriptParser,
|
|
494
|
+
"echo $'hello\\nworld'",
|
|
495
|
+
stringParserInputCompanion,
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
499
|
+
if (cmd.type === 'simple') {
|
|
500
|
+
t.is(cmd.args.length, 1);
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
// Braced variable in double quotes: "${VAR}"
|
|
505
|
+
test('braced variable in double quotes', async t => {
|
|
506
|
+
const result = await runParser(
|
|
507
|
+
bashScriptParser,
|
|
508
|
+
'echo "${HOME}"',
|
|
509
|
+
stringParserInputCompanion,
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
513
|
+
if (cmd.type === 'simple') {
|
|
514
|
+
const dq = cmd.args[0].parts[0];
|
|
515
|
+
if (dq.type === 'doubleQuoted') {
|
|
516
|
+
t.is(dq.parts[0].type, 'variableBraced');
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
// Arithmetic expansion in double quotes
|
|
522
|
+
test('arithmetic expansion in double quotes', async t => {
|
|
523
|
+
const result = await runParser(
|
|
524
|
+
bashScriptParser,
|
|
525
|
+
'echo "$((1+2))"',
|
|
526
|
+
stringParserInputCompanion,
|
|
527
|
+
);
|
|
528
|
+
|
|
529
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
530
|
+
if (cmd.type === 'simple') {
|
|
531
|
+
const dq = cmd.args[0].parts[0];
|
|
532
|
+
if (dq.type === 'doubleQuoted') {
|
|
533
|
+
t.is(dq.parts[0].type, 'arithmeticExpansion');
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// Process substitution: <(cmd)
|
|
539
|
+
test('process substitution input', async t => {
|
|
540
|
+
const result = await runParser(
|
|
541
|
+
bashScriptParser,
|
|
542
|
+
'diff <(sort file1) <(sort file2)',
|
|
543
|
+
stringParserInputCompanion,
|
|
544
|
+
);
|
|
545
|
+
|
|
546
|
+
t.truthy(result);
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
// Line continuation (backslash-newline)
|
|
550
|
+
test('line continuation', async t => {
|
|
551
|
+
const result = await runParser(
|
|
552
|
+
bashScriptParser,
|
|
553
|
+
'echo hello \\\nworld',
|
|
554
|
+
stringParserInputCompanion,
|
|
555
|
+
);
|
|
556
|
+
|
|
557
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
558
|
+
if (cmd.type === 'simple') {
|
|
559
|
+
t.is(cmd.args.length, 2);
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
// Hash in middle of unquoted word is literal, not a comment
|
|
564
|
+
test('hash in middle of unquoted word', async t => {
|
|
565
|
+
const result = await runParser(
|
|
566
|
+
bashScriptParser,
|
|
567
|
+
'echo foo#bar',
|
|
568
|
+
stringParserInputCompanion,
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
572
|
+
if (cmd.type === 'simple') {
|
|
573
|
+
t.deepEqual(cmd.args[0], {
|
|
574
|
+
parts: [{ type: 'literal', value: 'foo#bar' }],
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
test('if treated as command name', async t => {
|
|
580
|
+
const result = await runParser(
|
|
581
|
+
bashScriptParser,
|
|
582
|
+
'if true',
|
|
583
|
+
stringParserInputCompanion,
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
const cmd = result.entries[0].pipeline.commands[0];
|
|
587
|
+
if (cmd.type === 'simple') {
|
|
588
|
+
t.deepEqual(cmd.name, { parts: [{ type: 'literal', value: 'if' }] });
|
|
589
|
+
}
|
|
590
|
+
});
|