Changeset 23051

Show
Ignore:
Timestamp:
11/21/08 19:02:01 (7 weeks ago)
Author:
jnthn
Message:

[spectest] Try to clean up and correct a subtypes test file. It used the wrong keyword, had one test that was wrong and other mess. Fudge it for Rakudo too.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • t/spec/S02-builtin_data_types/subtypes.t

    r21426 r23051  
    33use Test; 
    44 
    5 # XXX: 20 tests should be run, but because of the various eval()s dieing too 
    6 # early, currently there're only 10 tests run. 
    7 # So, to avoid "7/20 failed" messages, *temporarily* pretend that only 13 tests 
    8 # are planned. 
    9 plan 13; 
     5plan 17; 
    106 
    117=begin description 
     
    2218'; 
    2319 
    24 ok(eval("$abs; 1"), "we can compile subtype declarations", :todo<feature>); 
     20ok(eval("$abs; 1"), "we can compile subtype declarations"); 
    2521 
    26 is(eval("$abs; my_abs(3)"), 3, "and we can use them, too", :todo<feature>); 
    27 is(eval("$abs; my_abs(-5)"), 5, "and they actually work", :todo<feature>); 
     22is(eval("my_abs(3)"), 3, "and we can use them, too"); 
     23is(eval("my_abs(-5)"), 5, "and they actually work"); 
    2824 
    2925 
    3026# Basic subtype creation 
    31 ok eval('subtype Num::Odd of Num where { $^num % 2 == 1 }'), 
    32   "subtype is correctly parsed", :todo<feature>; 
     27ok eval('subset Num::Odd of Num where { $^num % 2 == 1 }; 1'), 
     28  "subtype is correctly parsed"; 
    3329is eval('my Num::Odd $a = 3'), 3, "3 is an odd num"; 
    3430# The eval inside the eval is/will be necessary to hider our smarty 
     
    3632# (Actually, if the compiler is *really* smarty, it will notice our eval trick, 
    3733# too :)) 
    38 is eval('my Num::Odd $b = 3; try { $a = eval 4 }; $a'), 3, 
    39   "objects of Num::Odd don't get even", :todo<feature>; 
     34is eval('my Num::Odd $b = 3; try { $b = eval "4" }; $b'), 3, 
     35  "objects of Num::Odd don't get even"; 
    4036 
    4137# The same, but lexically 
    4238my $eval1 = '{ 
    43   my subtype Num::Even of Num where { $^num % 2 == 0 } 
    44   ok my Num::Even $c = 6, :todo<feature>; 
    45   ok $c ~~ Num::Even, "our var is a Num::Even", :todo<feature>; 
     39  my subset Num::Even of Num where { $^num % 2 == 0 } 
     40  ok my Num::Even $c = 6; 
     41  ok $c ~~ Num::Even, "our var is a Num::Even"; 
    4642  try { $c = eval 7 } 
    47   is $c, 6, "setting a Num::Even to an odd value dies", :todo<feature>; 
     43  is $c, 6, "setting a Num::Even to an odd value dies"; 
    4844}'; 
    4945eval $eval1; 
     
    5349# Subs with arguments of a subtype 
    5450ok eval('sub only_accepts_odds(Num::Odd $odd) { $odd + 1 }'), 
    55   "sub requiring a Num::Odd as argument defined (1)", :todo<feature>; 
    56 is eval('only_accepts_odds(3)'), 4, 
    57   "calling sub worked"; 
    58 ok eval('!try { only_accepts_odds(4) }'), 
    59   "calling sub did not work", :todo<feature>; 
     51  "sub requiring a Num::Odd as argument defined (1)"; 
     52is eval('only_accepts_odds(3)'), 4, "calling sub worked"; 
     53#?rakudo skip 'return value of try on a failure is null' 
     54ok eval('!try { only_accepts_odds(4) }'), "calling sub did not work"; 
    6055 
    6156# Normal Ints automatically morphed to Num::Odd 
    6257ok eval('sub is_num_odd(Num::Odd $odd) { $odd ~~ Num::Odd }'), 
    63   "sub requiring a Num::Odd as argument defined (2)", :todo<feature>; 
    64 ok eval('is_num_odd(3)'), "Int automatically morphed to Num::Odd", :todo<feature>; 
    65 is eval('only_accepts_odds("3")'), 4, "Str automatically morphed to Num::Odd"; 
     58  "sub requiring a Num::Odd as argument defined (2)"; 
     59ok eval('is_num_odd(3)'), "Int accepted by Num::Odd"; 
    6660 
    6761# Following code is evil, but should work: 
    68 my $eval2 = ' 
     62#?rakudo skip 'subests and lexicals' 
     63#?DOES 5 
     64{ 
    6965  my Int $multiple_of; 
    70   subtype Num::Multiple of Num where { $^num % $multiple_of == 0 } 
     66  subset Num::Multiple of Num where { $^num % $multiple_of == 0 } 
    7167 
    7268  $multiple_of = 5; 
    73   ok $multiple_of ~~ Isa, "basic sanity (1)", :todo<feature>; 
    74   is $multiple_of,     5, "basic sanity (2)", :todo<feature>; 
     69  ok $multiple_of ~~ Int, "basic sanity (1)"; 
     70  is $multiple_of,     5, "basic sanity (2)"; 
    7571 
    76   ok my Num::Multiple $d = 10, "creating a new Num::Multiple", :todo<feature>; 
    77   is $d,                   10, "creating a new Num::Multiple actually worked", :todo<feature>; 
     72  ok my Num::Multiple $d = 10, "creating a new Num::Multiple"; 
     73  is $d,                   10, "creating a new Num::Multiple actually worked"; 
    7874   
    7975  $multiple_of = 6; 
    8076  ok !try { my Num::Multiple $e = eval 10 }, 
    8177    "changed subtype definition worked"; 
    82 '; 
    83 eval $eval2; 
     78} 
     79