Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: rakudo-master
Fetching contributors…

Cannot retrieve contributors at this time

file 115 lines (94 sloc) 3.342 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
use v6;

use MONKEY_TYPING;

use Test;


=begin description

Enum tests from L<S12/Enumerations>

=end description

#?pugs 999 skip
# L<S12/Enumerations/keys are specified as a parenthesized list>
enum day <Sun Mon Tue Wed Thu Fri Sat>;

ok day ne "", 'enum itself stringififes';
#?rakudo skip 'regression'
ok day.WHAT, 'enum.WHAT returned a value';
ok day.perl, 'enum.perl returned a value';

sub test_stuff($x) {
#?rakudo 1 skip '.does for enum value - XXX is this really valid test? asked TimToady...'
  ok $x.does(day::Tue), "basic enum mixing worked ($x-2)";
  is $x.day, 2, "automatically created accessor worked ($x)";
  is day::Tue, 2, "enum provided a correct mapping ($x)";
  ok $x ~~ day, "smartmatch worked correctly ($x-1)";
  ok $x ~~ Tue, "smartmatch worked correctly ($x-2)";
  ok $x ~~ day::Tue, "smartmatch worked correctly ($x-3)";
  ok $x !~~ Wed, "smartmatch worked correctly ($x-4)";
#?rakudo 1 skip '.does for enum value - XXX is this really valid test? asked TimToady...'
  ok $x.does(Tue), ".does worked correctly ($x-1)";
  ok $x.does(day), ".does worked correctly ($x-2)";
  #?rakudo skip 'EnumValue($x)'
  ok Tue($x), "Tue() worked correctly ($x)";
  ok $x.Tue, ".Tue() worked correctly ($x)";
  #?rakudo skip 'unknown bug'
  ok $x.Tue.WHAT, '$obj.Tue.WHAT returns a true valuee';
  ok $x.Tue.perl, '$obj.Tue.perl returns a true valuee';
}

{
  my $x = 1;
  is $x, 1, "basic sanity (1)";
  # L<S12/Enumerations/on the right side of a but or does.>
  ok $x does day(Tue), "basic enum mixing worked (1-1)";
  test_stuff($x);
}


#?rakudo skip 'does day::Tue'
{
  my $x = 3;
  is $x, 3, "basic sanity (3)";
  ok $x does day::Tue, "basic enum mixing worked (3-1)";
  test_stuff($x);
}

#?DOES 16
#?rakudo skip 'does &day::("Tue")'
{
  my $x = 4;
  is $x, 4, "basic sanity (4)";
  # L<S12/Enumerations/Mixing in the full enumeration type produces a
  # read-write attribute>
  ok $x does day, "basic enum mixing worked (4-0)";
  ok $x.day = &day::("Tue"), "basic enum mixing worked (4-1)";
  test_stuff($x);
}

# used to be Rakudo regression, RT #64098
#?rakudo skip 'augment'
#?DOES 2
{
    augment class Mu {
        method f { 'inMu' };
    }

    augment class Bool {
        method f { 'inBool' };
    }
    is True.f, 'inBool', 'method on short name pick up the one from the enum';
    is Bool::True.f, 'inBool', 'method on long name pick up the one from the enum';
}

ok True.perl ~~/^ 'Bool::True'/, 'True.perl';
ok Bool::True.perl ~~/^ 'Bool::True'/, 'Bool::True.perl';

{
    enum Negation << :isnt<isnt> :arent<arent> :amnot<amnot> :aint<aint> >>;
    my Negation $foo;
    #?rakudo todo 'Null PMC Access in invoke()'
    lives_ok { $foo = Negation::isnt }, 'simple assignment from enum';
    #?rakudo skip 'Null PMC Access in invoke()'
    is $foo, Negation::isnt, 'assignment from enum works';
}

# RT #66886
{
    enum RT66886 <b>;
    eval_dies_ok 'RT66886::c', 'accessing non-value of enum dies proper-like';
}

# RT #65658
{
    enum RT65658 <Todo Bug Feature Ticket>;
    #?rakudo 2 skip 'RT 65658'
    is RT65658(2), RT65658::Feature, 'can index enum by number';
    is RT65658((Todo + 3.2).Int), RT65658::Ticket, 'enum and math and index';
}

done;

# vim: ft=perl6
Something went wrong with that request. Please try again.