Skip to content

Commit

Permalink
Merge pull request #424 from tebelorg/master
Browse files Browse the repository at this point in the history
#423 - enable check step within for loop

**update summary** - check step was not originally designed to work in for loops. this update allows check step to work in for loops, and also adds test cases to verify that check step can work within for loops.

**technical details** - check step will insert an if block into the code block that immediately closes without normal processing line by line. this will cause TagUI to be mistaken that parsing is still within an if block and not handling a for loop block as it should be handled. in this change, a helper function check_intent_clear_injected_if_block() is added and called during parsing of check step to update TagUI internal tracking that the if block has been closed at end of the check step. that allows for loops to function correctly when check step is used within a loop.
  • Loading branch information
kensoh authored May 13, 2019
2 parents 7229e79 + 4db980f commit 7b6d2c8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/tagui_parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
Expand Down
9 changes: 9 additions & 0 deletions src/test/positive_test
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 27 additions & 0 deletions src/test/positive_test.signature
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 7b6d2c8

Please sign in to comment.