-
Notifications
You must be signed in to change notification settings - Fork 138
/
packfilebytecodesegment.t
118 lines (85 loc) · 2.1 KB
/
packfilebytecodesegment.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!./parrot
# Copyright (C) 2009-2011, Parrot Foundation.
=head1 NAME
t/pmc/packfilebytecodesegment.t - test the PackfileBytecodeSegment PMC
=head1 SYNOPSIS
% prove t/pmc/packfilebytecodesegment.t
=head1 DESCRIPTION
Tests the PackfileBytecodeSegment PMC.
=cut
.sub 'test' :main
.include 'test_more.pir'
plan(12)
$P0 = new 'PackfileBytecodeSegment'
isa_ok($P0, 'PackfileBytecodeSegment')
test_basics()
test_keyed_access()
test_bad_push()
test_methods()
.end
.sub test_basics
$P0 = new 'PackfileBytecodeSegment'
$P1 = new ['ResizablePMCArray']
$P1[0] = 'say_sc' # full name of the op
$P1[1] = 2 # random arguments
push $P0, $P1
$I0 = $P0
is( $I0, 2, 'test get_integer' )
$I0 = elements $P0
is( $I0, 2, 'test elements' )
$N0 = $P0
is( $N0, 2, 'test get_number' )
sweep 1 # test mark
.end
.sub test_keyed_access
$P0 = new 'PackfileBytecodeSegment'
$P1 = new ['ResizablePMCArray']
$P1[0] = 'say_sc' # full name of the op
$P1[1] = 2 # random arguments
push $P0, $P1
$I0 = $P0[1]
is( $I0, 2, 'test get_integer_keyed_int' )
$P0[1] = 4
$I0 = $P0[1]
is( $I0, 4, 'test set_integer_keyed_int' )
$P2 = $P0[1]
is( $P2, 4, 'test get_pmc_keyed_int' )
$P3 = new ['Integer']
$P3 = 1
$P4 = new ['Integer']
$P4 = 6
$P0[$P3] = $P4
$I0 = $P0[1]
is( $I0, 6, 'test set_pmc_keyed_pmc' )
$P2 = $P0[$P3]
is( $P2, 6, 'test get_pmc_keyed_pmc' )
.end
.sub test_bad_push
$P0 = new 'PackfileBytecodeSegment'
$P1 = new 'Integer'
push_eh eh_notarray
push $P0, $P1
goto bad
eh_notarray:
ok(1,"Exception on bad push")
goto done
pop_eh
bad:
nok(0,"No exception on bad push")
done:
.end
.sub test_methods
$P0 = new 'PackfileBytecodeSegment'
$I0 = get_addr $P0
$P1 =$P0."opmap"()
$S0 = typeof $P1
is($S0, "PackfileOpMap", "opmap()")
$P1 = $P0."main_sub"()
$I0 = $P0
is($I0, 0, "main_sub()")
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: