diff options
| author | Drazen Borkovic <borkovic@users.noreply.github.com> | 2017-08-26 16:19:50 -0700 |
|---|---|---|
| committer | Drazen Borkovic <borkovic@users.noreply.github.com> | 2017-08-26 16:19:50 -0700 |
| commit | 2325713c2f574aa08b5ad1bb91a3e4ee30b6b0b5 (patch) | |
| tree | 9b19cfccfcc35ff74d513452f5b159d82cb9a0d0 /trip.rc | |
| parent | 7dc3033c862c30d8998ed3e4c98c056286f31401 (diff) | |
Add "continue" builtin
Diffstat (limited to 'trip.rc')
| -rw-r--r-- | trip.rc | 72 |
1 files changed, 72 insertions, 0 deletions
@@ -598,6 +598,78 @@ x=$tmpdir/qux*/foo rm -rf $tmpdir +############################################################################# +## Check builtin continue in while loop. +############################################################################# +q='''' +C=$q^while-continue$q +L=() + +ten = a^(1 2 3 4 5 6 7 8 9 10) +* = $ten +for (n) { + if (~ $n a2 a3) { + continue + } + L=($L $n) +} +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' |