Skip to content

Commit

Permalink
Merge 7979d84 into 697856f
Browse files Browse the repository at this point in the history
  • Loading branch information
FourierTransformer committed Jan 4, 2023
2 parents 697856f + 7979d84 commit eeb5a2b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/test-and-coverage.yml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 2 additions & 2 deletions ftcsv-1.2.1-1.rockspec → ftcsv-1.2.2-1.rockspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package = "ftcsv"
version = "1.2.1-1"
version = "1.2.2-1"

source = {
url = "git://github.com/FourierTransformer/ftcsv.git",
tag = "1.2.1"
tag = "1.2.2"
}

description = {
Expand Down
24 changes: 17 additions & 7 deletions ftcsv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,16 @@ local function parseOptions(delimiter, options, fromParseLine)
local fieldsToKeep = nil

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) .. "'.")
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) .. "'.")
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) .. "'.")
local ofieldsToKeep = options.fieldsToKeep
if ofieldsToKeep ~= nil then
Expand All @@ -422,23 +425,30 @@ local function parseOptions(delimiter, options, fromParseLine)
error("ftcsv: fieldsToKeep only works with header-less files when using the 'rename' functionality")
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) .. "'.")
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) .. "'.")
end
if options.ignoreQuotes == nil then

if options.ignoreQuotes == nil then
options.ignoreQuotes = false
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) .. "'.")
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) .. "'.")
if fromParseLine == false then
error("ftcsv: bufferSize can only be specified using 'parseLine'. When using 'parse', the entire file is read into memory")
end
end

else
options = {
["headers"] = true,
Expand Down
12 changes: 12 additions & 0 deletions spec/parseLine_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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)

0 comments on commit eeb5a2b

Please sign in to comment.