Skip to content

Instantly share code, notes, and snippets.

@0racle
Last active April 26, 2016 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0racle/0111368074fe2ddec228b2ea436bfdde to your computer and use it in GitHub Desktop.
Save 0racle/0111368074fe2ddec228b2ea436bfdde to your computer and use it in GitHub Desktop.
Listy eqv
use Test;

plan 22;

sub infix:<Meqv> { @^a == @^b && all @a Zeqv @b }

my @a =  1 ,  2 ,  3 ;
my @b = '1', '2', '3';

ok [1, 2, 3] Meqv @a, 'Array matches Array (Int)';
ok (1, 2, 3) Meqv @a, 'List matches Array (Int)';
ok Seq(1, 2, 3) Meqv @a, 'Seq matches Array (Int)';

ok ['1', '2', '3'] Meqv @b, 'Array matches Array (Str)';
ok ('1', '2', '3') Meqv @b, 'List matches Array (Str)';
ok Seq('1', '2', '3') Meqv @b, 'Seq matches Array (Int)';

nok [1, '2', 3] Meqv @a, 'A-A: Type mismatch fails';
nok @a Meqv [1, '2', 3], 'A-A: Type mismatch fails (Flipped)';

nok (1, '2', 3) Meqv @a, 'L-A: Type mismatch fails';
nok @a Meqv (1, '2', 3), 'L-A: Type mismatch fails (Flipped)';

nok Seq(1, '2', 3) Meqv @a, 'S-A: Type mismatch fails';
nok @a Meqv Seq(1, '2', 3), 'S-A: Type mismatch fails (Flipped)';

nok [1, 2, 3, 4] Meqv @a, 'A-A: Elem mismatch fails';
nok @a Meqv [1, 2, 3, 4], 'A-A: Elem mismatch fails (Flipped)';

nok (1, 2, 3, 4) Meqv @a, 'L-A: Elem mismatch fails';
nok @a Meqv (1, 2, 3, 4), 'L-A: Elem mismatch fails (Flipped)';

nok Seq(1, 2, 3, 4) Meqv @a, 'S-A: Elem mismatch fails';
nok @a Meqv Seq(1, 2, 3, 4), 'S-A: Elem mismatch fails (Flipped)';

# This would fool Z==
nok [1, (1, 2), 3] Meqv @a, 'Coercion test passes';
nok @a Meqv [1, (1, 2), 3], 'Coercion test passes (Flipped)';

# This would fool Z~~
nok [1, True, 3] Meqv @a, 'Bool test passes';
nok @a Meqv [1, True, 3], 'Bool test passes (Flipped)';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment