Ticket #195: override.diff

File override.diff, 2.2 KB (added by coke, 6 years ago)

How I'd expect the override to work

  • t/oo/vtableoverride.t

     
    1818 
    1919.sub main :main 
    2020    .include 'test_more.pir' 
    21     plan(4) 
     21    plan(11) 
    2222     
     23    newclass_tests() 
     24    subclass_tests() 
     25.end 
     26 
     27.sub 'newclass_tests' 
    2328    $P1 = new 'MyObject' 
    2429     
    2530    # Test get_string 
     
    2833    $P0 = getattribute $P1, "message" 
    2934    $S0 = $P0 
    3035    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  
    3245    # Test morph (doesn't actually perform a morph) 
    3346    morph $P1, "String" 
    3447    $P0 = getattribute $P1, "message" 
     
    4154    is($S0, "Morphing [MyObject] to type Integer", "Morph VTABLE override 1") 
    4255.end 
    4356 
     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 
    4473.namespace [ 'MyObject' ] 
    4574 
    4675.sub '__onload' :anon :init 
     
    6695    $P0 = box $S1 
    6796    setattribute self, "message", $P0 
    6897.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) 
     104yes: 
     105    .return (1) 
     106.end 
    70107 
     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) 
     120yes: 
     121    .return (1) 
     122.end 
     123 
     124 
     125 
     126 
    71127# Local Variables: 
    72128#   mode: pir 
    73129#   fill-column: 100