|
|
|
@ -139,6 +139,61 @@ var PARSE_TESTS = [
@@ -139,6 +139,61 @@ var PARSE_TESTS = [
|
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Header row with one row of data", |
|
|
|
|
input: 'A,B,C\r\na,b,c', |
|
|
|
|
config: { header: true }, |
|
|
|
|
expected: { |
|
|
|
|
data: [{"A": "a", "B": "b", "C": "c"}], |
|
|
|
|
errors: [] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Header row only", |
|
|
|
|
input: 'A,B,C', |
|
|
|
|
config: { header: true }, |
|
|
|
|
expected: { |
|
|
|
|
data: [], |
|
|
|
|
errors: [] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Row with too few fields", |
|
|
|
|
input: 'A,B,C\r\na,b', |
|
|
|
|
config: { header: true }, |
|
|
|
|
expected: { |
|
|
|
|
data: [{"A": "a", "B": "b"}], |
|
|
|
|
errors: [{ |
|
|
|
|
"type": "FieldMismatch", |
|
|
|
|
"code": "TooFewFields", |
|
|
|
|
"message": "Too few fields: expected 3 fields but parsed 2", |
|
|
|
|
"row": 0 |
|
|
|
|
}] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Row with too many fields", |
|
|
|
|
input: 'A,B,C\r\na,b,c,d,e\r\nf,g,h', |
|
|
|
|
config: { header: true }, |
|
|
|
|
expected: { |
|
|
|
|
data: [{"A": "a", "B": "b", "C": "c", "__parsed_extra": ["d", "e"]}, {"A": "f", "B": "g", "C": "h"}], |
|
|
|
|
errors: [{ |
|
|
|
|
"type": "FieldMismatch", |
|
|
|
|
"code": "TooManyFields", |
|
|
|
|
"message": "Too many fields: expected 3 fields but parsed 5", |
|
|
|
|
"row": 0 |
|
|
|
|
}] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Row with enough fields but blank field at end", |
|
|
|
|
input: 'A,B,C\r\na,b,', |
|
|
|
|
config: { header: true }, |
|
|
|
|
expected: { |
|
|
|
|
data: [{"A": "a", "B": "b", "C": ""}], |
|
|
|
|
errors: [] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Tab delimiter", |
|
|
|
|
input: 'a\tb\tc\r\nd\te\tf', |
|
|
|
@ -185,6 +240,33 @@ var PARSE_TESTS = [
@@ -185,6 +240,33 @@ var PARSE_TESTS = [
|
|
|
|
|
errors: [] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Dynamic typing converts numeric literals", |
|
|
|
|
input: '1,2.2,1e3\r\n-4,-4.5,-4e-5\r\n-,5a,5-2', |
|
|
|
|
config: { dynamicTyping: true }, |
|
|
|
|
expected: { |
|
|
|
|
data: [[1, 2.2, 1000], [-4, -4.5, -0.00004], ["-", "5a", "5-2"]], |
|
|
|
|
errors: [] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Dynamic typing converts boolean literals", |
|
|
|
|
input: 'true,false,T,F,TRUE,False', |
|
|
|
|
config: { dynamicTyping: true }, |
|
|
|
|
expected: { |
|
|
|
|
data: [[true, false, "T", "F", "TRUE", "False"]], |
|
|
|
|
errors: [] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Dynamic typing doesn't convert other types", |
|
|
|
|
input: 'A,B,C\r\nundefined,null,[\r\nvar,float,if', |
|
|
|
|
config: { dynamicTyping: true }, |
|
|
|
|
expected: { |
|
|
|
|
data: [["A", "B", "C"], ["undefined", "null", "["], ["var", "float", "if"]], |
|
|
|
|
errors: [] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Commented line at beginning (comments: true)", |
|
|
|
|
input: '# Comment!\r\na,b,c', |
|
|
|
@ -205,10 +287,10 @@ var PARSE_TESTS = [
@@ -205,10 +287,10 @@ var PARSE_TESTS = [
|
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
description: "Commented line at end (comments: true)", |
|
|
|
|
input: 'a,b,c\r\n# Comment', |
|
|
|
|
input: 'a,true,false\r\n# Comment', |
|
|
|
|
config: { comments: true }, |
|
|
|
|
expected: { |
|
|
|
|
data: [['a', 'b', 'c']], |
|
|
|
|
data: [['a', 'true', 'false']], |
|
|
|
|
errors: [] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -468,6 +550,13 @@ var PARSE_TESTS = [
@@ -468,6 +550,13 @@ var PARSE_TESTS = [
|
|
|
|
|
} |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Tests for Papa.parse() that involve asynchronous operation
|
|
|
|
|
var PARSE_ASYNC_TESTS = [ |
|
|
|
|
{ |
|
|
|
|
description: "Simple worker", |
|
|
|
|