@@ -163,4 +163,37 @@ describe("csv features", function()
163
163
assert .are .same (expected , actual )
164
164
end )
165
165
166
+ it (" should handle encoding files" , function ()
167
+ local expected = {}
168
+ expected [1 ] = {}
169
+ expected [1 ].A = " apple"
170
+ expected [1 ].B = " banana"
171
+ expected [1 ].C = " carrot"
172
+ local actual = ftcsv .parse (ftcsv .encode (expected , " ," ), " ," , {loadFromString = true })
173
+ local expected = ftcsv .parse (" A,B,C\n apple,banana,carrot" , " ," , {loadFromString = true })
174
+ assert .are .same (expected , actual )
175
+ end )
176
+
177
+ it (" should handle encoding files with odd delimiters" , function ()
178
+ local expected = {}
179
+ expected [1 ] = {}
180
+ expected [1 ].A = " apple"
181
+ expected [1 ].B = " banana"
182
+ expected [1 ].C = " carrot"
183
+ local actual = ftcsv .parse (ftcsv .encode (expected , " >" ), " >" , {loadFromString = true })
184
+ local expected = ftcsv .parse (" A,B,C\n apple,banana,carrot" , " ," , {loadFromString = true })
185
+ assert .are .same (expected , actual )
186
+ end )
187
+
188
+ it (" should handle encoding files with only certain fields to keep" , function ()
189
+ local expected = {}
190
+ expected [1 ] = {}
191
+ expected [1 ].A = " apple"
192
+ expected [1 ].B = " banana"
193
+ expected [1 ].C = " carrot"
194
+ local actual = ftcsv .parse (ftcsv .encode (expected , " ," , {fieldsToKeep = {" A" , " B" }}), " ," , {loadFromString = true })
195
+ local expected = ftcsv .parse (" A,B\n apple,banana" , " ," , {loadFromString = true })
196
+ assert .are .same (expected , actual )
197
+ end )
198
+
166
199
end )
0 commit comments