Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created November 27, 2016 04:11
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 zoffixznet/1065ba0bf15c06c036d15d735a498cf3 to your computer and use it in GitHub Desktop.
Save zoffixznet/1065ba0bf15c06c036d15d735a498cf3 to your computer and use it in GitHub Desktop.
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