• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FourierTransformer / ftcsv / 10266999296

06 Aug 2024 12:58PM UTC coverage: 98.755% (-0.4%) from 99.195%
10266999296

push

github

web-flow
Make delimiter optional and fix bug when reusing options table (#42)

113 of 120 new or added lines in 4 files covered. (94.17%)

14 existing lines in 1 file now uncovered.

1348 of 1365 relevant lines covered (98.75%)

1516.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.88
/spec/parseLine_spec.lua
1
local ftcsv = require('ftcsv')
8✔
2
local cjson = require('cjson')
8✔
3

4
local function loadFile(textFile)
5
    local file = io.open(textFile, "r")
32✔
6
    if not file then error("File not found at " .. textFile) end
24✔
7
    local allLines = file:read("*all")
24✔
8
    file:close()
24✔
9
    return allLines
24✔
10
end
11

12
describe("parseLine features small, working buffer size", function()
14✔
13
    it("should handle correctness", function()
14✔
14
        local json = loadFile("spec/json/correctness.json")
6✔
15
        json = cjson.decode(json)
6✔
16
        local parse = {}
6✔
17
        for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", ",", {bufferSize=52}) do
50✔
18
            assert.are.same(json[i], line)
60✔
19
            parse[i] = line
30✔
20
        end
21
        assert.are.same(#json, #parse)
12✔
22
        assert.are.same(json, parse)
12✔
23
    end)
24
end)
25

26
describe("parseLine features small, nonworking buffer size", function()
14✔
27
    it("should handle correctness", function()
14✔
28
        local test = function()
29
            local parse = {}
6✔
30
            for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", ",", {bufferSize=63}) do
24✔
31
                parse[i] = line
12✔
32
            end
33
            return parse
×
34
        end
35
        assert.has_error(test, "ftcsv: bufferSize needs to be larger to parse this file")
10✔
36
    end)
37
end)
38

39
describe("parseLine features smaller, nonworking buffer size", function()
14✔
40
    it("should handle correctness", function()
14✔
41
        local test = function()
42
            local parse = {}
6✔
43
            for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", ",", {bufferSize=50}) do
32✔
44
                parse[i] = line
18✔
45
            end
46
            return parse
×
47
        end
48
        assert.has_error(test, "ftcsv: bufferSize needs to be larger to parse this file")
10✔
49
    end)
50
end)
51

52
describe("smaller bufferSize than header and incorrect number of fields", function()
14✔
53
    it("should handle correctness", function()
14✔
54
        local test = function()
55
            local parse = {}
6✔
56
            for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", ",", {bufferSize=23}) do
6✔
57
                parse[i] = line
×
58
            end
59
            return parse
×
60
        end
61
        assert.has_error(test, "ftcsv: bufferSize needs to be larger to parse this file")
10✔
62
    end)
63
end)
64

65
describe("smaller bufferSize than header, but with correct field numbers", function()
14✔
66
    it("should handle correctness", function()
14✔
67
        local test = function()
68
            local parse = {}
6✔
69
            for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", ",", {bufferSize=30}) do
6✔
70
                parse[i] = line
×
71
            end
72
            return parse
×
73
        end
74
        assert.has_error(test, "ftcsv: bufferSize needs to be larger to parse this file")
10✔
75
    end)
76
end)
77

78
describe("parseLine with options but not bufferSize", function()
14✔
79
    it("should handle correctness", function()
14✔
80
        local json = loadFile("spec/json/correctness.json")
6✔
81
        json = cjson.decode(json)
6✔
82
    local parse = {}
6✔
83
    for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", ",", {rename={["Year"] = "Full Year"}}) do
50✔
84
        parse[i] = line
30✔
85
    end
86
        assert.are.same(#json, #parse)
12✔
87
    end)
88
end)
89

90
describe("parseLine features small, working buffer size without delimiter", function()
14✔
91
    it("should handle correctness", function()
14✔
92
        local json = loadFile("spec/json/correctness.json")
6✔
93
        json = cjson.decode(json)
6✔
94
        local parse = {}
6✔
95
        for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", {bufferSize=52}) do
50✔
96
            assert.are.same(json[i], line)
60✔
97
            parse[i] = line
30✔
98
        end
99
        assert.are.same(#json, #parse)
12✔
100
        assert.are.same(json, parse)
12✔
101
    end)
102
end)
103

104
describe("parseLine features small, nonworking buffer size without delimiter", function()
14✔
105
    it("should handle correctness", function()
14✔
106
        local test = function()
107
            local parse = {}
6✔
108
            for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", {bufferSize=63}) do
24✔
109
                parse[i] = line
12✔
110
            end
NEW
111
            return parse
×
112
        end
113
        assert.has_error(test, "ftcsv: bufferSize needs to be larger to parse this file")
10✔
114
    end)
115
end)
116

117
describe("parseLine features smaller, nonworking buffer size without delimiter", function()
14✔
118
    it("should handle correctness", function()
14✔
119
        local test = function()
120
            local parse = {}
6✔
121
            for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", {bufferSize=50}) do
32✔
122
                parse[i] = line
18✔
123
            end
NEW
124
            return parse
×
125
        end
126
        assert.has_error(test, "ftcsv: bufferSize needs to be larger to parse this file")
10✔
127
    end)
128
end)
129

130
describe("smaller bufferSize than header and incorrect number of fields without delimiter", function()
14✔
131
    it("should handle correctness", function()
14✔
132
        local test = function()
133
            local parse = {}
6✔
134
            for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", {bufferSize=23}) do
6✔
NEW
135
                parse[i] = line
×
136
            end
NEW
137
            return parse
×
138
        end
139
        assert.has_error(test, "ftcsv: bufferSize needs to be larger to parse this file")
10✔
140
    end)
141
end)
142

143
describe("smaller bufferSize than header, but with correct field numbers without delimiter", function()
14✔
144
    it("should handle correctness", function()
14✔
145
        local test = function()
146
            local parse = {}
6✔
147
            for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", {bufferSize=30}) do
6✔
NEW
148
                parse[i] = line
×
149
            end
NEW
150
            return parse
×
151
        end
152
        assert.has_error(test, "ftcsv: bufferSize needs to be larger to parse this file")
10✔
153
    end)
154
end)
155

156
describe("parseLine with options but not bufferSize without delimiter", function()
14✔
157
    it("should handle correctness", function()
14✔
158
        local json = loadFile("spec/json/correctness.json")
6✔
159
        json = cjson.decode(json)
6✔
160
    local parse = {}
6✔
161
    for i, line in ftcsv.parseLine("spec/csvs/correctness.csv", {rename={["Year"] = "Full Year"}}) do
50✔
162
    parse[i] = line
30✔
163
    end
164
        assert.are.same(#json, #parse)
12✔
165
    end)
166
end)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc