Skip to content

Commit

Permalink
Fixes for continue in [json lmap] and [json foreach]
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanogilvie committed Jan 27, 2015
1 parent 3cb1454 commit 196a952
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions generic/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ static int foreach(Tcl_Interp* interp, int objc, Tcl_Obj *const objv[], int coll
break;

case TCL_CONTINUE:
retcode = TCL_OK;
break;

case TCL_BREAK:
Expand Down
17 changes: 17 additions & 0 deletions tests/foreach.test
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ test foreach-5.1 {Single iterator, single var, over array, continue} -setup { #<
"6({\"x\":42})(x 42)" \
]
#>>>
test foreach-5.2 {Single iterator, single var, over array, continue on final iteration} -setup { #<<<
set i 0
set res {}
} -body {
json foreach elem {["a", "b", "other var", null]} {
if {[json get $elem] eq ""} continue
lappend res "[incr i]($elem)([json get $elem])"
}
set res
} -cleanup {
unset -nocomplain i res
} -result [list \
"1(\"a\")(a)" \
"2(\"b\")(b)" \
"3(\"other var\")(other var)" \
]
#>>>
test foreach-6.1 {Single iterator, single var, over array, break} -setup { #<<<
set i 0
set res {}
Expand Down
15 changes: 15 additions & 0 deletions tests/lmap.test
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ test lmap-5.1 {Single iterator, single var, over array, continue} -setup { #<<<
"6({\"x\":42})(x 42)" \
]
#>>>
test lmap-5.1 {Single iterator, single var, over array, continue on final iteration} -setup { #<<<
set i 0
} -body {
json lmap elem {["a", "b", "other var", null]} {
if {[json get $elem] eq ""} continue
string cat [incr i]($elem)([json get $elem])
}
} -cleanup {
unset -nocomplain i
} -result [list \
"1(\"a\")(a)" \
"2(\"b\")(b)" \
"3(\"other var\")(other var)" \
]
#>>>
test lmap-6.1 {Single iterator, single var, over array, break} -setup { #<<<
set i 0
} -body {
Expand Down

0 comments on commit 196a952

Please sign in to comment.