csv.lua: this all doesn't work with small buffer sizes. Whoops. Made tests at small buffer sizes and fixed the problem

This commit is contained in:
Geoff Leyland 2014-05-26 17:06:28 +12:00
parent c40e12bb7c
commit 13e3b69c74
2 changed files with 6 additions and 5 deletions

View File

@ -158,7 +158,7 @@ local function separated_values_iterator(file, parameters)
-- Cut the front off the buffer if we've already read it
local function truncate()
if anchor_pos > buffer_size then
local remove = math.floor(anchor_pos / buffer_size) * buffer_size
local remove = math.floor((anchor_pos-1) / buffer_size) * buffer_size
buffer = buffer:sub(remove + 1)
anchor_pos = anchor_pos - remove
line_start = line_start - remove

View File

@ -50,7 +50,7 @@ newline!
embedded
newline,embedded
newline,embedded
newline!]])
newline!]], { buffer_size=4})
test("../test-data/embedded-quotes.csv", [[
embedded "quotes",embedded "quotes",embedded "quotes"!
@ -58,17 +58,18 @@ embedded "quotes",embedded "quotes",embedded "quotes"!]])
test("../test-data/header.csv", [[
alpha:ONE,bravo:two,charlie:3!
alpha:four,bravo:five,charlie:6!]], {header=true})
alpha:four,bravo:five,charlie:6!]], {header=true, buffer_size=5})
test("../test-data/header.csv", [[
apple:one,charlie:30!
apple:four,charlie:60!]],
{ columns = {
{ buffer_size = 7,
columns = {
apple = { name = "ALPHA", transform = string.lower },
charlie = { transform = function(x) return tonumber(x) * 10 end }}})
test("../test-data/blank-line.csv", [[
this,file,ends,with,a,blank,line!]])
this,file,ends,with,a,blank,line!]], { buffer_size=11 })
if errors == 0 then