Ticket #796: globals.t_to_pir.patch
File globals.t_to_pir.patch, 5.8 KB (added by flh, 13 years ago) |
---|
-
t/op/globals.t
1 #!p erl2 # Copyright (C) 2001-200 8, Parrot Foundation.1 #!parrot 2 # Copyright (C) 2001-2009, Parrot Foundation. 3 3 # $Id$ 4 4 5 use strict;6 use warnings;7 use lib qw( . lib ../lib ../../lib );8 use Test::More;9 use Parrot::Test tests => 9;10 11 5 =head1 NAME 12 6 13 7 t/op/globals.t - Global Variables … … 22 16 23 17 =cut 24 18 25 pasm_output_is( <<'CODE', '12', "set/get" ); 26 new P0, 'Integer' 27 new P1, 'Integer' 28 set P0, 12 29 set P1, 7 30 set_global "Integer", P0 31 get_global P1, "Integer" 32 print P1 33 end 34 CODE 19 .const int TESTS = 12 35 20 36 pasm_error_output_like( <<'CODE', <<'OUTPUT', "get null global" ); 37 null S0 38 get_global P1, S0 39 end 40 CODE 41 /Tried to get null global/ 42 OUTPUT 21 .namespace [] 43 22 44 pasm_output_is( <<'CODE', <<OUT, "not found null" ); 45 get_global P1, "no_such_global" 46 print "ok 1\n" 47 defined I0, P1 48 unless I0, ok2 49 print "not " 50 ok2: print "ok 2\n" 51 end 52 CODE 53 ok 1 54 ok 2 55 OUT 23 .sub 'test' :main 24 .include 'test_more.pir' 56 25 57 pir_output_is( <<'CODE', <<OUT, "get/set global with key" ); 58 .namespace [ "Monkey" ] 59 .sub main :main 60 set_it() 61 $P1 = get_hll_global [ "Monkey" ; "Toaster" ], "Explosion" 62 print $P1 26 plan(TESTS) 27 28 root_integer() 29 get_null_global() 30 not_found_null() 31 get_set_global_with_key() 32 fetch_and_store() 33 find_null_global() 34 get_hll_global_not_found() 35 find_store_with_key() 63 36 .end 64 .sub set_it 65 $P0 = new 'String' 66 $P0 = "Ook...BANG!\n" 67 set_global [ "Toaster" ], "Explosion", $P0 37 38 .namespace [] 39 .sub 'root_integer' 40 $P0 = new ['Integer'] 41 $P1 = new ['Integer'] 42 43 $P0 = 12 44 $P1 = 7 45 46 set_global "Integer", $P0 47 $P1 = get_global "Integer" 48 49 is($P1, 12, 'root_integer') 68 50 .end 69 CODE70 Ook...BANG!71 OUT72 51 73 pir_output_is( <<'CODE', <<OUT, "get/set root global with key" ); 74 .namespace [ "Monkey" ] 75 .sub main :main 76 set_it() 77 $P1 = get_hll_global [ "Monkey" ; "Toaster" ], "Explosion" 78 print $P1 52 .sub 'get_null_global' 53 $S0 = null 54 55 $I0 = 0 56 push_eh get_null_global_catch 57 $P1 = get_global $S0 58 pop_eh 59 goto get_null_global_end 60 61 get_null_global_catch: 62 $I0 = 1 63 64 get_null_global_end: 65 ok($I0, 'get null global') 79 66 .end 80 .sub set_it 67 68 .sub 'not_found_null' 69 $P1 = get_global 'no_such_global' 70 ok(1, 'not_found_null get_global returns') 71 72 $I0 = defined $P1 73 nok($I0, 'not_found_null get_global returns null') 74 .end 75 76 .sub 'get_set_global_with_key' 77 $P0 = get_global ['Monkey'], 'do_explosion' 78 $I0 = defined $P0 79 ok($I0, 'get_global of a sub with a key') 80 $P0() 81 .end 82 83 .namespace ['Monkey'] 84 .sub 'do_explosion' 85 set_it() 86 $P1 = get_hll_global [ "Monkey" ; "Toaster" ], "Explosion" 87 is($P1, "Ook...BANG!\n", 'get/set_global with key') 88 .end 89 90 .sub 'set_it' 81 91 $P0 = new 'String' 82 92 $P0 = "Ook...BANG!\n" 83 set_ root_global [ "parrot"; "Monkey";"Toaster" ], "Explosion", $P093 set_global [ "Toaster" ], "Explosion", $P0 84 94 .end 85 CODE86 Ook...BANG!87 OUT88 95 89 96 #---------------------------------------------------------------- 90 97 # LEGACY 91 98 #---------------------------------------------------------------- 92 99 93 pasm_output_is( <<'CODE', '12', "Fetch and store" ); 94 new P0, 'Integer' 95 new P1, 'Integer' 96 set P0, 12 97 set P1, 7 98 set_global "Integer", P0 99 get_hll_global P1, "Integer" 100 print P1 101 end 102 CODE 100 .namespace [] 103 101 104 pasm_error_output_like( <<'CODE', <<'OUTPUT', "Find null global" ); 105 null S0 106 get_hll_global P1, S0 107 end 108 CODE 109 /Tried to get null global/ 110 OUTPUT 102 .sub 'fetch_and_store' 103 $P0 = new 'Integer' 104 $P1 = new 'Integer' 111 105 112 pasm_output_is( <<'CODE', <<OUT, "not found null" ); 113 get_hll_global P1, "no_such_global" 114 print "ok 1\n" 115 defined I0, P1 116 unless I0, ok2 117 print "not " 118 ok2: print "ok 2\n" 119 end 120 CODE 121 ok 1 122 ok 2 123 OUT 106 $P0 = 12 107 $P1 = 7 124 108 125 pir_output_is( <<'CODE', <<OUT, "find/store global with key" ); 126 .sub main :main 127 set_it() 128 $P1 = get_hll_global [ "Monkey" ; "Toaster" ], "Explosion" 129 print $P1 109 set_global 'Integer', $P0 110 $P1 = get_hll_global 'Integer' 111 is($P1, 12, 'Fetch and store') 130 112 .end 131 .sub set_it 132 $P0 = new 'String' 133 $P0 = "Ook...BANG!\n" 134 set_hll_global [ "Monkey" ; "Toaster" ], "Explosion", $P0 113 114 .sub 'find_null_global' 115 $S0 = null 116 push_eh find_null_global_catch 117 $P1 = get_hll_global $S0 118 pop_eh 119 $I0 = 0 120 goto find_null_global_end 121 122 find_null_global_catch: 123 $I0 = 1 124 find_null_global_end: 125 ok($I0, 'Find null global') 135 126 .end 136 CODE137 Ook...BANG!138 OUT139 127 128 .sub 'get_hll_global_not_found' 129 $P1 = get_hll_global 'no such global' 130 ok(1, 'get_hll_global returns if not found') 131 132 $I0 = defined $P1 133 nok($I0, 'get_hll_global returns null if not found') 134 .end 135 136 .sub 'find_store_with_key' 137 $P0 = get_global ['Monkey2'], 'do_explosion' 138 $I0 = defined $P0 139 ok($I0, 'get_hll_global of a sub with a key') 140 $P0() 141 .end 142 143 .namespace ['Monkey2'] 144 .sub 'do_explosion' 145 set_it() 146 $P1 = get_hll_global [ "Monkey2" ; "Toaster" ], "Explosion" 147 is($P1, "Ook...BANG, again!\n", 'find/store global with key') 148 .end 149 150 .sub 'set_it' 151 $P0 = new 'String' 152 $P0 = "Ook...BANG, again!\n" 153 set_hll_global [ "Monkey2"; "Toaster" ], "Explosion", $P0 154 .end 155 140 156 # Local Variables: 141 # mode: cperl 142 # cperl-indent-level: 4 157 # mode: pir 143 158 # fill-column: 100 144 159 # End: 145 # vim: expandtab shiftwidth=4 :160 # vim: expandtab shiftwidth=4 ft=pir: