From e31c231dd7bec1e73b4bf1bcd6c93cf9a75f443a Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 18 Nov 2014 16:51:42 -0700 Subject: [PATCH] Test cases for fast mode; preview fix --- papaparse.js | 3 +++ tests/test-cases.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/papaparse.js b/papaparse.js index c09c133..6190844 100644 --- a/papaparse.js +++ b/papaparse.js @@ -1115,7 +1115,10 @@ else data.push(rows[i].split(delim)); if (preview && i >= preview) + { + data = data.slice(0, preview); return returnable(true); + } } return returnable(); } diff --git a/tests/test-cases.js b/tests/test-cases.js index 89650f3..e6a7123 100644 --- a/tests/test-cases.js +++ b/tests/test-cases.js @@ -343,6 +343,42 @@ var CORE_PARSER_TESTS = [ data: [['a'], ['b'], [''], [''], ['c'], ['d'], ['e'], ['']], errors: [] } + }, + { + description: "Fast mode, basic", + input: 'a,b,c\nd,e,f', + config: { fastMode: true }, + expected: { + data: [['a', 'b', 'c'], ['d', 'e', 'f']], + errors: [] + } + }, + { + description: "Fast mode with comments", + input: '// Commented line\na,b,c', + config: { fastMode: true, comments: "//" }, + expected: { + data: [['a', 'b', 'c']], + errors: [] + } + }, + { + description: "Fast mode with preview", + input: 'a,b,c\nd,e,f\nh,j,i\n', + config: { fastMode: true, preview: 2 }, + expected: { + data: [['a', 'b', 'c'], ['d', 'e', 'f']], + errors: [] + } + }, + { + description: "Fast mode with blank line at end", + input: 'a,b,c\n', + config: { fastMode: true }, + expected: { + data: [['a', 'b', 'c'], ['']], + errors: [] + } } ];