mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Shell: Add tests for slices
This commit is contained in:
parent
4ff430b615
commit
2efa17184d
Notes:
sideshowbarker
2024-07-18 21:08:48 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/2efa17184d1 Pull-request: https://github.com/SerenityOS/serenity/pull/5749
1 changed files with 73 additions and 0 deletions
73
Userland/Shell/Tests/slice.sh
Normal file
73
Userland/Shell/Tests/slice.sh
Normal file
|
@ -0,0 +1,73 @@
|
|||
#!/bin/sh
|
||||
|
||||
source $(dirname "$0")/test-commons.inc
|
||||
|
||||
# can we use [0] as a bareword still?
|
||||
if not test [0] = "[0]" {
|
||||
fail cannot use '[0]' as a bareword anymore
|
||||
}
|
||||
|
||||
# can we use [0,2] as a bareword still?
|
||||
if not test [0,2] = "[0,2]" {
|
||||
fail cannot use '[0,2]' as a bareword anymore
|
||||
}
|
||||
|
||||
# can we use [0..2] as a bareword still?
|
||||
if not test [0..2] = "[0..2]" {
|
||||
fail cannot use '[0..2]' as a bareword anymore
|
||||
}
|
||||
|
||||
# Lists
|
||||
x=(1 2 3)
|
||||
if not test $x[0] -eq 1 {
|
||||
fail invalid first element
|
||||
}
|
||||
|
||||
if not test $x[1] -eq 2 {
|
||||
fail invalid second element
|
||||
}
|
||||
|
||||
if not test $x[-1] -eq 3 {
|
||||
fail invalid first-from-end element
|
||||
}
|
||||
|
||||
if not test $x[-2] -eq 2 {
|
||||
fail invalid second-from-end element
|
||||
}
|
||||
|
||||
## Multiple indices
|
||||
if not test "$x[1,2]" = "2 3" {
|
||||
fail invalid multi-select '(1, 2)'
|
||||
}
|
||||
|
||||
if not test "$x[0..2]" = "1 2 3" {
|
||||
fail invalid multi-select with range '[0..2]'
|
||||
}
|
||||
|
||||
# Strings
|
||||
x="Well Hello Friends!"
|
||||
if not test $x[0] = W {
|
||||
fail invalid string first element
|
||||
}
|
||||
|
||||
if not test $x[1] = e {
|
||||
fail invalid string second element
|
||||
}
|
||||
|
||||
if not test $x[-1] = '!' {
|
||||
fail invalid string first-from-end element
|
||||
}
|
||||
|
||||
if not test $x[-2] = 's' {
|
||||
fail invalid string second-from-end element
|
||||
}
|
||||
|
||||
if not test $x[0,5,11,-1] = 'WHF!' {
|
||||
fail invalid string multi-select
|
||||
}
|
||||
|
||||
if not test $x[5..9] = "Hello" {
|
||||
fail invalid string multi-select with range '[5..9]'
|
||||
}
|
||||
|
||||
pass
|
Loading…
Reference in a new issue