Revision 26750
- Date:
- 2009/05/10 10:55:39
- Files:
Legend:
- Added
- Removed
- Modified
-
t/spec/S02-whitespace_and_comments/unspace.t
48 48 49 49 #Test the "unspace" and unspace syntax 50 50 51 class Str is also { 52 method id($x:) { $x } 53 } 54 51 55 #This makes 'foo.id' and 'foo .id' mean different things 52 #This makes 'foo.lc' and 'foo .lc' mean different things 56 53 multi foo() { 'a' } 57 54 multi foo($x) { $x } 58 55 … … 61 58 62 59 $_ = 'b'; 63 60 64 is((foo.id ), 'a', 'sanity - foo.id'); 65 is((foo .id ), 'b', 'sanity - foo .id'); 66 is((bar.id ), 'a', 'sanity - bar.id'); 67 is((bar .id ), 'b', 'sanity - bar .id'); 68 is((foo\.id ), 'a', 'short unspace'); 69 is((foo\ .id ), 'a', 'unspace'); 70 is((foo \ .id), 'b', 'not a unspace'); 71 eval_dies_ok('fo\ o.id', 'unspace not allowed in identifier'); 72 is(eval('foo\ .id'), 'a', 'longer dot'); 73 is(eval('foo\#( comment ).id'), 'a', 'unspace with embedded comment'); 61 is((foo.lc ), 'a', 'sanity - foo.lc'); 62 is((foo .lc ), 'b', 'sanity - foo .lc'); 63 is((bar.lc ), 'a', 'sanity - bar.lc'); 64 is((bar .lc ), 'b', 'sanity - bar .lc'); 65 is((foo\.lc ), 'a', 'short unspace'); 66 is((foo\ .lc ), 'a', 'unspace'); 67 is((foo \ .lc), 'b', 'not a unspace'); 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'); 74 71 #?rakudo skip 'unimplemented' 75 eval_dies_ok('foo\#\ ( comment ).id', 'unspace can\'t hide space between # and opening bracket'); 72 eval_dies_ok('foo\#\ ( comment ).lc', 'unspace can\'t hide space between # and opening bracket'); 76 73 is((foo\ # comment 77 .id), 'a', 'unspace with end-of-line comment'); 74 .lc), 'a', 'unspace with end-of-line comment'); 78 75 is((:foo\ <bar>), (:foo<bar>), 'unspace in colonpair'); 79 76 #?rakudo skip 'unimplemented' 80 77 is((foo\ .\ ("x")), 'x', 'unspace is allowed both before and after method .'); … … 82 79 =begin comment 83 80 blah blah blah 84 81 =end comment 85 .id'), 'a', 'unspace with pod =begin/=end comment'); 82 .lc'), 'a', 'unspace with pod =begin/=end comment'); 86 83 #?rakudo skip '=for pod not implemented (in STD.pm)' 87 84 { 88 85 is(eval('foo\ … … 91 88 blah 92 89 blah 93 90 94 .id'), 'a', 'unspace with pod =for comment'); 91 .lc'), 'a', 'unspace with pod =for comment'); 95 92 } 96 93 is(eval('foo\ 97 94 =comment blah blah blah 98 .id'), 'a', 'unspace with pod =comment'); 95 .lc'), 'a', 'unspace with pod =comment'); 99 96 #This is pretty strange: according to Perl-6.0.0-STD.pm, 100 97 #unspace is allowed after a pod = ... which means pod is 101 98 #syntactically recursive, i.e. you can put pod comments … … 104 101 =\ begin comment 105 102 blah blah blah 106 103 =\ end comment 107 .id'), 'a', 'unspace with pod =begin/=end comment w/ pod unspace'); 104 .lc'), 'a', 'unspace with pod =begin/=end comment w/ pod unspace'); 108 105 #?rakudo skip '=for pod not implemented (in STD.pm)' 109 106 { 110 107 is(eval('foo\ … … 113 110 blah 114 111 blah 115 112 116 .id'), 'a', 'unspace with pod =for comment w/ pod unspace'); 113 .lc'), 'a', 'unspace with pod =for comment w/ pod unspace'); 117 114 } 118 115 is(eval('foo\ 119 116 =\ comment blah blah blah 120 .id'), 'a', 'unspace with pod =comment w/ pod unspace'); 117 .lc'), 'a', 'unspace with pod =comment w/ pod unspace'); 121 118 is(eval('foo\ 122 119 =\ 123 120 =begin nested pod … … 130 127 blah blah blah 131 128 =end nested pod 132 129 end comment 133 .id'), 'a', 'unspace with pod =begin/=end comment w/ pod-in-pod'); 130 .lc'), 'a', 'unspace with pod =begin/=end comment w/ pod-in-pod'); 134 131 #?rakudo skip '=for pod not implemented (in STD.pm)' 135 132 { 136 133 is(eval('foo\ … … 145 142 blah 146 143 blah 147 144 148 .id'), 'a', 'unspace with pod =for commenti w/ pod-in-pod'); 145 .lc'), 'a', 'unspace with pod =for commenti w/ pod-in-pod'); 149 146 is(eval('foo\ 150 147 =\ 151 148 =nested pod blah blah blah 152 149 comment blah blah blah 153 .id'), 'a', 'unspace with pod =comment w/ pod-in-pod'); 150 .lc'), 'a', 'unspace with pod =comment w/ pod-in-pod'); 154 151 is(eval('foo\ 155 152 =\ #1 156 153 =\ #2 … … 177 174 178 175 comment blah blah blah #6 179 176 end comment #5 180 .id'), 'a', 'hideous nested pod torture test'); 177 .lc'), 'a', 'hideous nested pod torture test'); 181 178 182 179 } 183 180 … … 193 190 # L<S06/"Blocks"/"unless followed immediately by a comma"> 194 191 # 195 192 { 196 sub baz(Code $x, *@y) { $x.(@y) } 193 sub baz(Code $x, *@y) { $x.(@y) } 197 194 198 is(eval('baz { @^x }, 1, 2, 3'), (1, 2, 3), 'comma immediately following arg block'); 199 is(eval('baz { @^x } , 1, 2, 3'), (1, 2, 3), 'comma not immediately following arg block'); 200 is(eval('baz { @^x }\ , 1, 2, 3'), (1, 2, 3), 'unspace then comma following arg block'); 201 202 class Code is also { 203 method xyzzy(Code $x: *@y) { $x.(@y) } 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'); 204 198 } 205 199 206 #?rakudo 3 skip 'indirect method calls' 207 is(eval('xyzzy { @^x }: 1, 2, 3'), (1, 2, 3), 'colon immediately following arg block'); 208 is(eval('xyzzy { @^x } : 1, 2, 3'), (1, 2, 3), 'colon not immediately following arg block'); 209 is(eval('xyzzy { @^x }\ : 1, 2, 3'), (1, 2, 3), 'unspace then colon following arg block'); 200 #?rakudo skip 'indirect method calls' 201 { 202 augment class Code{ 203 method xyzzy(Code $x: *@y) { $x.(@y) } 204 } 205 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'); 209 } 210 210 } 211 211 212 212 # L<S02/"Whitespace and Comments"/"natural conflict between postfix operators and infix operators"> … … 215 215 # ($n++) $m 216 216 # ($n) (++$m) 217 217 # ($n) + (+$m) 218 218 219 #?rakudo skip 'defining new operators' 219 220 { 220 221 my $n = 1; … … 281 282 is eval('.123'), 0.123, '.123 is equal to 0.123'; 282 283 } 283 284 285 # vim: ft=perl6