ddnrnboobaql / hamcrest

Automatically exported from code.google.com/p/hamcrest
0 stars 0 forks source link

Arrays should show non-index keys (0, 1, 2, ...) in output #142

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This test fails as it should.

    $keyed = array(1 => 'foo', 2 => 'bar');
    $indexed = array('foo', 'bar');
    assertThat($keyed, is($indexed));

But the error message is misleading.

    Expected: is ["foo", "bar"]
         but: was ["foo", "bar"]

If the keys are not standard numeric indexes they should be output in the 
display. The above should show as

    Expected: is ["foo", "bar"]
         but: was [1 => "foo", 2 => "bar"]

Note that equality (==) for arrays

* compares keys,
* treats indexes as standard keys, and
* ignores insertion order even though var_dump() shows it.

Identity (===) for arrays doesn't ignore insertion order but behaves like == 
otherwise.

Original issue reported on code.google.com by dharkn...@gmail.com on 15 Mar 2011 at 5:29