Changeset 23051
- Timestamp:
- 11/21/08 19:02:01 (7 weeks ago)
- Files:
-
- 1 modified
-
t/spec/S02-builtin_data_types/subtypes.t (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
t/spec/S02-builtin_data_types/subtypes.t
r21426 r23051 3 3 use Test; 4 4 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; 5 plan 17; 10 6 11 7 =begin description … … 22 18 '; 23 19 24 ok(eval("$abs; 1"), "we can compile subtype declarations" , :todo<feature>);20 ok(eval("$abs; 1"), "we can compile subtype declarations"); 25 21 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>);22 is(eval("my_abs(3)"), 3, "and we can use them, too"); 23 is(eval("my_abs(-5)"), 5, "and they actually work"); 28 24 29 25 30 26 # Basic subtype creation 31 ok eval('sub type Num::Odd of Num where { $^num % 2 == 1 }'),32 "subtype is correctly parsed" , :todo<feature>;27 ok eval('subset Num::Odd of Num where { $^num % 2 == 1 }; 1'), 28 "subtype is correctly parsed"; 33 29 is eval('my Num::Odd $a = 3'), 3, "3 is an odd num"; 34 30 # The eval inside the eval is/will be necessary to hider our smarty … … 36 32 # (Actually, if the compiler is *really* smarty, it will notice our eval trick, 37 33 # 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>;34 is eval('my Num::Odd $b = 3; try { $b = eval "4" }; $b'), 3, 35 "objects of Num::Odd don't get even"; 40 36 41 37 # The same, but lexically 42 38 my $eval1 = '{ 43 my sub typeNum::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"; 46 42 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"; 48 44 }'; 49 45 eval $eval1; … … 53 49 # Subs with arguments of a subtype 54 50 ok 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)"; 52 is eval('only_accepts_odds(3)'), 4, "calling sub worked"; 53 #?rakudo skip 'return value of try on a failure is null' 54 ok eval('!try { only_accepts_odds(4) }'), "calling sub did not work"; 60 55 61 56 # Normal Ints automatically morphed to Num::Odd 62 57 ok 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)"; 59 ok eval('is_num_odd(3)'), "Int accepted by Num::Odd"; 66 60 67 61 # Following code is evil, but should work: 68 my $eval2 = ' 62 #?rakudo skip 'subests and lexicals' 63 #?DOES 5 64 { 69 65 my Int $multiple_of; 70 sub typeNum::Multiple of Num where { $^num % $multiple_of == 0 }66 subset Num::Multiple of Num where { $^num % $multiple_of == 0 } 71 67 72 68 $multiple_of = 5; 73 ok $multiple_of ~~ I sa, "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)"; 75 71 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"; 78 74 79 75 $multiple_of = 6; 80 76 ok !try { my Num::Multiple $e = eval 10 }, 81 77 "changed subtype definition worked"; 82 '; 83 eval $eval2; 78 } 79
