summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it_pipe.class2
-rwxr-xr-xtest/it_pipe.t2
2 files changed, 3 insertions, 1 deletions
diff --git a/it_pipe.class b/it_pipe.class
index 2fe93db..94801c3 100644
--- a/it_pipe.class
+++ b/it_pipe.class
@@ -182,7 +182,7 @@ function cols($collist, $separator = "\t")
$this->lines[$idx] = (object)array_combine($keys, $arr);
else
{
- unset($this->lines[$idx]);
+ $this->lines[$idx] = (object)[];
foreach ($keys as $i => $key)
$this->lines[$idx]->$key = $arr[$i];
}
diff --git a/test/it_pipe.t b/test/it_pipe.t
index 16e2c29..a3cebd6 100755
--- a/test/it_pipe.t
+++ b/test/it_pipe.t
@@ -10,6 +10,8 @@ is(json_encode((new it_pipe(['data' => ["a\tb", "1\t2"]]))->csv("c,d")), '[{"c":
is(json_encode((new it_pipe(['data' => ["a\tb", "1\t2"]]))->csv(['forceschema' => "c,d"])), '[{"c":"1","d":"2"}]');
is(json_encode((new it_pipe(['data' => ["a b\tb", "1\t2"]]))->csv(['fixcolnames' => true])), '[{"a_b":"1","b":"2"}]');
+is(iterator_to_array((new it_pipe(['data' => ["a b\tb", "1\t2"]]))->cols('c')), [(object)['c' => 'a b'], (object)['c' => '1']], "cols() ignoring some columns");
+
# askey()
is(json_encode((new it_pipe(['data' => "a\nb\n"]))->askey()), '{"a":true,"b":true}');