1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

add extra test for CSV with odd quotes

This commit is contained in:
Dave Conway-Jones 2016-07-05 11:51:08 +01:00
parent 82269462a4
commit b74a35b9d1

View File

@ -124,6 +124,24 @@ describe('CSV node', function() {
});
});
it('should recover from an odd number of quotes in the input', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d,e,f,g", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(csvNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
//console.log(msg);
msg.should.have.property('payload', { a: 1, b: -2, c: '+3', d: 4, e: -5, f: 'ab"cd', g: 'with,a,comma' });
done();
});
var testString = '"with,a"n,odd",num"ber,of"quotes'+String.fromCharCode(10);
n1.emit("input", {payload:testString});
testString = '"1","-2","+3","04","-05",ab""cd,"with,a,comma"'+String.fromCharCode(10);
n1.emit("input", {payload:testString});
});
});
it('should be able to use the first line as a template', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", hdrin:true, wires:[["n2"]] },
{id:"n2", type:"helper"} ];
@ -219,7 +237,7 @@ describe('CSV node', function() {
});
});
it('should convert aan array of arrays back to a multi-line csv', function(done) {
it('should convert an array of arrays back to a multi-line csv', function(done) {
var flow = [ { id:"n1", type:"csv", temp:"a,b,c,d", wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(csvNode, flow, function() {
@ -281,15 +299,15 @@ describe('CSV node', function() {
helper.load(csvNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
try {
msg.should.have.property('topic', { a: 4, b: 3, c: 2, d: 1 });
msg.should.not.have.property('payload');
n2.on("input", function(msg) {
try {
msg.should.have.property('topic', { a: 4, b: 3, c: 2, d: 1 });
msg.should.not.have.property('payload');
done();
}
catch(e) { done(e); }
});
done();
}
catch(e) { done(e); }
});
var testJson = { d: 1, b: 3, c: 2, a: 4 };
n1.emit("input", {topic:testJson});
});