aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Kevin Ballard <kevin@sb.org>2014-08-20 22:01:24 -0700
committerGravatar Kevin Ballard <kevin@sb.org>2014-08-20 22:09:32 -0700
commitcc49042294aceb3ab30396eb5731e4ac0cf601bc (patch)
treeaa8b79cdcf55b3ca88f4f9db0685de2cef33a115 /tests
parent3981b644d68f6b6947b4a12810c2fa5e09da4e58 (diff)
Parse slices even for empty variables
When a variable is parsed as being empty, parse out the slice and validate the indexes anyway, behaving for slicing purposes as if the variable had a single empty value. Besides providing errors when expected, this also fixes the following: set -l foo echo "$foo[1]" This used to print "[1]", now it properly prints nothing.
Diffstat (limited to 'tests')
-rw-r--r--tests/expansion.err18
-rw-r--r--tests/expansion.in12
-rw-r--r--tests/expansion.out4
3 files changed, 34 insertions, 0 deletions
diff --git a/tests/expansion.err b/tests/expansion.err
index e69de29b..6346f23f 100644
--- a/tests/expansion.err
+++ b/tests/expansion.err
@@ -0,0 +1,18 @@
+Array index out of bounds
+fish: show "$foo[2]"
+ ^
+Array index out of bounds
+fish: show $foo[2]
+ ^
+Array index out of bounds
+fish: show "$foo[1 2]"
+ ^
+Array index out of bounds
+fish: show $foo[1 2]
+ ^
+Array index out of bounds
+fish: show "$foo[2 1]"
+ ^
+Array index out of bounds
+fish: show $foo[2 1]
+ ^
diff --git a/tests/expansion.in b/tests/expansion.in
index d362e789..8b48772e 100644
--- a/tests/expansion.in
+++ b/tests/expansion.in
@@ -62,3 +62,15 @@ show "$$foo"
show $$foo
show "prefix$$foo"
show prefix$$foo
+
+set -l foo
+show "$foo[1]"
+show $foo[1]
+show "$foo[-1]"
+show $foo[-1]
+show "$foo[2]"
+show $foo[2]
+show "$foo[1 2]"
+show $foo[1 2]
+show "$foo[2 1]"
+show $foo[2 1]
diff --git a/tests/expansion.out b/tests/expansion.out
index 3e763180..fe594539 100644
--- a/tests/expansion.out
+++ b/tests/expansion.out
@@ -36,3 +36,7 @@
2 baz quux
1 prefixbaz quux fooest
2 prefixbaz prefixquux
+1
+0
+1
+0