-
Notifications
You must be signed in to change notification settings - Fork 138
/
pair.t
85 lines (72 loc) · 1.63 KB
/
pair.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
#! parrot
# Copyright (C) 2001-2009, Parrot Foundation.
# $Id$
.const int NUM_OF_TESTS = 8
.sub main :main
loadlib $P1, 'pair'
load_bytecode 'Test/More.pbc'
.local pmc plan, is, ok
plan = get_hll_global [ 'Test'; 'More' ], 'plan'
is = get_hll_global [ 'Test'; 'More' ], 'is'
ok = get_hll_global [ 'Test'; 'More' ], 'ok'
# set a test plan
plan(NUM_OF_TESTS)
new $P0, ['Pair']
ok(1, "still alive")
new $P1, ['Integer']
set $P1, 42
set $P0["key"], $P1
ok(1, "still alive")
set $P2, $P0["key"]
is($P2, 42, "fetching value")
.local pmc p, kv
new p, ['Pair']
new $P1, ['Integer']
set $P1, 42
set p["key"], $P1
$P0 = p."key"()
is( $P0, 'key', 'get key' )
$P0 = p."value"()
is( $P0, 42, 'get key' )
kv = p."kv"()
$I0 = elements kv
is( $I0, 2, 'number of elements returned from "kv"' )
$P0 = kv[0]
is( $P0, 'key', 'first element returned from "kv"' )
$P0 = kv[1]
is( $P0, 42, 'third element returned from "kv"' )
.end
=for get it
SKIP: {
skip( "instantiate disabled", 1 );
pir_output_is( <<'CODE', <<'OUT', 'instantiate, assign' );
.sub main :main
.local pmc cl, p, kv, k, v
k = new ['String']
k = "key"
v = new ['String']
v = "value"
cl = get_class "Pair"
p = cl."instantiate"(k, v)
$P0 = p."key"()
print $P0
print ' '
$P0 = p."value"()
print $P0
print ' '
v = new ['Integer']
v = 77
assign p, v
$P0 = p."value"()
say $P0
.end
CODE
key value 77
OUT
}
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: