Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing with a metaoperator doesn't print the test description

Tags:

testing

raku

I was writing tests on Complex arrays and I was using the Z≅ operator to check whether the arrays were approximately equal, when I noticed a missing test description.
I tried to golf the piece of code to find out the simplest case that shows the result I was seeing. The description is missing in the second test even when I use Num or Int variables and the Z== operator.

use Test;

my @a = 1e0, 3e0;
my @b = 1e0, 3e0;
ok @a[0] == @b[0], 'description1';     # prints: ok 1 - description1
ok @a[^2] Z== @b[^2], 'description2';  # prints: ok 2 -

done-testing;

Is there a simple explanation or is this a bug?

like image 200
Fernando Santagata Avatar asked Mar 29 '20 16:03

Fernando Santagata


1 Answers

It's just precedence -- you need parens.

== is a binary op that takes a single operand on either side.

The Z metaop distributes its operator to a list on either side.

use Test;

my @a = 1e0, 3e0;
my @b = 1e0, 3e0;
ok  @a[0]   == @b[0],   'description1';  # prints: ok 1 - description1
ok (@a[^2] Z== @b[^2]), 'description2';  # prints: ok 2 - description2

done-testing;

Without parens, 'description2' becomes an additional element of the list on the right. And per the doc for Z:

If one of the operands runs out of elements prematurely, the zip operator will stop.

like image 162
raiph Avatar answered Nov 04 '22 21:11

raiph