diff --git a/src/tagui_parse.php b/src/tagui_parse.php index 0bce2b5a..43522329 100755 --- a/src/tagui_parse.php +++ b/src/tagui_parse.php @@ -857,6 +857,10 @@ function mouse_intent($raw_intent) { else if (strtolower($params) == "up") return "casper.then(function() {".call_sikuli($raw_intent,"up"); else echo "ERROR - " . current_line() . " cannot understand step " . $raw_intent . "\n";} +// helper function as check_intent() adds an if block that immediately closes without going through closure handling +function check_intent_clear_injected_if_block() {$last_delimiter_pos = strrpos($GLOBALS['code_block_tracker'],"|"); +$GLOBALS['code_block_tracker']=substr($GLOBALS['code_block_tracker'],0,$last_delimiter_pos); return "";} + function check_intent($raw_intent) { $params = trim(substr($raw_intent." ",1+strpos($raw_intent." "," "))); $params = str_replace("||"," JAVASCRIPT_OR ",$params); // to handle conflict with "|" delimiter @@ -867,8 +871,10 @@ function check_intent($raw_intent) { if (substr_count($params,"|")!=2) echo "ERROR - " . current_line() . " if/true/false missing for " . $raw_intent . "\n"; else if (getenv('tagui_test_mode') == 'true') return "casper.then(function() {"."{".parse_condition("if ".$param1). -"\ntest.assert(true,".add_concat($param2).");\nelse test.assert(false,".add_concat($param3).");}".end_fi()."});"."\n\n"; -else return "casper.then(function() {"."{".parse_condition("if ".$param1)."\nthis.echo(".add_concat($param2).");\nelse this.echo(".add_concat($param3).");}".end_fi()."});"."\n\n";} +"\ntest.assert(true,".add_concat($param2).");\nelse test.assert(false,".add_concat($param3).");}". +check_intent_clear_injected_if_block().end_fi()."});"."\n\n"; +else return "casper.then(function() {"."{".parse_condition("if ".$param1)."\nthis.echo(".add_concat($param2). +");\nelse this.echo(".add_concat($param3).");}".check_intent_clear_injected_if_block().end_fi()."});"."\n\n";} function test_intent($raw_intent) { echo "ERROR - " . current_line() . " use CasperJS tester module to professionally " . $raw_intent . "\n"; diff --git a/src/test/positive_test b/src/test/positive_test index 535024fc..1efa7b01 100644 --- a/src/test/positive_test +++ b/src/test/positive_test @@ -438,6 +438,15 @@ check eggs lesser than 10|"eggs lesser than 10"|"eggs not lesser than 10" check eggs lesser than 10 | 'eggs lesser than 10' | 'eggs not lesser than 10' check eggs lesser than 10|'eggs lesser than 10'|'eggs not lesser than 10' +// test check within for loop +for n from 1 to 10 +check eggs lesser than 10 | "eggs lesser than 10" | "eggs not lesser than 10" + +for n from 1 to 10 +{ +check eggs lesser than 10 | "eggs lesser than 10" | "eggs not lesser than 10" +} + // test frame frame mainframe echo "test mainframe" diff --git a/src/test/positive_test.signature b/src/test/positive_test.signature index 21402865..ec5d2dab 100644 --- a/src/test/positive_test.signature +++ b/src/test/positive_test.signature @@ -2733,6 +2733,33 @@ casper.then(function() {{if ((eggs < 10)) this.echo('eggs lesser than 10'); else this.echo('eggs not lesser than 10');}}); +// test check within for loop +casper.then(function() {for (n=1; n<=10; n++) +{casper.then(function() {for_loop_signal = '[CONTINUE_SIGNAL][n]';}); +(function (n) { // start of IIFE pattern +{ // start of code block + +casper.then(function() {{if ((eggs < 10)) +this.echo("eggs lesser than 10"); +else this.echo("eggs not lesser than 10");}}); + +} // end of code block +})(n); // end of IIFE pattern, with dummy marker for break step +casper.then(function() {for_loop_signal = '[BREAK_SIGNAL][n]';});}}); + +casper.then(function() {for (n=1; n<=10; n++) +{casper.then(function() {for_loop_signal = '[CONTINUE_SIGNAL][n]';}); +(function (n) { // start of IIFE pattern +{ // start of code block + +casper.then(function() {{if ((eggs < 10)) +this.echo("eggs lesser than 10"); +else this.echo("eggs not lesser than 10");}}); + +} // end of code block +})(n); // end of IIFE pattern, with dummy marker for break step +casper.then(function() {for_loop_signal = '[BREAK_SIGNAL][n]';});}}); + // test frame casper.then(function() {techo('frame mainframe');}); casper.withFrame('mainframe', function() {