root/lang/perl/PlPy/trunk/PlPy/recycle/2 @ 219

Revision 219, 4.1 kB (checked in by tokuhirom, 6 years ago)

ディレクトリ構成みなおし

Line 
1use strict;
2use warnings;
3use Test::Base;
4use lib qw/./;
5use PyVM;
6
7use XXX -dumper;
8
9plan tests => 1*blocks;
10
11run {
12    my $block = shift;
13
14    my $out = '';
15    tie_output *STDOUT, $out;
16    PyVM::run_it( $block->input );
17    untie *STDOUT;
18    is $out, $block->expected, $block->name;
19};
20
21# TODO:
22#   [1,2,3,5][:-1] etc.
23#   keyword args.
24
25__END__
26
27=== simple
28--- input
29print 3+2
30--- expected
315
32
33=== string add
34--- input
35print 'Boo'+'fy'
36--- expected
37Boofy
38
39=== add,mul
40--- input
41print (3*2)+4
42--- expected
4310
44
45=== binary operators
46--- input
47print (3+2)-4*3.14/2
48--- expected
49-1.28
50
51=== binary power
52--- input
53print 3**4
54--- expected
5581
56
57=== binary floor divide
58--- input
59print 25//3
60--- expected
618
62
63=== binary modulo
64--- input
65print 25%3
66--- expected
671
68
69=== tuple
70--- input
71(1,2,3)
72--- expected
73
74=== list
75--- input
76[1,2,3]
77--- expected
78
79=== variable
80--- input
81x = 'kent'
82print x
83--- expected
84kent
85
86=== list one
87--- input
88x = [1,2,3]
89print x[1]
90--- expected
912
92
93=== inplace modulo
94--- input
95x = 58
96x %= 7
97print x
98--- expected
992
100
101=== binary lshift
102--- input
103print 1 << 3
104--- expected
1058
106
107=== binary rshift
108--- input
109print 25352 >> 3
110--- expected
1113169
112
113=== binary and
114--- input
115print 25352 & 522
116--- expected
117520
118
119=== binary or
120--- input
121print 25352 | 522
122--- expected
12325354
124
125=== binary xor
126--- input
127print 25352 ^ 522
128--- expected
12924834
130
131=== unary not
132--- input
133print not 25453
134--- expected
1350
136
137=== unary_INVERT
138--- input
139print ~25453
140--- expected
141-25454
142
143=== if
144--- input
145if 3>4:
146    print 'too bad'
147else:
148    print 'ok'
149--- expected
150ok
151
152=== if
153--- input
154if 3<4:
155    print 'ok'
156else:
157    print 'too bad'
158--- expected
159ok
160
161=== SLICE+0
162--- input
163x = [1,2,3,4,5]
164print x[:]
165--- expected
166[1, 2, 3, 4, 5]
167
168=== SLICE+1
169--- input
170x = [1,2,3,4,5]
171print x[2:]
172--- expected
173[3, 4, 5]
174
175=== SLICE+1
176--- input
177x = [1]
178print x[2:]
179--- expected
180[]
181
182=== SLICE+2
183--- input
184x = [1,2,3,4,5]
185print x[:2]
186--- expected
187[1, 2]
188
189=== SLICE+2
190--- input
191x = [1]
192print x[:2]
193--- expected
194[1]
195
196=== SLICE+3
197--- input
198x = [1, 2,3,4,5,6,7,8,9,10]
199print x[3:5]
200--- expected
201[4, 5]
202
203=== WHILE
204--- input
205i=0
206while i<3:
207    print i
208    i+=1
209--- expected
2100
2111
2122
213
214=== string modulo
215--- input
216print "mixi: %s" % 'Boofy'
217--- expected
218mixi: Boofy
219
220=== string modulo by tuple
221--- input
222print "mixi: %s, %s" % ('Boofy', 'bonnu')
223--- expected
224mixi: Boofy, bonnu
225
226=== FOR
227--- SKIP
228--- input
229for x in ['foo', 'bar', 'baz']:
230    print x
231--- expected
232foo
233bar
234baz
235
236=== simple function2
237--- input
238def foo(x, y, z):
239    print x*5+y*3
240
241foo(20, 4, 52)
242--- expected
243112
244
245=== use function with return value
246--- input
247def foo(x, y, z):
248    return x*5+y*2
249
250print foo(20, 4, 52)
251--- expected
252108
253
254=== use function with keyword arguments
255--- input
256def func(a1, a2="default a2", a3="default a3"):
257    print "a1=%s" % a1
258    print "a2=%s" % a2
259    print "a3=%s" % a3
260
261func(a3="custom a3", a1="custom a1")
262--- expected
263a1=custom a1
264a2=default a2
265a3=custom a3
266
267=== use function with keyword arguments
268--- ONLY
269--- input
270def func(a1, a2="default a2", a3="default a3"):
271    print "a1=%s" % a1
272    print "a2=%s" % a2
273    print "a3=%s" % a3
274
275func("custom a1", 'custom a2')
276--- expected
277a1=custom a1
278a2=custom a2
279a3=default a3
280
281
282=== use function with keyword arguments
283--- ONLY
284--- input
285def func(a1, a2="default a2", a3="default a3"):
286    print "a1=%s" % a1
287    print "a2=%s" % a2
288    print "a3=%s" % a3
289
290func("custom a1")
291--- expected
292a1=custom a1
293a2=default a2
294a3=default a3
295
296=== use function with keyword arguments
297--- SKIP
298--- input
299def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
300    print "-- This parrot wouldn't", action,
301    print "if you put", voltage, "Volts through it."
302    print "-- Lovely plumage, the", type
303    print "-- It's", state, "!"
304
305parrot(action = 'VOOOOOM', voltage = 1000000)
306#parrot('a thousand', state = 'pushing up the daisies')
307#parrot('a million', 'bereft of life', 'jump')
308#parrot(1000)
309--- expected
310108
311
312=== simple function
313--- SKIP
314--- input
315def foo(x, y):
316    x*=5
317    print x
318
319x = 20
320foo(x)
321print x
322--- expected
323100
324
325=== simple function
326--- SKIP
327--- input
328def foo(x):
329    print x*5
330
331foo(20)
332--- expected
333100
334
335=== �Ǥդ�����-- SKIP
336--- input
337def foo(x=4):
338    print x*5
339
340foo(20)
341--- expected
342100
Note: See TracBrowser for help on using the browser.