On Fri, 16 Dec 2016 12:40:05 -0800, TimTom wrote:
> The is-deeply operator does not appear to pick up custom infix eqv
> variants.  I can see on line 567 of rakudo/lib/Test.pm6 that
> _is_deeply is using infix:<eqv>, but it doesn't pick up the custom
> variant.  I attempted exporting the operator and moving the use Test
> below the multi declaration, but it didn't make any difference (I
> didn't expect it to, but didn't hurt to try).
> 
> 
> use v6;
> use Test;
> 
> class Custom-Equality {
>     has $.a;
>     has $.b;
> }
> 
> # Define a custom equivalence operator that equates the opposite
> properties
> # instead of the same properties.
> multi infix:<eqv>(Custom-Equality $l, Custom-Equality $r) {
>     return !$r.defined unless $l.defined;
>     return $r.defined && $l.a eqv $r.b && $l.b eqv $r.a;
> }
> 
> my Custom-Equality $x .= new(:a<cat>, :b<dog>);
> my Custom-Equality $y .= new(:a<dog>, :b<cat>);
> 
> ok($x eqv $y, 'x is equivalent to y'); # Passes
> is-deeply($x, $y, 'x is deeply y'); # Fails

Thank you for the report. However, this is not a bug.

What is-deeply uses under the hood is secret and you should not be
relying on it. I noticed our documentation was worded in a way that may
make one think what you're doing should work. I have now reworded it[1].

As for the reason why it doesn't work, it's because your infix:<eqv> routine is
not in lexical scope of is-deeply. In other words, defining an operator does not
make it available in the entire program. The behaviour is the same as it would
be with any other routine.

[1] https://github.com/perl6/doc/commit/f705a6fe000b1daca8577c7e7b8c93f62928fe05

Cheers,
ZZ

Reply via email to