Skip to content

Commit

Permalink
#241 - improve use of variables - variable instead of '+variable+'
Browse files Browse the repository at this point in the history
more details in issue - #241
  • Loading branch information
kensoh committed Jul 16, 2018
1 parent 0d44300 commit 84c60fe
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/tagui_parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ function parse_backticks($script_line) {
// check for even number of ` to reduce false-positive because backtick syntax is supposed to be matching pairs
if ((substr_count($script_line,'`') > 1) and (!(substr_count($script_line,'`') & 1))) {
if ($GLOBALS['repo_count'] == 0) {
echo "ERROR - ".current_line()." no repository data for ".$script_line."\n";
$script_line = parse_variables($script_line);
} else {
if (getenv('tagui_data_set')!==false) {
$data_set = intval(getenv('tagui_data_set'));
Expand All @@ -328,11 +328,20 @@ function parse_backticks($script_line) {
$script_line = str_replace($repo_keyword, $repo_data_value, $script_line);
}
if (strpos($script_line,'`')!==false) {
echo "ERROR - ".current_line()." no repository data for ".$script_line."\n";
$script_line = parse_variables($script_line);
}
}
} return $script_line;}

function parse_variables($script_line) { // `variable` --> '+variable+'
$quote_token = "'+"; // token to alternate replacements for '+variable+'
for ($char_counter = 0; $char_counter < strlen($script_line); $char_counter++) {
if (substr($script_line,$char_counter,1) == "`") {
$script_line = substr_replace($script_line,$quote_token,$char_counter,1);
if ($quote_token == "'+") $quote_token = "+'"; else $quote_token = "'+";
}
} return $script_line;}

function parse_closure($script_line) {switch($script_line) {
// \\n is needed for py, r, vision as multi-line string needs to have \n escaped to work in javascript
// replacement code for [END_OF_LINE] custom token to denote line break is done at py, r, vision intents
Expand Down
15 changes: 15 additions & 0 deletions src/test/positive_test
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ api http://www.dummytestsite.com/api?COLOR1=red&COLOR2=green&COLOR3=blue
// test api with variables
var COLOR1='red'; var COLOR2='green'; var COLOR3='blue';
api http://www.dummytestsite.com/api?COLOR1='+COLOR1+'&COLOR2='+COLOR2+'&COLOR3='+COLOR3+'
api http://www.dummytestsite.com/api?COLOR1=`COLOR1`&COLOR2=`COLOR2`&COLOR3=`COLOR3`

// test run
run face_recognition par1 par2 par3
Expand Down Expand Up @@ -557,6 +558,20 @@ http://www.dummytestsite.com
// test url with variable
target_url = "www.dummytestsite.com";
http://'+target_url+'
http://`target_url`

// test use of variable
// old way for '+variable+' backward compatibility
locator = 'email_button'
click '+locator+'
number = 5
click (//*[@id="test"])['+variable+']

// new way of using `variable` to denote variable
locator = 'email_button'
click `locator`
number = 5
click (//*[@id="test"])[`variable`]

// test present function
if present('footer')
Expand Down
46 changes: 46 additions & 0 deletions src/test/positive_test.signature
Original file line number Diff line number Diff line change
Expand Up @@ -2631,6 +2631,10 @@ casper.then(function() {{techo('api http://www.dummytestsite.com/api?COLOR1='+CO
api_result = ''; api_result = call_api('http://www.dummytestsite.com/api?COLOR1='+COLOR1+'&COLOR2='+COLOR2+'&COLOR3='+COLOR3+'');
try {api_json = JSON.parse(api_result);} catch(e) {api_json = JSON.parse('null');}}});

casper.then(function() {{techo('api http://www.dummytestsite.com/api?COLOR1='+COLOR1+'&COLOR2='+COLOR2+'&COLOR3='+COLOR3+'');
api_result = ''; api_result = call_api('http://www.dummytestsite.com/api?COLOR1='+COLOR1+'&COLOR2='+COLOR2+'&COLOR3='+COLOR3+'');
try {api_json = JSON.parse(api_result);} catch(e) {api_json = JSON.parse('null');}}});

// test run
casper.then(function() {techo('run face_recognition par1 par2 par3');});
casper.then(function() {casper.waitForExec('face_recognition par1 par2 par3', null, function(response) {run_result = '';
Expand Down Expand Up @@ -2795,6 +2799,48 @@ target_url = "www.dummytestsite.com";
casper.then(function() {casper.thenOpen('http://'+target_url+'', function() {
techo('http://'+target_url+'' + ' - ' + this.getTitle());});}); // end of dynamic url block

casper.then(function() {casper.thenOpen('http://'+target_url+'', function() {
techo('http://'+target_url+'' + ' - ' + this.getTitle());});}); // end of dynamic url block

// test use of variable
// old way for '+variable+' backward compatibility
casper.then(function() { // start of JS code
locator = 'email_button'
}); // end of JS code

casper.then(function() {{techo('click '+locator+'');
casper.waitFor(function check() {return check_tx(''+locator+'');},
function then() {this.click(tx(''+locator+''));},
function timeout() {this.echo('ERROR - cannot find '+locator+'').exit();});}});

casper.then(function() { // start of JS code
number = 5
}); // end of JS code

casper.then(function() {{techo('click (//*[@id="test"])['+variable+']');
casper.waitFor(function check() {return check_tx('(//*[@id="test"])['+variable+']');},
function then() {this.click(tx('(//*[@id="test"])['+variable+']'));},
function timeout() {this.echo('ERROR - cannot find (//*[@id="test"])['+variable+']').exit();});}});

// new way of using '+variable+' to denote variable
casper.then(function() { // start of JS code
locator = 'email_button'
}); // end of JS code

casper.then(function() {{techo('click '+locator+'');
casper.waitFor(function check() {return check_tx(''+locator+'');},
function then() {this.click(tx(''+locator+''));},
function timeout() {this.echo('ERROR - cannot find '+locator+'').exit();});}});

casper.then(function() { // start of JS code
number = 5
}); // end of JS code

casper.then(function() {{techo('click (//*[@id="test"])['+variable+']');
casper.waitFor(function check() {return check_tx('(//*[@id="test"])['+variable+']');},
function then() {this.click(tx('(//*[@id="test"])['+variable+']'));},
function timeout() {this.echo('ERROR - cannot find (//*[@id="test"])['+variable+']').exit();});}});

// test present function
casper.then(function() {if ((present('footer')))
{ // start of code block
Expand Down

0 comments on commit 84c60fe

Please sign in to comment.