diff options
| author | Toby Goodwin <toby@paccrat.org> | 2018-03-17 18:32:40 +0000 |
|---|---|---|
| committer | Toby Goodwin <toby@paccrat.org> | 2018-03-17 18:32:40 +0000 |
| commit | e7b1461bb4ff9fed1b1240e50726012e365f160d (patch) | |
| tree | 8187e5070ef89146dbc1db61421207daf9a8b522 /trip.rc | |
| parent | cccdab7ea2bb922413f02698ecc5969c00e7a7aa (diff) | |
| parent | d18aac739636fd9ae1f84fef8347f46216fb8d9c (diff) | |
Merge branch 'continue'
Diffstat (limited to 'trip.rc')
| -rw-r--r-- | trip.rc | 76 |
1 files changed, 76 insertions, 0 deletions
@@ -598,6 +598,82 @@ x=$tmpdir/qux*/foo rm -rf $tmpdir +############################################################################# +## Check builtin continue in while loop. +############################################################################# +q='''' +C=$q^while-continue$q +L=() + +save_star = * +ten = a^(1 2 3 4 5 6 7 8 9 10) +* = $ten +while (! ~ $#* 0) { + n = $1; shift + if (~ $n a2 a3) { + continue + } + L=($L $n) +} +* = $save_star; save_star = () + +if (!~ $#L 8) { + fail Wrong length of list from $C: $#L +} +if (!~ $L(1) a1) { + fail First element of $C list is not a1: $L(1) +} +if (!~ $L(2) a4) { + fail Second element of $C list is not a4: $L(2) +} +C=() L=() + +############################################################################# +## Check builtin continue in for loop. +############################################################################# +C=$q^for-continue$q +L=() + +for (x in a b c d e f g) { + if (~ $x c f) { + continue + } + L=($L $x) +} +if (!~ $#L 5) { + fail Wrong length of list from $C +} +if (!~ $L(1) a) { + fail First element of $C list is not a: $L(1) +} +if (!~ $L(3) d) { + fail Third element of $C list is not d: $L(3) +} +if (!~ $L(5) g) { + fail Fifth element of $C list is not g: $L(5) +} +C=() L=() + +submatch continue 'rc: continue outside of loop' 'continue outside of loop' + +############################################################################# +## check builtin continue in for loop (2) +############################################################################# +L=() +for (x in a b c d e f g) { + if (~ $x b d) { + continue + } + L=($L $x) + if (~ $x f) { + break; + } +} + +if (!~ $^L 'a c e f') { + fail List should be '(a c e f)', but is $L +} + # test support for unquoted = submatch 'echo foo = bar' 'foo = bar' 'unquoted equals 2' submatch 'echo foo=bar' 'foo=bar' 'unquoted equals 2' |