1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-10-03 09:21:19 +02:00
zsh/Test/14array.ztst

78 lines
1.0 KiB
Plaintext
Raw Normal View History

2000-06-02 03:35:54 +02:00
# Tests for array indexing
%prep
foo=(a b c d e f g)
%test
echo .$foo[1].
0:The first element
>.a.
2000-06-02 03:35:54 +02:00
echo .$foo[1,4].
0:Normal multi-item indexing
2000-06-02 03:35:54 +02:00
>.a b c d.
echo .$foo[1,0].
0:This should be empty
>..
2000-06-02 03:35:54 +02:00
echo .$foo[4,1].
0:Another empty slice
2000-06-02 03:35:54 +02:00
>..
echo .$foo[1,-8].
2000-06-02 11:32:30 +02:00
0:An empty slice with a negative end
>..
2000-06-02 03:35:54 +02:00
echo .$foo[0].
0:Treat 0 like 1
2000-06-02 03:35:54 +02:00
>.a.
echo .$foo[0,0].
0:Treat 0,0 like 1,1.
2000-06-02 03:35:54 +02:00
>.a.
echo .$foo[0,1].
0:Another weird way to access the first element
2000-06-02 03:35:54 +02:00
>.a.
echo .$foo[3].
0:An inner element
>.c.
2000-06-02 03:35:54 +02:00
echo .$foo[2,2].
0:Another inner element
2000-06-02 03:35:54 +02:00
>.b.
echo .$foo[2,-4].
2000-06-02 11:32:30 +02:00
0:A slice with a negative end
>.b c d.
2000-06-02 03:35:54 +02:00
echo .$foo[-4,5].
0:A slice with a negative start
2000-06-02 03:35:54 +02:00
>.d e.
2000-06-02 03:40:51 +02:00
echo .$foo[-6,-2].
2000-06-02 11:32:30 +02:00
0:A slice with a negative start and end
2000-06-02 03:40:51 +02:00
>.b c d e f.
setopt ksh_arrays
echo .${foo[1,2]}.
unsetopt ksh_arrays
0:Ksh array indexing
>.b c.
setopt ksh_arrays
echo .${foo[0,1]}.
unsetopt ksh_arrays
0:Ksh array indexing (ii)
>.a b.
setopt ksh_arrays
echo .${foo[1,-1]}.
unsetopt ksh_arrays
0:Ksh array indexing (iii)
>.b c d e f g.