mirror of
https://github.com/FourierTransformer/ftcsv.git
synced 2024-11-19 19:54:23 +00:00
Fixed bufferSize default bug with options present and new release (#29)
This commit is contained in:
parent
697856f0c2
commit
49bf0e7e28
42
.github/workflows/test-and-coverage.yml
vendored
Normal file
42
.github/workflows/test-and-coverage.yml
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
name: Run Tests and Code Coverage
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
tags: [ '*.*.*' ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
|
||||||
|
- name: Setup ‘lua’
|
||||||
|
uses: leafo/gh-actions-lua@v9
|
||||||
|
with:
|
||||||
|
luaVersion: ${{ matrix.luaVersion }}
|
||||||
|
- name: Setup ‘luarocks’
|
||||||
|
uses: leafo/gh-actions-luarocks@v4
|
||||||
|
|
||||||
|
- name: install depedencies
|
||||||
|
run: |
|
||||||
|
luarocks install busted
|
||||||
|
luarocks install lua-cjson
|
||||||
|
luarocks install luacov
|
||||||
|
luarocks install luacov-coveralls
|
||||||
|
|
||||||
|
|
||||||
|
- name: run unit tests with coverage
|
||||||
|
run: busted --verbose --coverage
|
||||||
|
|
||||||
|
- name: Report test coverage
|
||||||
|
if: success()
|
||||||
|
continue-on-error: true
|
||||||
|
run: luacov-coveralls -e .luarocks
|
||||||
|
env:
|
||||||
|
COVERALLS_REPO_TOKEN: ${{ github.token }}
|
@ -1,5 +1,5 @@
|
|||||||
# ftcsv
|
# ftcsv
|
||||||
[![Build Status](https://travis-ci.org/FourierTransformer/ftcsv.svg?branch=master)](https://travis-ci.org/FourierTransformer/ftcsv) [![Coverage Status](https://coveralls.io/repos/github/FourierTransformer/ftcsv/badge.svg?branch=master)](https://coveralls.io/github/FourierTransformer/ftcsv?branch=master)
|
[![Run Tests and Code Coverage](https://github.com/FourierTransformer/ftcsv/actions/workflows/test-and-coverage.yml/badge.svg)](https://github.com/FourierTransformer/ftcsv/actions/workflows/test-and-coverage.yml) [![Coverage Status](https://coveralls.io/repos/github/FourierTransformer/ftcsv/badge.svg?branch=master)](https://coveralls.io/github/FourierTransformer/ftcsv?branch=master)
|
||||||
|
|
||||||
ftcsv is a fast csv library written in pure Lua. It's been tested with LuaJIT 2.0/2.1 and Lua 5.1, 5.2, 5.3, and 5.4
|
ftcsv is a fast csv library written in pure Lua. It's been tested with LuaJIT 2.0/2.1 and Lua 5.1, 5.2, 5.3, and 5.4
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package = "ftcsv"
|
package = "ftcsv"
|
||||||
version = "1.2.1-1"
|
version = "1.2.2-1"
|
||||||
|
|
||||||
source = {
|
source = {
|
||||||
url = "git://github.com/FourierTransformer/ftcsv.git",
|
url = "git://github.com/FourierTransformer/ftcsv.git",
|
||||||
tag = "1.2.1"
|
tag = "1.2.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
description = {
|
description = {
|
24
ftcsv.lua
24
ftcsv.lua
@ -403,13 +403,16 @@ local function parseOptions(delimiter, options, fromParseLine)
|
|||||||
local fieldsToKeep = nil
|
local fieldsToKeep = nil
|
||||||
|
|
||||||
if options then
|
if options then
|
||||||
if options.headers ~= nil then
|
|
||||||
|
if options.headers ~= nil then
|
||||||
assert(type(options.headers) == "boolean", "ftcsv only takes the boolean 'true' or 'false' for the optional parameter 'headers' (default 'true'). You passed in '" .. tostring(options.headers) .. "' of type '" .. type(options.headers) .. "'.")
|
assert(type(options.headers) == "boolean", "ftcsv only takes the boolean 'true' or 'false' for the optional parameter 'headers' (default 'true'). You passed in '" .. tostring(options.headers) .. "' of type '" .. type(options.headers) .. "'.")
|
||||||
end
|
end
|
||||||
if options.rename ~= nil then
|
|
||||||
|
if options.rename ~= nil then
|
||||||
assert(type(options.rename) == "table", "ftcsv only takes in a key-value table for the optional parameter 'rename'. You passed in '" .. tostring(options.rename) .. "' of type '" .. type(options.rename) .. "'.")
|
assert(type(options.rename) == "table", "ftcsv only takes in a key-value table for the optional parameter 'rename'. You passed in '" .. tostring(options.rename) .. "' of type '" .. type(options.rename) .. "'.")
|
||||||
end
|
end
|
||||||
if options.fieldsToKeep ~= nil then
|
|
||||||
|
if options.fieldsToKeep ~= nil then
|
||||||
assert(type(options.fieldsToKeep) == "table", "ftcsv only takes in a list (as a table) for the optional parameter 'fieldsToKeep'. You passed in '" .. tostring(options.fieldsToKeep) .. "' of type '" .. type(options.fieldsToKeep) .. "'.")
|
assert(type(options.fieldsToKeep) == "table", "ftcsv only takes in a list (as a table) for the optional parameter 'fieldsToKeep'. You passed in '" .. tostring(options.fieldsToKeep) .. "' of type '" .. type(options.fieldsToKeep) .. "'.")
|
||||||
local ofieldsToKeep = options.fieldsToKeep
|
local ofieldsToKeep = options.fieldsToKeep
|
||||||
if ofieldsToKeep ~= nil then
|
if ofieldsToKeep ~= nil then
|
||||||
@ -422,23 +425,30 @@ local function parseOptions(delimiter, options, fromParseLine)
|
|||||||
error("ftcsv: fieldsToKeep only works with header-less files when using the 'rename' functionality")
|
error("ftcsv: fieldsToKeep only works with header-less files when using the 'rename' functionality")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if options.loadFromString ~= nil then
|
|
||||||
|
if options.loadFromString ~= nil then
|
||||||
assert(type(options.loadFromString) == "boolean", "ftcsv only takes a boolean value for optional parameter 'loadFromString'. You passed in '" .. tostring(options.loadFromString) .. "' of type '" .. type(options.loadFromString) .. "'.")
|
assert(type(options.loadFromString) == "boolean", "ftcsv only takes a boolean value for optional parameter 'loadFromString'. You passed in '" .. tostring(options.loadFromString) .. "' of type '" .. type(options.loadFromString) .. "'.")
|
||||||
end
|
end
|
||||||
if options.headerFunc ~= nil then
|
|
||||||
|
if options.headerFunc ~= nil then
|
||||||
assert(type(options.headerFunc) == "function", "ftcsv only takes a function value for optional parameter 'headerFunc'. You passed in '" .. tostring(options.headerFunc) .. "' of type '" .. type(options.headerFunc) .. "'.")
|
assert(type(options.headerFunc) == "function", "ftcsv only takes a function value for optional parameter 'headerFunc'. You passed in '" .. tostring(options.headerFunc) .. "' of type '" .. type(options.headerFunc) .. "'.")
|
||||||
end
|
end
|
||||||
if options.ignoreQuotes == nil then
|
|
||||||
|
if options.ignoreQuotes == nil then
|
||||||
options.ignoreQuotes = false
|
options.ignoreQuotes = false
|
||||||
else
|
else
|
||||||
assert(type(options.ignoreQuotes) == "boolean", "ftcsv only takes a boolean value for optional parameter 'ignoreQuotes'. You passed in '" .. tostring(options.ignoreQuotes) .. "' of type '" .. type(options.ignoreQuotes) .. "'.")
|
assert(type(options.ignoreQuotes) == "boolean", "ftcsv only takes a boolean value for optional parameter 'ignoreQuotes'. You passed in '" .. tostring(options.ignoreQuotes) .. "' of type '" .. type(options.ignoreQuotes) .. "'.")
|
||||||
end
|
end
|
||||||
if options.bufferSize ~= nil then
|
|
||||||
|
if options.bufferSize == nil then
|
||||||
|
options.bufferSize = 2^16
|
||||||
|
else
|
||||||
assert(type(options.bufferSize) == "number", "ftcsv only takes a number value for optional parameter 'bufferSize'. You passed in '" .. tostring(options.bufferSize) .. "' of type '" .. type(options.bufferSize) .. "'.")
|
assert(type(options.bufferSize) == "number", "ftcsv only takes a number value for optional parameter 'bufferSize'. You passed in '" .. tostring(options.bufferSize) .. "' of type '" .. type(options.bufferSize) .. "'.")
|
||||||
if fromParseLine == false then
|
if fromParseLine == false then
|
||||||
error("ftcsv: bufferSize can only be specified using 'parseLine'. When using 'parse', the entire file is read into memory")
|
error("ftcsv: bufferSize can only be specified using 'parseLine'. When using 'parse', the entire file is read into memory")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
options = {
|
options = {
|
||||||
["headers"] = true,
|
["headers"] = true,
|
||||||
|
@ -74,3 +74,15 @@ describe("smaller bufferSize than header, but with correct field numbers", funct
|
|||||||
assert.has_error(test, "ftcsv: bufferSize needs to be larger to parse this file")
|
assert.has_error(test, "ftcsv: bufferSize needs to be larger to parse this file")
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe("parseLine with options but not bufferSize", function()
|
||||||
|
it("should handle correctness", function()
|
||||||
|
local json = loadFile("spec/json/correctness.json")
|
||||||
|
json = cjson.decode(json)
|
||||||
|
local parse = {}
|
||||||
|
for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", ",", {rename={["Year"] = "Full Year"}}) do
|
||||||
|
parse[i] = line
|
||||||
|
end
|
||||||
|
assert.are.same(#json, #parse)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user