[t][TT #1122] Convert t/op/literal.t to PIR and keep old PASM tests in t/op/literal...
[parrot.git] / t / oo / methods.t
bloba4a1b3e3fa015f24b211164d698f96be6572a769
1 #! parrot
2 # Copyright (C) 2007 - 2008, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/oo/methods.t - Test OO methods
9 =head1 SYNOPSIS
11     % prove t/oo/methods.t
13 =head1 DESCRIPTION
15 Tests features related to the creation, addition, and execution of OO methods.
17 =cut
19 .sub main :main
20     .include 'test_more.pir'
22     create_library()
24     plan(5)
26     loading_methods_from_file()
27     loading_methods_from_eval()
28     overridden_find_method()
30     delete_library()
32 .end
34 .sub create_library
35     .local pmc file
36     .local string filename
38     filename = "method_library.pir"
39     file = open filename, 'w'
41     $S0 = <<'END'
42     .namespace['Foo']
43     .sub 'bar_method' :method
44         .return (1)
45     .end
46 END
48     print file, $S0
49     close file
51 .end
53 .sub delete_library
54     .local pmc os
55     os = new 'OS'
56     $S0 = "method_library.pir"
57     os.'rm'($S0)
58 .end
60 .sub loading_methods_from_file
61     $P0 = newclass 'Foo'
62     $P1 = new 'Foo'
63     $I0 = $P1.'foo_method'()
64     ok ($I0, 'calling foo_method')
66     load_bytecode 'method_library.pir'
67     $P1 = new 'Foo'
68     $I0 = $P1.'bar_method'()
69     ok ($I0, 'calling bar_method')
70     $P0 = null
71 .end
73 .namespace ['Foo']
74 .sub 'foo_method' :method
75     .return (1)
76 .end
77 .namespace []
79 .sub loading_methods_from_eval
80     $P0 = newclass 'Bar'
81     $P1 = new 'Bar'
83     $I0 = $P1.'foo_method'()
84     ok ($I0, 'calling foo_method')
86     $S2 = <<'END'
87         .namespace ['Bar']
88         .sub 'bar_method' :method
89             .return (1)
90         .end
91 END
92     $P2 = compreg 'PIR'
93     $P2($S2)
95     $P1 = new 'Bar'
96     $I0 = $P1.'bar_method'()
97     ok ($I0, 'calling bar_method')
98 .end
100 .namespace ['Bar']
101 .sub 'foo_method' :method
102     .return (1)
103 .end
104 .namespace []
106 .sub overridden_find_method
107     $P0 = newclass 'Obj'
108     $P2 = new 'Obj'
109     $I0 = $P2.'some_method'(42)
110     is ($I0, 42, 'calling overriden method')
111 .end
113 .namespace ['Obj']
115 .sub 'meth' :method
116     .param pmc a
117     .return (a)
118 .end
120 .sub 'find_method' :vtable :method
121     .param string meth_name
123     .const 'Sub' meth = 'meth'
124     .return (meth)
125 .end
127 .namespace []
129 # Local Variables:
130 #   mode: pir
131 #   fill-column: 100
132 # End:
133 # vim: expandtab shiftwidth=4 ft=pir: