[t][TT #1122] Convert t/op/numbert.t to PIR, mgrimes++
[parrot.git] / t / pmc / globals.t
blobd57e81ea46bf4906a10156fa6c4eb5b2771138b3
1 #! perl
2 # Copyright (C) 2001-2005, Parrot Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( . lib ../lib ../../lib );
8 use Test::More;
9 use Parrot::Test tests => 4;
11 =head1 NAME
13 t/pmc/globals.t - Globals and Namespaces
15 =head1 SYNOPSIS
17     % prove t/pmc/globals.t
19 =head1 DESCRIPTION
21 Tests the globals fetch and store operations.
23 =cut
25 pir_output_is( <<'CODE', <<'OUTPUT', "get namespace" );
26 .sub main
27    .local pmc ns, o
28    ns = get_global "Foo"
29    o = ns["f"]
30    o()
31 .end
33 .namespace ["Foo"]
34 .sub f
35     print "ok\n"
36 .end
37 CODE
39 OUTPUT
41 pir_output_is( <<'CODE', <<'OUTPUT', "create namespace" );
42 .sub main
43     .local pmc f, x
44     f = get_global "f"
45     set_global ["Foo"], "x", f
46     x = get_global ["Foo"], "x"
47     x()
48 .end
50 .sub f
51     print "ok\n"
52 .end
53 CODE
55 OUTPUT
57 pir_output_is( <<'CODE', <<'OUTPUT', "get namespace - nested" );
58 .sub main
59    .local pmc ns, o
60    ns = get_hll_namespace ["Foo"; "Bar"]
61    o = ns["f"]
62    o()
63 .end
65 .namespace ["Foo" ; "Bar"]
66 .sub f
67     print "ok\n"
68 .end
69 CODE
71 OUTPUT
73 # this is pretty much taken from PDD 21
74 pir_output_is( <<'CODE', <<'OUTPUT', "get namespace - array" );
75 .namespace ['Foo'; 'Bar']
76 .sub test
77   print "ok\n"
78   .return()
79 .end
81 .namespace []
82 .sub main :main
83   $P0 = split "::", "Foo::Bar::test"
84   $S0 = pop $P0
86   $P1 = get_hll_namespace $P0
87   $P1 = $P1[$S0]
89   $P1()
90   end
91 .end
92 CODE
94 OUTPUT
96 # Local Variables:
97 #   mode: cperl
98 #   cperl-indent-level: 4
99 #   fill-column: 100
100 # End:
101 # vim: expandtab shiftwidth=4: