Skip to content

Commit

Permalink
Fixed toString in case of same keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
Athari committed Jan 11, 2016
1 parent bf1e9f9 commit 339871d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Tests/Unit/EnumerableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2533,6 +2533,9 @@ function testToString ()
$this->assertEquals(
'123',
E::from([ 1, 'a' => 2, 3 ])->toString());
$this->assertEquals(
'123',
E::from([ [ 0, 1 ], [ 0, 2 ], [ 1, 3 ] ])->select('$v[1]', '$v[0]')->toString());

// toString (separator)
$this->assertEquals(
Expand All @@ -2544,6 +2547,9 @@ function testToString ()
$this->assertEquals(
'1, 2, 3',
E::from([ 1, 'a' => 2, 3 ])->toString(', '));
$this->assertEquals(
'1, 2, 3',
E::from([ [ 0, 1 ], [ 0, 2 ], [ 1, 3 ] ])->select('$v[1]', '$v[0]')->toString(', '));

// toString (separator, selector)
$this->assertEquals(
Expand All @@ -2555,6 +2561,9 @@ function testToString ()
$this->assertEquals(
'0=1, a=2, 1=3',
E::from([ 1, 'a' => 2, 3 ])->toString(', ', '"$k=$v"'));
$this->assertEquals(
'0=1, 0=2, 1=3',
E::from([ [ 0, 1 ], [ 0, 2 ], [ 1, 3 ] ])->select('$v[1]', '$v[0]')->toString(', ', '"$k=$v"'));
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion YaLinqo/Enumerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ public function toObject ($propertySelector = null, $valueSelector = null)
public function toString ($separator = '', $valueSelector = null)
{
$valueSelector = Utils::createLambda($valueSelector, 'v,k', false);
$array = $valueSelector ? $this->select($valueSelector)->toArray() : $this->toArray();
$array = $valueSelector ? $this->select($valueSelector)->toList() : $this->toList();
return implode($separator, $array);
}

Expand Down

0 comments on commit 339871d

Please sign in to comment.