|
|
@ -13,15 +13,13 @@ var FILES_ENABLED = false; |
|
|
|
try { |
|
|
|
try { |
|
|
|
new File([""], ""); // eslint-disable-line no-new
|
|
|
|
new File([""], ""); // eslint-disable-line no-new
|
|
|
|
FILES_ENABLED = true; |
|
|
|
FILES_ENABLED = true; |
|
|
|
} catch (e) { |
|
|
|
} catch (e) {} // safari, ie
|
|
|
|
} // safari, ie
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var XHR_ENABLED = false; |
|
|
|
var XHR_ENABLED = false; |
|
|
|
try { |
|
|
|
try { |
|
|
|
new XMLHttpRequest(); // eslint-disable-line no-new
|
|
|
|
new XMLHttpRequest(); // eslint-disable-line no-new
|
|
|
|
XHR_ENABLED = true; |
|
|
|
XHR_ENABLED = true; |
|
|
|
} catch (e) { |
|
|
|
} catch (e) {} // safari, ie
|
|
|
|
} // safari, ie
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tests for the core parser using new Papa.Parser().parse() (CSV to JSON)
|
|
|
|
// Tests for the core parser using new Papa.Parser().parse() (CSV to JSON)
|
|
|
|
var CORE_PARSER_TESTS = [ |
|
|
|
var CORE_PARSER_TESTS = [ |
|
|
@ -417,14 +415,6 @@ var CORE_PARSER_TESTS = [ |
|
|
|
errors: [] |
|
|
|
errors: [] |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
|
|
|
|
description: "Pipes with decimal numbers and comma as decimal separator", |
|
|
|
|
|
|
|
input: 'a|3,4|b\r\nc|3,4|d', |
|
|
|
|
|
|
|
expected: { |
|
|
|
|
|
|
|
data: [['a', '3,4', 'b'], ['c', '3,4', 'd']], |
|
|
|
|
|
|
|
errors: [] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
description: "Commented line at end", |
|
|
|
description: "Commented line at end", |
|
|
|
input: 'a,true,false\n# Comment', |
|
|
|
input: 'a,true,false\n# Comment', |
|
|
@ -604,6 +594,7 @@ describe('Core Parser Tests', function () { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tests for Papa.parse() function -- high-level wrapped parser (CSV to JSON)
|
|
|
|
// Tests for Papa.parse() function -- high-level wrapped parser (CSV to JSON)
|
|
|
|
var PARSE_TESTS = [ |
|
|
|
var PARSE_TESTS = [ |
|
|
|
{ |
|
|
|
{ |
|
|
@ -816,11 +807,7 @@ var PARSE_TESTS = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
description: "Callback delimiter", |
|
|
|
description: "Callback delimiter", |
|
|
|
input: 'a$ b$ c', |
|
|
|
input: 'a$ b$ c', |
|
|
|
config: { |
|
|
|
config: { delimiter: function(input) { return input[1] + ' '; } }, |
|
|
|
delimiter: function (input) { |
|
|
|
|
|
|
|
return input[1] + ' '; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
expected: { |
|
|
|
expected: { |
|
|
|
data: [['a', 'b', 'c']], |
|
|
|
data: [['a', 'b', 'c']], |
|
|
|
errors: [] |
|
|
|
errors: [] |
|
|
@ -888,11 +875,7 @@ var PARSE_TESTS = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
description: "Dynamic typing by indices can be determined by function", |
|
|
|
description: "Dynamic typing by indices can be determined by function", |
|
|
|
input: '001,002,003', |
|
|
|
input: '001,002,003', |
|
|
|
config: { |
|
|
|
config: { dynamicTyping: function(field) { return (field % 2) === 0; } }, |
|
|
|
dynamicTyping: function (field) { |
|
|
|
|
|
|
|
return (field % 2) === 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
expected: { |
|
|
|
expected: { |
|
|
|
data: [[1, "002", 3]], |
|
|
|
data: [[1, "002", 3]], |
|
|
|
errors: [] |
|
|
|
errors: [] |
|
|
@ -901,11 +884,7 @@ var PARSE_TESTS = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
description: "Dynamic typing by headers can be determined by function", |
|
|
|
description: "Dynamic typing by headers can be determined by function", |
|
|
|
input: 'A_as_int,B,C_as_int\r\n001,002,003', |
|
|
|
input: 'A_as_int,B,C_as_int\r\n001,002,003', |
|
|
|
config: { |
|
|
|
config: { header: true, dynamicTyping: function(field) { return /_as_int$/.test(field); } }, |
|
|
|
header: true, dynamicTyping: function (field) { |
|
|
|
|
|
|
|
return /_as_int$/.test(field); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
expected: { |
|
|
|
expected: { |
|
|
|
data: [{"A_as_int": 1, "B": "002", "C_as_int": 3}], |
|
|
|
data: [{"A_as_int": 1, "B": "002", "C_as_int": 3}], |
|
|
|
errors: [] |
|
|
|
errors: [] |
|
|
@ -1401,6 +1380,7 @@ describe('Parse Tests', function () { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tests for Papa.parse() that involve asynchronous operation
|
|
|
|
// Tests for Papa.parse() that involve asynchronous operation
|
|
|
|
var PARSE_ASYNC_TESTS = [ |
|
|
|
var PARSE_ASYNC_TESTS = [ |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1443,7 +1423,8 @@ var PARSE_ASYNC_TESTS = [ |
|
|
|
description: "Simple file", |
|
|
|
description: "Simple file", |
|
|
|
disabled: !FILES_ENABLED, |
|
|
|
disabled: !FILES_ENABLED, |
|
|
|
input: FILES_ENABLED ? new File(["A,B,C\nX,Y,Z"], "sample.csv") : false, |
|
|
|
input: FILES_ENABLED ? new File(["A,B,C\nX,Y,Z"], "sample.csv") : false, |
|
|
|
config: {}, |
|
|
|
config: { |
|
|
|
|
|
|
|
}, |
|
|
|
expected: { |
|
|
|
expected: { |
|
|
|
data: [['A','B','C'],['X','Y','Z']], |
|
|
|
data: [['A','B','C'],['X','Y','Z']], |
|
|
|
errors: [] |
|
|
|
errors: [] |
|
|
@ -1488,6 +1469,7 @@ describe('Parse Async Tests', function () { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tests for Papa.unparse() function (JSON to CSV)
|
|
|
|
// Tests for Papa.unparse() function (JSON to CSV)
|
|
|
|
var UNPARSE_TESTS = [ |
|
|
|
var UNPARSE_TESTS = [ |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1587,6 +1569,14 @@ var UNPARSE_TESTS = [ |
|
|
|
config: { newline: '\r' }, |
|
|
|
config: { newline: '\r' }, |
|
|
|
expected: 'a,b,c\rd,e,f' |
|
|
|
expected: 'a,b,c\rd,e,f' |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
description:"Pipes with decimal numbers and comma as decimal separator", |
|
|
|
|
|
|
|
input:'a|3,4|b\r\nc|3,4|d', |
|
|
|
|
|
|
|
expected:{ |
|
|
|
|
|
|
|
data:[['a','3,4','b'],['c','3,4','d']], |
|
|
|
|
|
|
|
errors:[] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
description: "Custom line ending (\\n)", |
|
|
|
description: "Custom line ending (\\n)", |
|
|
|
input: [['a', 'b', 'c'], ['d', 'e', 'f']], |
|
|
|
input: [['a', 'b', 'c'], ['d', 'e', 'f']], |
|
|
@ -1652,11 +1642,44 @@ var UNPARSE_TESTS = [ |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
description: "Date objects are exported in its ISO representation", |
|
|
|
description: "Date objects are exported in its ISO representation", |
|
|
|
input: [{ |
|
|
|
input: [{date: new Date("2018-05-04T21:08:03.269Z"), "not a date": 16}, {date: new Date("Tue May 08 2018 08:20:22 GMT-0700 (PDT)"), "not a date": 32}], |
|
|
|
date: new Date("2018-05-04T21:08:03.269Z"), |
|
|
|
|
|
|
|
"not a date": 16 |
|
|
|
|
|
|
|
}, {date: new Date("Tue May 08 2018 08:20:22 GMT-0700 (PDT)"), "not a date": 32}], |
|
|
|
|
|
|
|
expected: 'date,not a date\r\n2018-05-04T21:08:03.269Z,16\r\n2018-05-08T15:20:22.000Z,32' |
|
|
|
expected: 'date,not a date\r\n2018-05-04T21:08:03.269Z,16\r\n2018-05-08T15:20:22.000Z,32' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
description: "Returns empty rows when empty rows are passed and skipEmptyLines is false", |
|
|
|
|
|
|
|
input: [[null, ' '], [], ['1', '2']], |
|
|
|
|
|
|
|
config: {skipEmptyLines: false}, |
|
|
|
|
|
|
|
expected: '," "\r\n\r\n1,2' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
description: "Returns without empty rows when skipEmptyLines is true", |
|
|
|
|
|
|
|
input: [[null, ' '], [], ['1', '2']], |
|
|
|
|
|
|
|
config: {skipEmptyLines: true}, |
|
|
|
|
|
|
|
expected: '," "\r\n1,2' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
description: "Returns without rows with no content when skipEmptyLines is 'greedy'", |
|
|
|
|
|
|
|
input: [[null, ' '], [], ['1', '2']], |
|
|
|
|
|
|
|
config: {skipEmptyLines: 'greedy'}, |
|
|
|
|
|
|
|
expected: '1,2' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
description: "Returns empty rows when empty rows are passed and skipEmptyLines is false with headers", |
|
|
|
|
|
|
|
input: [{a: null, b: ' '}, {}, {a: '1', b: '2'}], |
|
|
|
|
|
|
|
config: {skipEmptyLines: false, header: true}, |
|
|
|
|
|
|
|
expected: 'a,b\r\n," "\r\n\r\n1,2' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
description: "Returns without empty rows when skipEmptyLines is true with headers", |
|
|
|
|
|
|
|
input: [{a: null, b: ' '}, {}, {a: '1', b: '2'}], |
|
|
|
|
|
|
|
config: {skipEmptyLines: true, header: true}, |
|
|
|
|
|
|
|
expected: 'a,b\r\n," "\r\n1,2' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
description: "Returns without rows with no content when skipEmptyLines is 'greedy' with headers", |
|
|
|
|
|
|
|
input: [{a: null, b: ' '}, {}, {a: '1', b: '2'}], |
|
|
|
|
|
|
|
config: {skipEmptyLines: 'greedy', header: true}, |
|
|
|
|
|
|
|
expected: 'a,b\r\n1,2' |
|
|
|
} |
|
|
|
} |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
@ -1684,6 +1707,7 @@ describe('Unparse Tests', function () { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var CUSTOM_TESTS = [ |
|
|
|
var CUSTOM_TESTS = [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
description: "Complete is called with all results if neither step nor chunk is defined", |
|
|
|
description: "Complete is called with all results if neither step nor chunk is defined", |
|
|
@ -2093,16 +2117,12 @@ var CUSTOM_TESTS = [ |
|
|
|
'?x=1&papaworker&y=1', |
|
|
|
'?x=1&papaworker&y=1', |
|
|
|
'?x=1&papaworker=1' |
|
|
|
'?x=1&papaworker=1' |
|
|
|
]; |
|
|
|
]; |
|
|
|
var results = searchStrings.map(function () { |
|
|
|
var results = searchStrings.map(function() { return false; }); |
|
|
|
return false; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
var workers = []; |
|
|
|
var workers = []; |
|
|
|
|
|
|
|
|
|
|
|
// Give it .5s to do something
|
|
|
|
// Give it .5s to do something
|
|
|
|
setTimeout(function() { |
|
|
|
setTimeout(function() { |
|
|
|
workers.forEach(function (w) { |
|
|
|
workers.forEach(function(w) { w.terminate(); }); |
|
|
|
w.terminate(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
callback(results); |
|
|
|
callback(results); |
|
|
|
}, 500); |
|
|
|
}, 500); |
|
|
|
|
|
|
|
|
|
|
|