Skip to content

Commit 9802fb3

Browse files
lkoskelaljharb
authored andcommitted
[New] Add support for here strings (<<<)
1 parent 216b198 commit 9802fb3

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

parse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// '<(' is process substitution operator and
44
// can be parsed the same as control operator
55
var CONTROL = '(?:' + [
6-
'\\|\\|', '\\&\\&', ';;', '\\|\\&', '\\<\\(', '>>', '>\\&', '<\\&', '[&;()|<>]'
6+
'\\|\\|', '\\&\\&', ';;', '\\|\\&', '\\<\\(', '\\<\\<\\<', '>>', '>\\&', '<\\&', '[&;()|<>]'
77
].join('|') + ')';
88
var META = '|&;()<> \\t';
99
var BAREWORD = '(\\\\[\'"' + META + ']|[^\\s\'"' + META + '])+';

test/env.js

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ test('expand environment variables', function (t) {
2323
t.end();
2424
});
2525

26+
test('expand environment variables within here-strings', function (t) {
27+
t.same(parse('a <<< $x', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']);
28+
t.same(parse('a <<< ${x}', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']);
29+
t.same(parse('a <<< "$x"', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']);
30+
t.same(parse('a <<< "${x}"', { x: 'Joe' }), ['a', { op: '<<<' }, 'Joe']);
31+
32+
t.end();
33+
});
34+
2635
test('environment variables with metacharacters', function (t) {
2736
t.same(parse('a $XYZ c', { XYZ: '"b"' }), ['a', '"b"', 'c']);
2837
t.same(parse('a $XYZ c', { XYZ: '$X', X: 5 }), ['a', '$X', 'c']);

test/op.js

+9
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ test('duplicating input file descriptors', function (t) {
8282
t.end();
8383
});
8484

85+
test('here strings', function (t) {
86+
t.same(parse('cat <<< "hello world"'), ['cat', { op: '<<<' }, 'hello world']);
87+
t.same(parse('cat <<< hello'), ['cat', { op: '<<<' }, 'hello']);
88+
t.same(parse('cat<<<hello'), ['cat', { op: '<<<' }, 'hello']);
89+
t.same(parse('cat<<<"hello world"'), ['cat', { op: '<<<' }, 'hello world']);
90+
91+
t.end();
92+
});
93+
8594
test('glob patterns', function (t) {
8695
t.same(
8796
parse('tap test/*.test.js'),

0 commit comments

Comments
 (0)