Sahi Script, using variable in _assertEqual - sahi

I want to put variable to check if is Equal some text in the page, but in this way - doens't work:
function check($value) {
_assertEqual($value, " - VERSION", _getText(_heading1($value, " - VERSION")));
_click(_link("Edit[1]"));
}
check ("HELP")
The result:
_assertEqual("HELP", " - VERSION", _getText(_heading1("HELP", " - VERSION"))); Error: The parameter passed to _getText was not found on
the browser at check (scripts/check.sah:3) at 2015-1-28 11:53:29
So, if I do in this way, it's works:
function check($value) {
_assertEqual("HELP - VERSION", _getText(_heading1("HELP - VERSION")));
_click(_link("Edit[1]"));
}
check ("HELP")
How to put this variable to works correctly?

Instead of _getText, try _set
for example:
var $helpVersion;
_set($helpVersion, _heading1("HELP - VERSION").textContent);
_assertEqual("HELP - VERSION", $helpVersion);

Rumen, the following is incorrect.
_heading1($value, " - VERSION")
A single string parameter has to be passed to _heading1. In your case, joining $value and " - VERSION" will work.
_heading1($value + " - VERSION")
The above change is what you need. So, your final function will look like this:
function check($value) {
_assertEqual("HELP - VERSION", _getText(_heading1($value + " - VERSION")));
_click(_link("Edit[1]"));
}
check ("HELP")

Related

Pre-compile textual replacement macro with arguments

I am trying to create some kind of a dut_error wrapper. Something that will take some arguments and construct them in a specific way to a dut_error.
I can't use a method to replace the calls to dut_error because to my understanding after check that ... then ... else can only come a dut_error (or dut_errorf). And indeed if I try to do something like:
my_dut_error(arg1: string, arg2: string) is {
dut_error("first argument is ", arg, " and second argument is ", arg2);
};
check that FALSE else my_dut_error("check1", "check2");
I get an error:
*** Error: Unrecognized exp
[Unrecognized expression 'FALSE else my_dut_error("check1", "check2")']
at line x in main.e
check that FALSE else my_dut_error("check1", "check2");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
So I thought about defining a macro to simply do a textual replace from my wrapper to an actual dut_error:
define <my_dut_error'exp> "my_dut_error(<arg1'name>, <arg2'name>)" as {
dut_error("first argument is ", <arg1'name>, " and second argument is ", <arg2'name>)
};
But got the same error.
Then I read about the preprocessor directive #define so tried:
#define my_dut_error(arg1, arg2) dut_error("first argument is ", arg, " and second argument is ", arg2)
But that just gave a syntax error.
How can I define a pre-compiled textual replacement macro that takes arguments, similar to C?
The reason I want to do that is to achieve some sort of an "interface" to the dut_error so all errors have a consistent structure. This way, different people writing different errors will only pass the arguments necessary by that interface and internally an appropriate message will be created.
not sure i understood what you want to do in the wrapper, but perhaps you can achieve what you want by using the dut_error_struct.
it has set of api, which you can use as hooks (do something when the error is caught) and to query about the specific error.
for example:
extend dut_error_struct {
pre_error() is also {
if source_method_name() == "post_generate" and
source_struct() is a BLUE packet {
out("\nProblem in generation? ", source_location());
// do something for error during generation
};
write() is first {
if get_mesage() ~ "AHB Error..." {
ahb_monitor::increase_errors();
};
};
};
dut_error accepts one parameter, one string. but you can decide of a "separator", that will define two parts to the message.
e.g. - instruct people to write "XXX" in the message, before "first arg" and "second arg".
check that legal else dut_error("ONE thing", "XXX", "another thing");
check that x < 7 else dut_error("failure ", "XXX", "of x not 7 but is ", x);
extend dut_error_struct {
write() is first {
var message_parts := str_split(get_message(), "XXX");
if message_parts.size() == 2 {
out ("First part of message is ", message_parts[0],
"\nand second part of message is ", message_parts[1]
);
};
};
I could get pretty close to what I want using the dut_errorf method combined with a preprocessor directive defining the format string:
#define DUT_FORMAT "first argument is %s and second argument is %s"
check that FALSE else dut_errorf(DUT_FORMAT, "check1", "check2");
but I would still prefer a way that doesn't require this DUT_FORMAT directive and instead uses dut_error_struct or something similar.

Assign empty string to a variable and change the value while executing the powershell script

I have a sample powershell script say test.ps1 with the below contents
$Arg=" "
Function EnableArg()
{
$Arg= "arg"
}
Function DisableArg()
{
$Arg= " "
}
Function Print()
{
Write-Host "Value - $Arg"
}
If I run this script using powershell ISE and try the following:
Print - > Value -
EnableArg
Print -> Value -
When I executed step 2 and then step 3, I was expecting
Value - arg
But unfortunately it shows
Value -
Not sure if the script is being reset everytime. I also tried explicitly declaring the type to [string] but no luck. Thanks in advance!
Instead of crossing scope boundaries, I recommend you use functions in a more appropriate fashion. You pass in parameters/arguments and you return output. Meaning you will capture the output of a function in a variable and pass arguments into a function.
Function EnableArg()
{
"arg"
}
Function DisableArg()
{
" "
}
Function Print($InternalArg)
{
Write-Host "Value - $InternalArg"
}
$arg = EnableArg
print $arg
$arg = DisableArg
Print $arg

Wix: Populate repeater with external API call

I'm referring to the following video How to Create A Web App With External API Access using Wix Code & wanted to know how I would populate a repeater rather than populating a paragraph tag as shown in the youtube video mentioned above.
Basically here is the pseudocode of what I would like to achieve:
If search box is equal to null or empty
Display all crypto currencie(s)
else
Display single crypto currency
Putting the info in a repeater isn't too different than what the example already shows. Actually, when the search box is empty, the API returns an array that just needs a little playing with to get it to work with a repeater.
So, assuming you added a repeater with the ID repeater1 that contains a text element with the id result, you can make the following minor changes to the page code. You don't need to touch the backend code at all.
First, in the button1_click event handler we'll remove the code that populates the text element with the data returned from the API. Instead, we'll add an _id property to each currency object (required for the repeater) and then feed that data to the repeater.
export function button1_click(event) {
getCryptoCurrencyInfo($w("#currencyInput").value)
.then(currencyInfo => {
// add an _id property to each currency object
currencyInfo.forEach(item => item._id = item.id);
// feed the data to the repeater
$w('#repeater1').data = currencyInfo;
} );
}
Then, we can take the code for populating the text element and stick it in the repeater1_itemReady event handler. This function will run once for each currency item in the array fed to the repeater's data property. Make sure you use the properties panel to wire the function to the matching repeater event.
export function repeater1_itemReady($item, itemData, index) {
$item("#result").text = "Name: " + itemData.name + "\n"
+ "Symbol: " + itemData.symbol + "\n"
+ "Rank: " + itemData.rank + "\n"
+ "Price (USD): " + itemData.price_usd + "\n"
+ "Market Capitalization (USD): " + itemData.market_cap_usd + "\n"
+ "Percent Change 1h: " + itemData.percent_change_1h + "\n"
+ "Percent Change 24h: " + itemData.percent_change_24h + "\n"
+ "Percent Change 7d: " + itemData.percent_change_7d;
}
Notice two subtle changes to the code. First, we use $item instead of $w to select the text element. This selects the specific instance of the text element in the current repeater element. Second, we use itemData instead of currencyInfo[0]. This gives us the specific data that is associated with the current repeater element.

adding params to joomla plugin based on external file

I am trying to develope a simple joomla plugin and i have a question, if you kindly could help me.
I have a long list of constants to use in my plugin, a group is to use with a joomla version and another group to use with another version, like this
//joomla version 2.5
$a01 = " some value "
$a02 = " some value "
$a03 =" some value "
....
....
$a99 = " some value "
//joomla version 3.0
$b01 = " some value "
$b02 = " some value "
$b03 = " some value "
....
....
$b99 = " some value "
In my plugin file i have this code:
if (!version_compare(JVERSION, '3.0', 'ge'))
{
// do something using constants for version less than 3.0
} else {
// do something using constants for version more than 3.0
}
For a better reading and organization where can hold those constants? In same file or in another file like (params or constants)? Which is the best approach? And how could i implement it?
What about placing it in a db-table? You retrieve them in your plugin by:
$db=JFactory::getDbo();
$db->setQuery('select key, value from #__yourtable where version ='.$version);
$list=$db-loadAssocList();
foreach($list as $v){
eval("define({$v['key']}, {$v['value']});");
}
Now all your constants for version $version are loaded.
...and if you want to be able to manage your constants from the joomla backend interface you could use a component-creator to quickly create this simple table with a full editing interface ( try component-creator.com )
regards Jonas (not affiliated with component-creator.com :) )

Where can I find the emit() function implementation used in MongoDB's map/reduce?

I am trying to develop a deeper understanding of map/reduce in MongoDB.
I figure the best way to accomplish this is to look at emit's actual implementation. Where can I find it?
Even better would just be a simple implementation of emit(). In the MongoDB documentation, they show a way to troubleshoot emit() by writing your own, but the basic implementation they give is really too basic.
I'd like to understand how the grouping is taking place.
I think the definition you are looking for is located here:
https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/mr.cpp#L886
There is quite a lot of context needed though to fully understand what is going on. I confess, I do not.
1.Mongo's required JS version is no longer in O.Powell's url, which is dead. I cannot find it.
2.The below code seems to be the snippet of most interest. This cpp function, switchMode, computes the emit function to use. It is currently at;
https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/mr.cpp#L815
3.I was trying to see if emit has a default to include the _id key, which seems to occur via _mrMap, not shown here. Elsewhere it is initialized to {}, the empty map.
void State::switchMode(bool jsMode) {
_jsMode = jsMode;
if (jsMode) {
// emit function that stays in JS
_scope->setFunction("emit",
"function(key, value) {"
" if (typeof(key) === 'object') {"
" _bailFromJS(key, value);"
" return;"
" }"
" ++_emitCt;"
" var map = _mrMap;"
" var list = map[key];"
" if (!list) {"
" ++_keyCt;"
" list = [];"
" map[key] = list;"
" }"
" else"
" ++_dupCt;"
" list.push(value);"
"}");
_scope->injectNative("_bailFromJS", _bailFromJS, this);
}
else {
// emit now populates C++ map
_scope->injectNative( "emit" , fast_emit, this );
}
}