Ticket #195: override.diff
| File override.diff, 2.2 KB (added by coke, 4 years ago) |
|---|
-
t/oo/vtableoverride.t
18 18 19 19 .sub main :main 20 20 .include 'test_more.pir' 21 plan( 4)21 plan(11) 22 22 23 newclass_tests() 24 subclass_tests() 25 .end 26 27 .sub 'newclass_tests' 23 28 $P1 = new 'MyObject' 24 29 25 30 # Test get_string … … 28 33 $P0 = getattribute $P1, "message" 29 34 $S0 = $P0 30 35 is($S0, "[MyObject]", "attribute sideeffect of get_string") 31 36 37 # Test does 38 $I0 = does $P1, 'this_dress_make...' 39 is ($I0, 1, "check first does, ok") 40 $I0 = does $P1, 'a_body_good' 41 is ($I0, 1, "check second does, ok") 42 $I0 = does $P1, 'it_better' 43 is ($I0, 0, "no it doesn't") 44 32 45 # Test morph (doesn't actually perform a morph) 33 46 morph $P1, "String" 34 47 $P0 = getattribute $P1, "message" … … 41 54 is($S0, "Morphing [MyObject] to type Integer", "Morph VTABLE override 1") 42 55 .end 43 56 57 .sub 'subclass_tests' 58 $P1 = new 'MySubObject' 59 60 # Test does, same as newclass. 61 $I0 = does $P1, 'this_dress_make...' 62 is ($I0, 1, "check first does, ok") 63 $I0 = does $P1, 'a_body_good' 64 is ($I0, 1, "check second does, ok") 65 $I0 = does $P1, 'it_better' 66 is ($I0, 0, "no it doesn't") 67 # Also verify we does what our parent does 68 $I0 = does $P1, 'array' 69 is ($I0, 1, "inherited does") 70 .end 71 72 44 73 .namespace [ 'MyObject' ] 45 74 46 75 .sub '__onload' :anon :init … … 66 95 $P0 = box $S1 67 96 setattribute self, "message", $P0 68 97 .end 69 98 99 .sub 'does' :vtable 100 .param string query 101 if query == 'this_dress_make...' goto yes 102 if query == 'a_body_good' goto yes 103 .return(0) 104 yes: 105 .return (1) 106 .end 70 107 108 .namespace [ 'MySubObject' ] 109 110 .sub '__onload' :anon :init 111 $P1 = get_class 'ResizablePMCArray' 112 $P0 = subclass $P1, 'MySubObject' 113 .end 114 115 .sub 'does' :vtable 116 .param string query 117 if query == 'this_dress_make...' goto yes 118 if query == 'a_body_good' goto yes 119 .return(0) 120 yes: 121 .return (1) 122 .end 123 124 125 126 71 127 # Local Variables: 72 128 # mode: pir 73 129 # fill-column: 100
