Skip to content

Instantly share code, notes, and snippets.

@usev6
Created December 21, 2014 19:01
Show Gist options
  • Save usev6/1b805c3f0dad510b8f32 to your computer and use it in GitHub Desktop.
Save usev6/1b805c3f0dad510b8f32 to your computer and use it in GitHub Desktop.
tests for RT #122342
use v6;
use Test;
plan 25;
## see S03 "Binary hyper operators"
{
my @a = (1, 4, 9);
@a>>++;
is @a, (2, 5, 10), 'OK';
@a»++;
is @a, (3, 6, 11), 'OK';
@a>>.++;
is @a, (4, 7, 12), 'OK';
@a».++;
is @a, (5, 8, 13), 'OK';
}
## non-wordy postfix operator
{
sub postfix:<???>($) {
return 42;
}
my @a = 1 .. 3;
is @a>>???, (42, 42, 42), 'OK';
is @a»???, (42, 42, 42), 'OK';
is @a>>.???, (42, 42, 42), 'OK';
is @a».???, (42, 42, 42), 'OK';
}
## wordy postfix operator
{
sub postfix:<foo>($) {
return 42;
}
my @a = 1 .. 3;
is @a>>foo, (42, 42, 42), 'OK';
is @a»foo, (42, 42, 42), 'OK';
throws_like { @a>>.foo }, X::Method::NotFound,
message => "No such method 'foo' for invocant of type 'Int'",
'OK';
throws_like { @a».foo }, X::Method::NotFound,
message => "No such method 'foo' for invocant of type 'Int'",
'OK';
}
{
my @a = <f foo foobar>;
is @a>>.chars, (1, 3, 6), 'OK';
is @a».chars, (1, 3, 6), 'OK';
is @a>>."chars"(), (1, 3, 6), 'OK';
is @a»."chars"(), (1, 3, 6), 'OK';
}
## no confusion with postfix:<i> (see S32-Numeric)
{
my class D { method i { 42 } };
is D.i, 42, 'OK';
is D.i(), 42, 'OK';
is 4i, Complex.new(0, 4), 'OK';
is 4\i, Complex.new(0, 4), 'OK';
throws_like { 4.i }, X::Method::NotFound,
message => "No such method 'i' for invocant of type 'Int'",
'OK';
is (2,3)>>i, (Complex.new(0, 2), Complex.new(0, 3)), 'OK';
is (2,3)»i, (Complex.new(0, 2), Complex.new(0, 3)), 'OK';
}
{
my @a = ( { 42 }, { 43 } );
is @a>>.(), (42, 43), 'OK';
is @a».(), (42, 43), 'OK';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment