|
| 1 | +use v6; |
| 2 | +use Test; |
| 3 | + |
| 4 | +plan 33; |
| 5 | + |
| 6 | +# Degenerate and Transformative Any methods |
| 7 | +# ----- |
| 8 | +# This file covers methods on Any that are normally provided by other types |
| 9 | +# and the Any version simply translates the object to that type, throws, |
| 10 | +# or returns a degenerate result |
| 11 | + |
| 12 | +{ # coverage; 2016-09-18 |
| 13 | + throws-like { 42.classify }, Exception, '.classify() on Any throws'; |
| 14 | + throws-like { 42.classify: * }, Exception, '.classify(*) on Any throws'; |
| 15 | + throws-like { 42.categorize }, Exception, '.categorize() on Any throws'; |
| 16 | + throws-like { 42.categorize: * }, Exception, '.categorize(*) on Any throws'; |
| 17 | + |
| 18 | + throws-like { 42.Map }, X::Hash::Store::OddNumber, '.Map [odd num of els]'; |
| 19 | + is-deeply (42, 'a').Map, Map.new(("42" => "a")), '.Map [even num of els]'; |
| 20 | + |
| 21 | + is-deeply Any.kv, (), 'Any:U.kv returns empty list'; |
| 22 | + is-deeply Any.pairs, (), 'Any:U.pairs returns empty list'; |
| 23 | + is-deeply Any.antipairs, (), 'Any:U.antipairs returns empty list'; |
| 24 | + |
| 25 | + my @exp = 1, 2, "foo"; |
| 26 | + my class AnyU { |
| 27 | + method append (*@got) { is-deeply @got, @exp, 'append called' ; 1; } |
| 28 | + method prepend (*@got) { is-deeply @got, @exp, 'prepend called'; 1; } |
| 29 | + method unshift (*@got) { is-deeply @got, @exp, 'unshift called'; 1; } |
| 30 | + method push (*@got) { is-deeply @got, @exp, 'push called' ; 1; } |
| 31 | + } |
| 32 | + my class AnyUPos is AnyU does Positional {} |
| 33 | + |
| 34 | + for <append prepend unshift push> -> $m { |
| 35 | + is AnyU."$m"( @exp), 1, ".$m on custom Any:U"; |
| 36 | + is AnyUPos."$m"(@exp), 1, ".$m on custom Any:U does Positonal"; |
| 37 | + } |
| 38 | + |
| 39 | + is-deeply $ .unshift(@exp), [@exp,], '.unshift on Any:U'; |
| 40 | + is-deeply $ .prepend(@exp), @exp, '.prepend on Any:U'; |
| 41 | + is-deeply $ .append( @exp), @exp, '.append on Any:U'; |
| 42 | + is-deeply $ .push( @exp), [@exp,], '.push on Any:U'; |
| 43 | + is-deeply @ .prepend(@exp), @exp, '.prepend on Any:U [Positional]'; |
| 44 | + is-deeply @ .append( @exp), @exp, '.append on Any:U [Positional]'; |
| 45 | + is-deeply @ .unshift(@exp), [@exp,], '.unshift on Any:U [Positional]'; |
| 46 | + is-deeply @ .push( @exp), [@exp,], '.push on Any:U [Positional]'; |
| 47 | +} |
0 commit comments