Revision 26751
- Date:
- 2009/05/10 10:55:44
- Files:
Legend:
- Added
- Removed
- Modified
-
t/spec/S02-whitespace_and_comments/unspace.t
2 2 3 3 use Test; 4 4 5 plan 76; 5 plan 75; 6 6 7 7 # L<S02/"Whitespace and Comments"/This is known as the "unspace"> 8 8 … … 66 66 is((foo\ .lc ), 'a', 'unspace'); 67 67 is((foo \ .lc), 'b', 'not a unspace'); 68 68 eval_dies_ok('fo\ o.lc', 'unspace not allowed in identifier'); 69 is(eval('foo\ .lc'), 'a', 'longer dot'); 70 is(eval('foo\#( comment ).lc'), 'a', 'unspace with embedded comment'); 69 is((foo\ .lc), 'a', 'longer dot'); 70 is((foo\#( comment ).lc), 'a', 'unspace with embedded comment'); 71 71 #?rakudo skip 'unimplemented' 72 72 eval_dies_ok('foo\#\ ( comment ).lc', 'unspace can\'t hide space between # and opening bracket'); 73 73 is((foo\ # comment … … 75 75 is((:foo\ <bar>), (:foo<bar>), 'unspace in colonpair'); 76 76 #?rakudo skip 'unimplemented' 77 77 is((foo\ .\ ("x")), 'x', 'unspace is allowed both before and after method .'); 78 is(eval('foo\ 78 is((foo\ 79 79 =begin comment 80 80 blah blah blah 81 81 =end comment 82 .lc'), 'a', 'unspace with pod =begin/=end comment'); 82 .lc), 'a', 'unspace with pod =begin/=end comment'); 83 83 #?rakudo skip '=for pod not implemented (in STD.pm)' 84 84 { 85 is(eval('foo\ 85 is((foo\ 86 86 =for comment 87 87 blah 88 88 blah 89 89 blah 90 90 91 .lc'), 'a', 'unspace with pod =for comment'); 91 .lc), 'a', 'unspace with pod =for comment'); 92 92 } 93 93 is(eval('foo\ 94 94 =comment blah blah blah … … 181 181 # L<S04/"Statement-ending blocks"/"Because subroutine declarations are expressions"> 182 182 #XXX probably shouldn't be in this file... 183 183 184 { 185 eval('sub f { 3 } sub g { 3 }'); 186 eval_dies_ok('f', 'semicolon or newline required between blocks'); 187 eval_dies_ok('g', 'semicolon or newline required between blocks'); 188 } 184 eval_dies_ok('sub f { 3 } sub g { 3 }', 'semicolon or newline required between blocks'); 189 185 190 186 # L<S06/"Blocks"/"unless followed immediately by a comma"> 191 187 # 192 188 { 193 189 sub baz(Code $x, *@y) { $x.(@y) } 194 190 195 is(eval('baz { @^x }, 1, 2, 3'), (1, 2, 3), 'comma immediately following arg block'); 196 is(eval('baz { @^x } , 1, 2, 3'), (1, 2, 3), 'comma not immediately following arg block'); 197 is(eval('baz { @^x }\ , 1, 2, 3'), (1, 2, 3), 'unspace then comma following arg block'); 191 is((baz { @^x }, 1, 2, 3), (1, 2, 3), 'comma immediately following arg block'); 192 is((baz { @^x } , 1, 2, 3), (1, 2, 3), 'comma not immediately following arg block'); 193 is((baz { @^x }\ , 1, 2, 3), (1, 2, 3), 'unspace then comma following arg block'); 198 194 } 199 195 200 196 #?rakudo skip 'indirect method calls' … … 203 199 method xyzzy(Code $x: *@y) { $x.(@y) } 204 200 } 205 201 206 is(eval('xyzzy { @^x }: 1, 2, 3'), (1, 2, 3), 'colon immediately following arg block'); 207 is(eval('xyzzy { @^x } : 1, 2, 3'), (1, 2, 3), 'colon not immediately following arg block'); 208 is(eval('xyzzy { @^x }\ : 1, 2, 3'), (1, 2, 3), 'unspace then colon following arg block'); 202 is((xyzzy { @^x }: 1, 2, 3), (1, 2, 3), 'colon immediately following arg block'); 203 is((xyzzy { @^x } : 1, 2, 3), (1, 2, 3), 'colon not immediately following arg block'); 204 is((xyzzy { @^x }\ : 1, 2, 3), (1, 2, 3), 'unspace then colon following arg block'); 209 205 } 210 206 } 211 207 … … 223 219 sub infix:<++>($x, $y) { 42 } 224 220 225 221 #'$n++$m' should be a syntax error 226 #?rakudo 3 skip 'test dependency' 227 222 eval_dies_ok('$n++$m', 'infix requires space when ambiguous with postfix'); 228 223 is($n, 1, 'check $n'); 229 224 is($m, 2, 'check $m'); … … 251 246 252 247 #Unspace inside operator splits it 253 248 $n = 1; $m = 2; 254 is(eval('$n+\ +$m'), 3, 'unspace inside operator splits it'); 249 is(($n+\ +$m), 3, 'unspace inside operator splits it'); 255 250 is($n, 1, 'check $n'); 256 251 is($m, 2, 'check $m'); 257 252 … … 260 255 is($n, 1, 'check $n'); 261 256 262 257 $n = 1; 263 is(eval('$n.++'), 1, 'postfix dot'); 258 is($n.++, 1, 'postfix dot'); 264 259 is($n, 2, 'check $n'); 265 260 266 261 $n = 1; 267 is(eval('$n\ ++'), 1, 'postfix unspace'); 262 is($n\ ++, 1, 'postfix unspace'); 268 263 is($n, 2, 'check $n'); 269 264 270 265 $n = 1; 271 is(eval('$n\ .++'), 1, 'postfix unspace'); 266 is($n\ .++, 1, 'postfix unspace'); 272 267 is($n, 2, 'check $n'); 273 268 274 269 # L<S02/"Lexical Conventions"/"U+301D codepoint has two closing alternatives"> 275 is(eval('foo\#〝 comment 〞.id'), 'a', 'unspace with U+301D/U+301E comment'); 270 is((foo\#〝 comment 〞.id), 'a', 'unspace with U+301D/U+301E comment'); 276 271 eval_dies_ok('foo\#〝 comment 〟.id', 'unspace with U+301D/U+301F is invalid'); 277 272 278 273 # L<S02/"Whitespace and Comments"/".123"> 279 274 # .123 is equal to 0.123 280 275 281 is eval(' .123'), 0.123, ' .123 is equal to 0.123'; 282 is eval('.123'), 0.123, '.123 is equal to 0.123'; 276 is ( .123), 0.123, ' .123 is equal to 0.123'; 277 is (.123), 0.123, '.123 is equal to 0.123'; 283 278 } 284 279 285 280 # vim: ft=perl6