diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-05-25 12:12:13 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-05-27 15:44:40 +0200 |
commit | ba628f6f90e7412245dcebdecd9cfa7e4bbf989c (patch) | |
tree | 8f7f109c70d615bc93daa2a8f4b25ceb3842e062 /tests/expansion | |
parent | 2a9204cab666d47770bf3809d95a689088019121 (diff) |
Add support for value subscript after expansionsadhoc-recipe-history
Value subscript is only recognized in evaluation contexts (due to ambiguity
with wildcard patterns; consider: $x[123].txt) and should be unseparated from
the previous token. For example:
x = ($y[1])
x = (($f ? $y : $z)[1])
x = ($identity($x)[$z])
Diffstat (limited to 'tests/expansion')
-rw-r--r-- | tests/expansion/concat.testscript | 2 | ||||
-rw-r--r-- | tests/expansion/subscript.testscript | 97 |
2 files changed, 98 insertions, 1 deletions
diff --git a/tests/expansion/concat.testscript b/tests/expansion/concat.testscript index 181a738..bec48ce 100644 --- a/tests/expansion/concat.testscript +++ b/tests/expansion/concat.testscript @@ -1,4 +1,4 @@ -# file : tests/expansion/type.testscript +# file : tests/expansion/concat.testscript # license : MIT; see accompanying LICENSE file # Test concatenated expansion. diff --git a/tests/expansion/subscript.testscript b/tests/expansion/subscript.testscript new file mode 100644 index 0000000..0c06394 --- /dev/null +++ b/tests/expansion/subscript.testscript @@ -0,0 +1,97 @@ +# file : tests/expansion/subscript.testscript +# license : MIT; see accompanying LICENSE file + +# Test subscript expansion. + +.include ../common.testscript + +: basics +: +$* <<EOI >>EOO +x = zero one two three +y = zero@one two@three +i = 2 + +print ($x[1]) +print ($x[4]) +print (($x)[1]) +print (($x)[4]) +print ($identity($x)[1]) +print ($identity($x)[4]) + +print + +print ($y[1]) +print ($y[4]) +print (($y)[1]) +print (($y)[4]) +print ($identity($y)[1]) +print ($identity($y)[4]) + +print + +print ($x[$i]) + +EOI +one +[null] +one +[null] +one +[null] + +two@three +[null] +two@three +[null] +two@three +[null] + +two +EOO + +: unseparated +: +$* <<EOI >>EOO +x = zero one +print ($x [1]) +EOI +zero one +EOO + +: escape +: +$* <<EOI >>EOO +x = zero +print ($x\[abc]) +EOI +EOO + +: preparse +: +$* <<EOI >>EOO +x = zero one two three +print (true ? $x[1] : $x[]) +EOI +one +EOO + +: missing-rsbrace +: +$* <'print ($x[1)' 2>>EOE != 0 +<stdin>:1:12: error: expected ']' instead of ')' +EOE + +: invalid-subscript +: +$* <'print ($x[1a])' 2>>EOE != 0 +<stdin>:1:11: error: invalid value subscript: invalid uint64 value: '1a' + <stdin>:1:9: info: use the '\[' escape sequence if this is a wildcard pattern +EOE + +: empty-subscript +: +$* <'print ($x[])' 2>>EOE != 0 +<stdin>:1:11: error: invalid value subscript: invalid uint64 value: empty + <stdin>:1:9: info: use the '\[' escape sequence if this is a wildcard pattern +EOE |