Skip to content

Commit

Permalink
Fix parser CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
BorderCloud committed May 14, 2021
1 parent 20a942c commit bcb114b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[*]
charset=utf-8
end_of_line=lf

[*.php]
trim_trailing_whitespace=true
insert_final_newline=true
indent_style=space
Expand Down
2 changes: 1 addition & 1 deletion src/ParserCSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function csvToArray($csv, $delimiter = ',', $enclosure = '\'', $es
$tabTemp = array();
// array_combine($names,$values);
foreach ($names as $key => $nameCol) {
if (isset($values[$key])) {
if (isset($values[$key]) && ! empty($values[$key])) {
$value = $values[$key];
if (strpos($value,'"')===0 || strpos($value,"'")===0){
$value = trim($value,'"');
Expand Down
17 changes: 4 additions & 13 deletions tests/ParserCsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ final class ParserCsvTest extends TestCase
public function testParserTsv()
{
//check write
$sample = <<<EOT
?s ?p ?o ?p2 ?o2
<http://example.org/s1> <http://example.org/p1> <http://example.org/s2> <http://example.org/p2> "foo"
<http://example.org/s2> <http://example.org/p2> "foo"
<http://example.org/s3> <http://example.org/p3> "bar"
<http://example.org/s4> <http://example.org/p4> 4
<http://example.org/s5> <http://example.org/p5> 5.5
<http://example.org/s6> <http://example.org/p6> _:b0
<http://example.org/s7> <http://example.org/p7> "10"
EOT;
$sample = file_get_contents (__DIR__ . "/csvtsv02.tsv");
$expected = [
0 => [
"?s" => "<http://example.org/s1>",
Expand Down Expand Up @@ -78,11 +69,11 @@ public function testParserTsv()
];
//"text/tab-separated-values; charset=utf-8":
$tabResultDataset = ParserCSV::csvToArray($sample,"\t");
$sort = false;
$sort = true;
$distinct = false;
$tabDiff = ParserCSV::compare($expected,$tabResultDataset,$sort,$distinct);
// print_r($tabDiff);
// print_r($tabResultDataset);
print_r($tabDiff);
print_r($tabResultDataset);
$this->assertTrue(count($tabDiff)==0,print_r($tabDiff,true));
}

Expand Down
8 changes: 8 additions & 0 deletions tests/csvtsv02.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
?s ?p ?o ?p2 ?o2
<http://example.org/s1> <http://example.org/p1> <http://example.org/s2> <http://example.org/p2> "foo"
<http://example.org/s2> <http://example.org/p2> "foo"
<http://example.org/s3> <http://example.org/p3> "bar"
<http://example.org/s4> <http://example.org/p4> 4
<http://example.org/s5> <http://example.org/p5> 5.5
<http://example.org/s6> <http://example.org/p6> _:b0
<http://example.org/s7> <http://example.org/p7> "10"

0 comments on commit bcb114b

Please sign in to comment.