Skip to content

Commit

Permalink
removed unneccessary code and added some more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FourierTransformer committed Apr 16, 2019
1 parent 255e63c commit aff9327
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ftcsv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ else
if j == nil then
return nil
end
if i == nil then
return inputLength-1, doubleQuoteEscape
end
difference = j - i
if difference >= 1 then doubleQuoteEscape = true end
if difference == 1 then
Expand Down Expand Up @@ -285,9 +282,14 @@ local function parseString(inputString, i, options)

-- in buffered mode and it can't find the closing quote
-- it usually means in the middle of a buffer and need to backtrack
if i == nil and buffered then
outResults[lineNum] = nil
return outResults, lineStart
if i == nil then
if buffered then
outResults[lineNum] = nil
return outResults, lineStart
else
error("ftcsv: can't find closing quote in row " .. options.rowOffset + lineNum ..
". Try running with the option ignoreQuotes=true if the source incorrectly uses quotes.")
end
end

-- Increment Counter
Expand Down
7 changes: 7 additions & 0 deletions spec/error_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ describe("parseLine features small, nonworking buffer size", function()
assert.has_error(test, "ftcsv: parseLine currently doesn't support loading from string")
end)
end)

it("should error when dealing with quotes", function()
local test = function()
local actual = ftcsv.parse('a,b,c\n"apple,banana,carrot', ",", {loadFromString=true})
end
assert.has_error(test, "ftcsv: can't find closing quote in row 1. Try running with the option ignoreQuotes=true if the source incorrectly uses quotes.")
end)
10 changes: 10 additions & 0 deletions spec/feature_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,14 @@ describe("csv features", function()
assert.are.same(expected, actual)
end)

it("should handle ignoring the single quote", function()
local expected = {}
expected[1] = {}
expected[1].a = '"apple'
expected[1].b = "banana"
expected[1].c = "carrot"
local actual = ftcsv.parse('a,b,c\n"apple,banana,carrot', ",", {loadFromString=true, ignoreQuotes=true})
assert.are.same(expected, actual)
end)

end)

0 comments on commit aff9327

Please sign in to comment.