Ticket #160: t_library.diff
File t_library.diff, 14.3 KB (added by geraud, 13 years ago) |
---|
-
t/library/File_Spec.t
1 #! p erl2 # Copyright (C) 2001-200 8, The Perl Foundation.1 #! parrot 2 # Copyright (C) 2001-2009, The Perl Foundation. 3 3 # $Id$ 4 4 5 use strict;6 use warnings;7 use lib qw( t . lib ../lib ../../lib );8 use Test::More;9 use Parrot::Test tests => 20;10 11 5 =head1 NAME 12 6 13 t/library/File -Spec.t - test File::Spec module7 t/library/File_Spec.t - test File::Spec module 14 8 15 9 =head1 SYNOPSIS 16 10 17 % prove t/library/File -Spec.t11 % prove t/library/File_Spec.t 18 12 19 13 =head1 DESCRIPTION 20 14 … … 25 19 ############################## 26 20 # File::Spec 27 21 28 my $PRE = <<'PRE'; 29 .sub 'main' :main 30 load_bytecode 'library/File/Spec.pir'22 .sub main :main 23 .include 'test_more.pir' 24 plan(22) 31 25 32 .local int classtype 33 .local pmc spec 26 FS_load_bytecode() 27 FS_new() 28 FS_can() 29 FS_isa() 30 FS_version() 31 FS_private_subs() 32 .end 34 33 35 spec = new 'File::Spec' 34 .sub FS_load_bytecode 35 load_bytecode 'File/Spec.pir' 36 ok(1, 'load_bytecode') 37 .end 36 38 37 PRE 38 my $POST = <<'POST'; 39 goto OK 40 NOK: 41 print "not " 42 OK: 43 print "ok" 44 END: 45 print "\n" 39 .sub FS_new 40 .local pmc spec 41 42 spec = new 'File::Spec' 43 ok(1, 'new') 46 44 .end 47 POST48 45 49 ## 1 50 pir_output_is( <<'CODE'. $POST, <<'OUT', "load_bytecode" ); 51 .sub 'main' :main 52 load_bytecode 'File/Spec.pir' 53 CODE 54 ok 55 OUT 46 .sub FS_can 47 .local pmc spec 48 .local pmc method_list 56 49 57 pir_output_is( $PRE . <<'CODE'. $POST, <<'OUT', "new" ); 58 CODE 59 ok 60 OUT 50 $S0 = '__isa VERSION devnull tmpdir case_tolerant file_name_is_absolute ' 51 $S0 = concat $S0, 'catfile catdir path canonpath splitpath splitdir ' 52 $S0 = concat $S0, 'catpath abs2rel rel2abs' 53 method_list = split ' ', $S0 61 54 62 my @meths = ( 63 qw/ 64 __isa VERSION devnull tmpdir case_tolerant file_name_is_absolute catfile 65 catdir path canonpath splitpath splitdir catpath abs2rel rel2abs 66 / 67 ); 68 pir_output_is( $PRE . <<"CODE". $POST, <<'OUT', "can ($_)" ) for @meths; 69 .local pmc meth 70 \$I0 = can spec, "$_" 71 unless \$I0, NOK 72 CODE 73 ok 74 OUT 55 spec = new 'File::Spec' 75 56 76 pir_output_like( $PRE . <<'CODE'. $POST, <<'OUT', "isa" ); 77 .local pmc class 78 class= new 'String' 57 LOOP: 58 $I0 = elements method_list 59 if $I0 == 0 goto END_TEST 60 $S0 = method_list.'shift'() 61 $I0 = can spec, $S0 62 $S1 = concat 'File::Spec can ', $S0 63 ok($I0, $S1) 64 goto LOOP 79 65 80 class= spec.'__isa'() 81 print class 82 print "\n" 83 CODE 84 /^File::Spec::.+/ 85 OUT 66 END_TEST: 67 .end 86 68 87 pir_output_is( $PRE . <<'CODE'. $POST, <<'OUT', "version" ); 88 .local pmc version 89 version= spec.'VERSION'() 90 print version 91 goto END 92 CODE 93 0.1 94 OUT 69 .sub FS_isa 70 .local pmc spec 95 71 96 ## testing private subs 97 pir_output_is( $PRE . <<'CODE'. $POST, <<'OUT', "_get_module" ); 98 .local string module 99 .local pmc get_module 100 get_module = get_hll_global [ 'File::Spec' ], '_get_module' 101 module= get_module( 'MSWin32' ) 102 print module 103 print "\n" 104 module= get_module( 'foobar' ) 105 print module 106 goto END 107 CODE 108 Win32 109 Unix 110 OUT 72 spec = new 'File::Spec' 73 isa_ok(spec, 'File::Spec') 74 $S0 = spec.'__isa'() 75 like($S0, "File '::' Spec '::' .+", 'The object isa File::Spec::.+') 76 .end 111 77 78 .sub FS_version 79 .local pmc spec 80 81 spec = new 'File::Spec' 82 $S0 = spec.'VERSION'() 83 is($S0, '0.1', 'VERSION 0.1') 84 .end 85 86 .sub FS_private_subs 87 .local pmc spec 88 89 spec = new 'File::Spec' 90 .local string module 91 .local pmc get_module 92 get_module = get_hll_global [ 'File::Spec' ], '_get_module' 93 94 module = get_module( 'MSWin32' ) 95 is(module, 'Win32', 'File::Spec module for MSWin32 is Win32') 96 97 module = get_module( 'foobar' ) 98 is(module, 'Unix', 'File::Spec module for foobar is Unix') 99 .end 100 112 101 # Local Variables: 113 # mode: cperl 114 # cperl-indent-level: 4 102 # mode: pir 115 103 # fill-column: 100 116 104 # End: 117 # vim: expandtab shiftwidth=4 :105 # vim: expandtab shiftwidth=4 ft=pir: -
t/library/data_escape.t
1 #! perl2 # Copyright (C) 2001-200 6, The Perl Foundation.1 #! parrot 2 # Copyright (C) 2001-2009, The Perl Foundation. 3 3 # $Id$ 4 4 5 use strict;6 use warnings;7 use lib qw( t . lib ../lib ../../lib );8 use Test::More;9 use Parrot::Test tests => 22;10 11 5 =head1 NAME 12 6 13 7 t/library/data_escape.t - Data::Escape tests … … 18 12 19 13 =cut 20 14 21 my $lib = 'Data/Escape.pir';22 my $ns = 'Data::Escape';23 my @subs = qw/ String /;24 25 my $PRE = <<"PRE";26 15 .sub main :main 27 load_bytecode "$lib" 16 .include 'test_more.pir' 17 plan(22) 28 18 29 .local pmc escape_string 30 31 escape_string = get_global ['$ns'], 'String' 32 PRE 33 34 my $POST = <<'POST'; 35 NOK: 36 print "not " 37 OK: 38 print "ok" 39 END: 40 print "\n" 19 DE_load_bytecode() 20 DE_get_global() 21 DE_escape_string_empty_string() 22 DE_escape_string_no_escapes() 23 DE_escape_string_tab_carriage_return_linefeed() 24 DE_escape_string_other_characters_less_than_32() 25 DE_escape_string_single_quote() 26 DE_escape_string_double_quote() 27 DE_escape_string_single_and_double_escape_single() 28 DE_escape_string_single_and_double_escape_double() 29 DE_escape_string_backslash() 30 DE_escape_string_unprintable_followed_by_numbers() 31 DE_escape_string_non_ascii() 32 DE_escape_string_freeze_a_simple_pmc() 33 DE_unicode_test() 41 34 .end 42 POST43 35 44 ## 1 45 pir_output_is( <<CODE, <<'OUT', "load_bytecode" ); 46 .sub main :main 47 load_bytecode "$lib" 48 goto OK 49 NOK: 50 print "not " 51 OK: 52 print "ok" 53 END: 54 print "\\n" 36 .sub DE_load_bytecode 37 load_bytecode 'Data/Escape.pir' 38 ok(1, 'load_bytecode') 55 39 .end 56 CODE57 ok58 OUT59 40 60 ## get_global tests 61 for my $sub (@subs) { 62 pir_output_is( <<CODE, <<'OUT', "get_global ['$sub']" ); 63 .sub main :main 64 load_bytecode "$lib" 65 .local pmc sub 66 sub = get_global ['$ns'], "$sub" 67 goto OK 68 NOK: 69 print "not " 70 OK: 71 print "ok" 72 END: 73 print "\\n" 41 .sub DE_get_global 42 .local pmc sub_list, sub_obj 43 .local string test_message 44 45 $S0 = 'String' 46 sub_list = split ' ', $S0 47 48 LOOP: 49 $I0 = elements sub_list 50 if $I0 == 0 goto END_TEST 51 $S0 = sub_list.'shift'() 52 test_message = concat "get_global ['Data::Escape'], '", $S0 53 test_message = concat test_message, "'" 54 sub_obj = get_global ['Data::Escape'], $S0 55 ok(1, test_message) 56 57 END_TEST: 74 58 .end 75 CODE76 ok77 OUT78 } ## end get_global tests79 59 80 pir_output_is( $PRE . <<'CODE' . $POST, <<'OUT', "escape_string: empty string" ); 60 .sub DE_escape_string_empty_string 61 .local pmc escape_string 62 escape_string = get_global ['Data::Escape'], 'String' 63 81 64 .local string str 82 65 str = "" 83 66 str = escape_string( str, '"' ) 67 is(str, '', 'escape_string: empty string') 68 .end 84 69 85 print str 86 goto OK 87 CODE 88 ok 89 OUT 70 .sub DE_escape_string_no_escapes 71 .local pmc escape_string 72 escape_string = get_global ['Data::Escape'], 'String' 90 73 91 pir_output_is( $PRE . <<'CODE' . $POST, <<'OUT', "escape_string: no escapes" );92 74 .local string str 93 94 75 str = "abc 123" 95 76 str = escape_string( str, '"' ) 77 is(str, 'abc 123', 'escape_string: no escapes') 78 .end 96 79 97 print str 98 goto END 99 CODE 100 abc 123 101 OUT 80 .sub DE_escape_string_tab_carriage_return_linefeed 81 .local pmc escape_string 82 escape_string = get_global ['Data::Escape'], 'String' 102 83 103 pir_output_is( $PRE . <<'CODE' . $POST, <<'OUT', "escape_string: tab, carriage return, linefeed" );104 84 .local string str 105 106 85 str = "a\tb\nc" 107 86 str = escape_string( str, '"' ) 87 is(str, 'a\tb\nc', 'escape_string: tab, carriage return, linefeed') 88 .end 108 89 109 print str 110 goto END 111 CODE 112 a\tb\nc 113 OUT 90 .sub DE_escape_string_other_characters_less_than_32 91 .local pmc escape_string 92 escape_string = get_global ['Data::Escape'], 'String' 114 93 115 pir_output_is( $PRE . <<CODE . $POST, <<'OUT', "escape_string: other characters less than 32" );116 94 .local string str, x 117 95 118 96 .local int index 119 97 index = 0 120 98 str = '' 121 99 122 LOOP:100 LOOP: 123 101 if index >= 32 goto DONE 124 102 125 103 x = chr index … … 128 106 inc index 129 107 branch LOOP 130 108 131 DONE:109 DONE: 132 110 str = escape_string( str, "'" ) 111 is(str, '\000\001\002\003\004\005\006\007\010\t\n\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037', 'escape_string: other characters less than 32') 112 .end 133 113 134 print str 135 goto END 136 CODE 137 \000\001\002\003\004\005\006\007\010\t\n\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 138 OUT 114 .sub DE_escape_string_single_quote 115 .local pmc escape_string 116 escape_string = get_global ['Data::Escape'], 'String' 139 117 140 pir_output_is( $PRE . <<'CODE' . $POST, <<'OUT', "escape_string: single quote" );141 118 .local string str 142 143 str = "a'b'c'" 119 str = "a'b'c" 144 120 str = escape_string( str, "'" ) 121 is(str, "a\\'b\\'c", 'escape_string: single quote') 122 .end 145 123 146 print str 147 goto END 148 CODE 149 a\'b\'c\' 150 OUT 124 .sub DE_escape_string_double_quote 125 .local pmc escape_string 126 escape_string = get_global ['Data::Escape'], 'String' 151 127 152 pir_output_is( $PRE . <<'CODE' . $POST, <<'OUT', "escape_string: double quote" );153 128 .local string str 154 155 str = 'a"b"c"' 129 str = 'a"b"c' 156 130 str = escape_string( str, '"' ) 131 is(str, 'a\"b\"c', 'escape_string: double quote') 132 .end 157 133 158 print str 159 goto END 160 CODE 161 a\"b\"c\" 162 OUT 134 .sub DE_escape_string_single_and_double_escape_single 135 .local pmc escape_string 136 escape_string = get_global ['Data::Escape'], 'String' 163 137 164 pir_output_is( $PRE . <<'CODE' . $POST, <<'OUT', "escape_string: single double: escape single" );165 138 .local string str 166 167 139 str = "ab\"'\"'c" 168 140 str = escape_string( str, "'" ) 141 is(str, "ab\"\\'\"\\'c",'escape_string: single and double, escape single') 142 .end 169 143 170 print str 171 goto END 172 CODE 173 ab"\'"\'c 174 OUT 144 .sub DE_escape_string_single_and_double_escape_double 145 .local pmc escape_string 146 escape_string = get_global ['Data::Escape'], 'String' 175 147 176 pir_output_is( $PRE . <<'CODE' . $POST, <<'OUT', "escape_string: single & double: escape double" );177 148 .local string str 178 179 149 str = "ab\"'\"'c" 180 150 str = escape_string( str, '"' ) 151 is(str, "ab\\\"'\\\"'c", 'escape_string: single and double, escape double') 152 .end 181 153 182 print str 183 goto END 184 CODE 185 ab\"'\"'c 186 OUT 154 .sub DE_escape_string_backslash 155 .local pmc escape_string 156 escape_string = get_global ['Data::Escape'], 'String' 187 157 188 pir_output_is( $PRE . <<'CODE' . $POST, <<'OUT', "escape_string: backslash" );189 158 .local string str 190 191 159 str = '\ abc \t' 192 160 str = escape_string( str, '"' ) 161 is(str, '\\ abc \\t', 'escape_string: backslash') 162 .end 193 163 194 print str 195 goto END 196 CODE 197 \\ abc \\t 198 OUT 164 .sub DE_escape_string_unprintable_followed_by_numbers 165 .local pmc escape_string 166 escape_string = get_global ['Data::Escape'], 'String' 199 167 200 pir_output_is( $PRE . <<'CODE' . $POST, <<'OUT', "escape_string: unprintable followed by numbers" );201 168 .local string str 202 203 169 str = chr 2 204 170 concat str, '123' 205 171 str = escape_string( str, '"' ) 172 is(str, '\002123', 'escape_string: unprintable followed by numbers') 173 .end 206 174 207 print str 208 goto END 209 CODE 210 \002123 211 OUT 175 .sub DE_escape_string_non_ascii 176 todo(0, 'escape_string: non-ascii', 'test not written') 177 .end 212 178 213 SKIP: { 214 skip 'test not written' => 1; 215 pir_output_is( 216 $PRE . <<'CODE' . $POST, <<'OUT', "escape_string: non-ascii", todo => 'test not written' ); 217 CODE 218 ok 219 OUT 220 } 179 .sub DE_escape_string_freeze_a_simple_pmc 180 .local pmc escape_string 181 escape_string = get_global ['Data::Escape'], 'String' 221 182 222 pir_output_is( $PRE . <<'CODE', <<'OUT', "escape_string: freeze a simple pmc" );223 183 .local pmc original_pmc 224 184 original_pmc = new 'String' 225 185 original_pmc = "ok\n" … … 234 194 pir_code = ".sub test :anon\n$P1 = thaw binary:\"" 235 195 236 196 pir_code .= escaped_frozen_pmc 237 pir_code .= "\"\nprint $P1\n.end\n" 197 pir_code .= "\"\n.return($P1)\n.e" 198 # split sub ending to play nice with some editors 199 pir_code .= "nd\n" 238 200 239 201 .local pmc pir_compiler 240 202 pir_compiler = compreg "PIR" 241 203 242 204 .local pmc compiled_sub 243 205 compiled_sub = pir_compiler(pir_code) 244 compiled_sub() 206 $P0 = compiled_sub() 207 is($P0, "ok\n", 'escape_string: freeze a simple pmc') 245 208 .end 246 CODE247 ok248 OUT249 209 250 my @codes = qw/ 0666 0777 0888 0999 6666 7777 8888 9999/; 210 .sub _unicode_gen 211 .param string codepoint 251 212 252 my $unicode_test = $PRE . << 'CODE' . $POST; 253 .local string str 254 str = unicode:"\u%s" 213 .local string pir_code 214 pir_code = ".sub ugen :anon\n$S0 = unicode:\"\\u" 215 pir_code .= codepoint 216 pir_code .= "\"\n.return($S0)\n.e" 217 # split sub ending to play nice with some editors 218 pir_code .= "nd\n" 219 220 .local pmc pir_compiler, compiled_sub 221 pir_compiler = compreg "PIR" 222 compiled_sub = pir_compiler(pir_code) 223 .tailcall compiled_sub() 224 .end 225 226 .sub DE_unicode_test 227 .local pmc escape_string 228 escape_string = get_global ['Data::Escape'], 'String' 229 230 .local pmc codepoint_list 231 $S0 = '0666 0777 0888 0999 6666 7777 8888 9999' 232 codepoint_list = split ' ', $S0 233 234 .local string s_codepoint, i_codepoint 235 .local string str, expected, test_message 236 237 LOOP: 238 $I0 = elements codepoint_list 239 if $I0 == 0 goto TEST_END 240 s_codepoint = codepoint_list.'shift'() 241 $I1 = s_codepoint 242 i_codepoint = $I1 243 244 expected = concat "\\x{", i_codepoint 245 expected .= "}" 246 test_message = concat "escape_string: unicode: ", s_codepoint 247 str = _unicode_gen(s_codepoint) 248 255 249 str = escape_string( str, '"' ) 256 print str 257 goto END 258 CODE 250 is(str, expected, test_message) 251 goto LOOP 259 252 260 foreach my $codepoint (@codes) { 261 pir_output_is( 262 ( sprintf $unicode_test, $codepoint ), 263 ( sprintf "\\x{%i}\n", $codepoint ), 264 "escape_string: unicode: $codepoint" 265 ); 266 } 253 TEST_END: 254 .end 267 255 268 256 # Local Variables: 269 # mode: cperl 270 # cperl-indent-level: 4 257 # mode: pir 271 258 # fill-column: 100 272 259 # End: 273 # vim: expandtab shiftwidth=4 :260 # vim: expandtab shiftwidth=4 ft=pir: