Skip to content

Commit e2ac897

Browse files
authored
Merge pull request #24 from keboola/odin-escapedby
tests: add tests for escaped by parameter, fixes #23
2 parents 57884d5 + d0d9e2b commit e2ac897

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/CsvFileTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,39 @@ public function testParse()
101101
self::assertEquals($expected, $rows);
102102
}
103103

104+
public function testParseEscapedBy()
105+
{
106+
$csvFile = new CsvFile(__DIR__ . '/data/escapingEscapedBy.csv', ",", '"', '\\');
107+
108+
$expected = [
109+
[
110+
'col1', 'col2',
111+
],
112+
[
113+
'line without enclosure', 'second column',
114+
],
115+
[
116+
'enclosure \" in column', 'hello \\\\',
117+
],
118+
[
119+
'line with enclosure', 'second column',
120+
],
121+
[
122+
'column with enclosure \", and comma inside text', 'second column enclosure in text \"',
123+
],
124+
[
125+
"columns with\nnew line", "columns with\ttab",
126+
],
127+
[
128+
"Columns with WINDOWS\r\nnew line", "second",
129+
],
130+
[
131+
'column with \n \t \\\\', 'second col',
132+
],
133+
];
134+
135+
self::assertEquals($expected, iterator_to_array($csvFile));
136+
}
104137

105138
public function testEmptyHeader()
106139
{

tests/data/escapingEscapedBy.csv

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
col1,col2
2+
line without enclosure,second column
3+
"enclosure \" in column","hello \\"
4+
"line with enclosure","second column"
5+
"column with enclosure \", and comma inside text","second column enclosure in text \""
6+
"columns with
7+
new line","columns with tab"
8+
"Columns with WINDOWS
9+
new line", "second"
10+
"column with \n \t \\","second col"

0 commit comments

Comments
 (0)