Skip to content

Commit

Permalink
Test Range operators with Range subclasses
Browse files Browse the repository at this point in the history
Rakudo fix: Raku/doc#1798
  • Loading branch information
zoffixznet committed Mar 2, 2018
1 parent 81d8cc9 commit 6607795
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion S03-operators/range.t
Expand Up @@ -3,7 +3,7 @@ use lib $?FILE.IO.parent(2).add("packages");
use Test;
use Test::Util;

plan 177;
plan 178;

# L<S03/Nonchaining binary precedence/Range object constructor>

Expand Down Expand Up @@ -276,4 +276,25 @@ for @opvariants {
eval-lives-ok "\{ use fatal; (~4)$_ 5 }", "$_ doesn't warn on parenthesized stringification (endpoint)";
}

# https://github.com/rakudo/rakudo/issues/1582
subtest 'Range operators work with subclasses of Range' => {
plan 10;
# While `(42 but role Foo {}) + 42` produces a plain `Int`, Range ops will produce a subclass
# rather than plain `Range`, if one was used originally, since there's only one `Range` object
# involved, so we know exactly what we have to become.
my role Meows {}
my $r := (2..^5) but Meows;
is-deeply ($r + 5), ((7..^10) but Meows), 'Range + Real';
is-deeply (5 + $r), ((7..^10) but Meows), 'Real + Range';
is-deeply ($r - 5), ((-3..^0) but Meows), 'Range - Real'; # No `Real - Range` meaning
is-deeply ($r * 5), ((10..^25) but Meows), 'Range * Real';
is-deeply (5 * $r), ((10..^25) but Meows), 'Real Range';
is-deeply ($r / 5), (((2/5)..^1.0) but Meows), 'Range / Real'; # No `Real / Range` meaning

is-deeply ($r5), ((-3..^0) but Meows), "Range U+2212 minus Real";
is-deeply ($r × 5), ((10..^25) but Meows), 'Range U+00D7 Real';
is-deeply (5 × $r), ((10..^25) but Meows), 'Real U+00D7 Range';
is-deeply ($r ÷ 5), (((2/5)..^1.0) but Meows), 'Range U+00F7 Real';
}

# vim: ft=perl6

1 comment on commit 6607795

@zoffixznet
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meant to say: Rakudo fix: rakudo/rakudo@440fcea

Please sign in to comment.