I've got a few methods which set the text within a text file.
I've set-up my jasmine tests to create the files with wrong values before I run my tests.
var gpioPath = 'tests/gpio-test/class/gpio';
//setup the filesystem with the exports path
fs.outputFileSync(gpioPath+'/export',0);
for(var i=0;i<6;i++){
fs.outputFileSync(gpioPath+i+'/value',2,'utf-8');
fs.outputFileSync(gpioPath+i+'/direction','none','utf-8');
}
Then, I run the methods which update the values in the files, and then I check that the files now have the correct values.
expect(fs.readFileSync(gpioPath+'/export','utf-8')).toBeGreaterThan(0);
var pin1d = fs.readFileSync(gpioPath+'1/direction','utf-8');
var pin1v = fs.readFileSync(gpioPath+'1/value','utf-8');
expect(pin1d).toBe('out');
expect(pin1v).toBe(0);
For some reason, these tests are all failing. I get
'0' expected to be greater than '0'
But when I look in the file, I have a value of 6.
I've tried putting a waits before running the test, just in case the files hadn't been changed yet, but even with a 10 second wait this is still failing.
I don't get any errors from the fileWrite method, which is what is updating the data, and as I've said, I can see that the file is updated, so why don't my tests reflect this?
fs.readFileSync(gpioPath+'/export','utf-8') will return a string, so you are essentially doing if (0 > '0'), which is false.
if you need to test numbers, you need to parse it as a number:
expect(parseInt(fs.readFileSync(gpioPath+'/export','utf-8'), 10))
.toBeGreaterThan(0);
This is assuming the file contains an ascii zero, and not a null byte.
Related
i'm trying to do something like that:
get_num_of_ones = "('1'):rep(%d)"
print(get_num_of_ones:format(24))
but i get the following result: ('1'):rep(24) and not 24 times the number 1.
how can I do it in this way so that i will get 111...11 (24 times the number 1) ?
The simplest, most straightforward, efficient and readable way to achieve what you want is simply to pass your number directly to string.rep; there is no need to format source code here:
get_num_of_ones = ('1'):rep(24)
print(get_num_of_ones)
If there is the artificial constraint that it needs to be achieved by formatting a source code template, you need to use load/loadstring:
get_num_of_ones = "return ('1'):rep(%d)" -- you need the "return" to make it a valid chunk, and to be able to get the result out
local source = get_num_of_ones:format(24) -- formatted source code
local chunk = assert(load(source)) -- load the source code; gives us a "chunk" (function) if there was no syntax error
local retval = chunk()
print(retval)
I'm trying to convert CSVs to JSONs in Node, and am running into a problem dynamically parsing date values (in addition to the built-in checkType: true for numbers and boolean values).
Using CSVtoJSON (csvtojson), I'm able to write an explicit declaration in the colParser parameter,
const jsonArray=await csv({checkType: true, colParser:{
'Measurement Timestamp':(item => {return new Date(item);})
}
}).fromFile(csvFilePath);
and this works well, but I want to be able to recognize the content on its own without me needing to explicitly write the header name.
I'm even happy to use a filter like let isTimeDate = (data) => /time|date/i.test(data) to run on the header names prior to the parsing, but I'm running into a wall trying to have the colParser cycle through that list.
I also don't want to have to run a isDate function on every single element, because that's just wasteful.
I have read this question
How to test for blank text field when using robotframework-selenium?
as well as the two links to the Robot Framework documentation in the answers but I still don't get how to check if a variable is empty.
I want to do this
if var A equals var B then
do something
else
do something else
where A is a string that can both contain something as well as be empty and where B is empty or null.
can be achieve using many different ways some are as follows, use whichever fits for you
this way you can check two variables equals OR not
Run Keyword If '${A}'=='${B}' do something ELSE do something
this way you can check if both of your variable are None or not in one go
Run Keyword If '${A}'=='None' And '${B}'=='None' do something
using following also you can get if your variables are equal of not if both values are equal it will return true
Should Be Equal ${A} ${B}
if both values are NOT equal it will return true.
Should Not Be Equal ${A} ${B}
for more information go through this docs
there is also ${EMPTY} variable in robot framework which you can use to check if variable is empty or not
Like this is working:
${aaax}= set variable aaa aa ba baavaa
${aaaxx}= set variable aaa aba baavaa
${aba}= set variable aba
${res1}= run keyword and return status should contain ${aaax} ${aba}
${res2}= run keyword and return status should contain ${aaaxx} ${aba}
log to console ${EMPTY}
log to console res1: ${res1}
log to console res2: ${res2}
I'm new to Node and I'm trying to write a command-line tool in Node that would allow you to pass a string in as an argument.
I saw that Node seems to break each word passed in as an array when using process.argv. I was wondering if the best way to grab the string is to loop through the array to construct the string or if there was a different option?
So let's say I have a simple program that takes a string and simply console.logs it out. It would look something like this.
> node index.js This is a sentence.
> This is a sentence.
You can surround the sentence in quotes, i.e.
> node index.js "This is a sentence."
Another option is to join the text in your program:
process.argv.shift() // skip node.exe
process.argv.shift() // skip name of js file
console.log(process.argv.join(" "))
Another solution that doesn't require quotes or modifying process.argv:
const [ node, file, ...args ] = process.argv;
const string = args.join(' ');
console.log(string);
Output:
> node index.js This is a sentence
> This is a sentence
If you want to know more about the way I've used the spread operator (...) here, read this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Rest_in_Object_Destructuring
The above answer uses excessive code!
Instead of shifting it twice use Array.prototype.splice.
// Removes elements from offset of 0
process.argv.splice(0, 2);
// Print the text as usually!
console.log(process.argv.join(' '));
Summary of the code
Remove first 2 elements from the array.
Join them using the [Backspace] delimeter.
if you are up for using npm package. Then use minimist. Become easy to deal with command line arguments. Check out their npmjs webpage for example. Hope this will help you.
var args=require('minimist')(process.argv.slice(2),{string:"name"});
console.log('Hello ' +args.name);
output is..
node app.js --name=test
Hello test
Ok, so I'm creating a Flash HUD in AS2 that runs on the Surface and connects to our server.
As it stands now, I'm having to hard code the IP addresses for the Surface to connect to, and I'm trying to get past this.
I have 4 text fields for the user to enter the 4 fields of IP address data. My issue at the moment is that if I set the String variable literally, it works fine. But if I dynamically create the string, instead of outputting on one line, it outputs each of the 4 strings separately.
Here's my code:
var newIP1 = getIP.IPtext.IP1.text; //grabbing the data from the UI
var newIP2 = getIP.IPtext.IP2.text;
var newIP3 = getIP.IPtext.IP3.text;
var newIP4 = getIP.IPtext.IP4.text;
var ipArray = new Array(newIP1,newIP2,newIP3,newIP4); //setting the array
trace (ipArray.join(".")); // output the string, replacing the commas with a period
//output:
//10
//.255
//.255
//.22
//If I do this it works fine
var IPstr = "10.255.255.2";
trace(IPstr);
// output: 10.255.255.22
I appreciate any help on this, thanks in advance.
Your code looks good and should work as expected.
One thing to check would be to see if there isn't a carriage return or newline character being added to each individual input box. One way to check would be to check the length of each of your input strings to ensure there isn't an invisible character there.