@@ -61,15 +61,15 @@ describe("csv features", function()
61
61
assert .are .same (expected , actual )
62
62
end )
63
63
64
- it (" should handle escaped doublequotes" , function ()
65
- local expected = {}
66
- expected [1 ] = {}
67
- expected [1 ].a = ' A"B""C'
68
- expected [1 ].b = ' A""B"C'
69
- expected [1 ].c = ' A"""B""C'
70
- local actual = ftcsv .parse (' a;b;c\n "A""B""""C";"A""""B""C";"A""""""B""""C"' , " ;" , {loadFromString = true })
71
- assert .are .same (expected , actual )
72
- end )
64
+ it (" should handle escaped doublequotes" , function ()
65
+ local expected = {}
66
+ expected [1 ] = {}
67
+ expected [1 ].a = ' A"B""C'
68
+ expected [1 ].b = ' A""B"C'
69
+ expected [1 ].c = ' A"""B""C'
70
+ local actual = ftcsv .parse (' a;b;c\n "A""B""""C";"A""""B""C";"A""""""B""""C"' , " ;" , {loadFromString = true })
71
+ assert .are .same (expected , actual )
72
+ end )
73
73
74
74
it (" should handle renaming a field" , function ()
75
75
local expected = {}
@@ -435,25 +435,41 @@ describe("csv features", function()
435
435
it (" should handle encoding files (str test)" , function ()
436
436
local expected = ' "a","b","c","d"\r\n "1","","foo","""quoted"""\r\n '
437
437
output = ftcsv .encode ({
438
- { a = 1 , b = ' ' , c = ' foo' , d = ' "quoted"' };
439
- }, ' ,' )
440
- assert .are .same (expected , output )
438
+ { a = 1 , b = ' ' , c = ' foo' , d = ' "quoted"' };
439
+ }, ' ,' )
440
+ assert .are .same (expected , output )
441
+ end )
442
+
443
+ it (" should handle encoding files (str test) with other delimiter" , function ()
444
+ local expected = ' "a">"b">"c">"d"\r\n "1">"">"foo">"""quoted"""\r\n '
445
+ output = ftcsv .encode ({
446
+ { a = 1 , b = ' ' , c = ' foo' , d = ' "quoted"' };
447
+ }, ' >' )
448
+ assert .are .same (expected , output )
441
449
end )
442
450
443
451
it (" should handle encoding files without quotes (str test)" , function ()
444
- local expected = ' a,b,c,d\r\n 1,,foo,"""quoted"""\r\n '
452
+ local expected = ' a,b,c,d\r\n 1,,"fo,o","""quoted"""\r\n '
453
+ output = ftcsv .encode ({
454
+ { a = 1 , b = ' ' , c = ' fo,o' , d = ' "quoted"' };
455
+ }, ' ,' , {onlyRequiredQuotes = true })
456
+ assert .are .same (expected , output )
457
+ end )
458
+
459
+ it (" should handle encoding files without quotes with other delimiter (str test)" , function ()
460
+ local expected = ' a>b>c>d\r\n 1>>fo,o>"""quoted"""\r\n '
445
461
output = ftcsv .encode ({
446
- { a = 1 , b = ' ' , c = ' foo ' , d = ' "quoted"' };
447
- }, ' , ' , {noQuotes = true })
448
- assert .are .same (expected , output )
462
+ { a = 1 , b = ' ' , c = ' fo,o ' , d = ' "quoted"' };
463
+ }, ' > ' , {onlyRequiredQuotes = true })
464
+ assert .are .same (expected , output )
449
465
end )
450
466
451
467
it (" should handle encoding files without quotes with certain fields to keep (str test)" , function ()
452
468
local expected = " b,c\r\n ,foo\r\n "
453
469
output = ftcsv .encode ({
454
- { a = 1 , b = ' ' , c = ' foo' , d = ' "quoted"' };
455
- }, ' ,' , {noQuotes = true , fieldsToKeep = {" b" , " c" }})
456
- assert .are .same (expected , output )
470
+ { a = 1 , b = ' ' , c = ' foo' , d = ' "quoted"' };
471
+ }, ' ,' , {onlyRequiredQuotes = true , fieldsToKeep = {" b" , " c" }})
472
+ assert .are .same (expected , output )
457
473
end )
458
474
459
475
it (" should handle headers attempting to escape" , function ()
0 commit comments