From 2325713c2f574aa08b5ad1bb91a3e4ee30b6b0b5 Mon Sep 17 00:00:00 2001 From: Drazen Borkovic Date: Sat, 26 Aug 2017 16:19:50 -0700 Subject: Add "continue" builtin --- trip.rc | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'trip.rc') diff --git a/trip.rc b/trip.rc index 1189fb9..585e6be 100644 --- a/trip.rc +++ b/trip.rc @@ -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' -- cgit v1.2.3 From 383ea67ea46d335e0bd8b78168cd44c8bd56f6eb Mon Sep 17 00:00:00 2001 From: Drazen Borkovic Date: Sun, 27 Aug 2017 12:49:03 -0700 Subject: Change one continue-testing loop from for to while --- trip.rc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'trip.rc') diff --git a/trip.rc b/trip.rc index 585e6be..6a42350 100644 --- a/trip.rc +++ b/trip.rc @@ -605,14 +605,18 @@ q='''' C=$q^while-continue$q L=() +save_star = * ten = a^(1 2 3 4 5 6 7 8 9 10) * = $ten -for (n) { +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 } -- cgit v1.2.3