|
189 | 189 | end |
190 | 190 |
|
191 | 191 | context "instance method calls" do |
192 | | - #it "should support instance method calls" # TODO |
| 192 | + it "should support instance method calls" do |
| 193 | + phpize('$object.method').should == '$object->method()' |
| 194 | + phpize{ $object.method }.should == '$object->method()' |
| 195 | + end |
| 196 | + end |
| 197 | + |
| 198 | + context "string operators" do |
| 199 | + it "should support the . (concatenation) operator" do |
| 200 | + phpize('"123" << "456"').should == '"123" . "456"' |
| 201 | + phpize{ "123" << "456" }.should == '"123" . "456"' |
| 202 | + end |
193 | 203 | end |
194 | 204 |
|
195 | 205 | context "arithmetic operators" do |
|
246 | 256 | end |
247 | 257 |
|
248 | 258 | context "bitwise operators" do |
| 259 | + it "should support the ~ (bitwise not) operator" do |
| 260 | + phpize('~1').should == '~1' |
| 261 | + phpize{ ~1 }.should == '~1' |
| 262 | + phpize('~$x').should == '~$x' |
| 263 | + phpize{ ~$x }.should == '~$x' |
| 264 | + end |
| 265 | + |
249 | 266 | it "should support the & (bitwise and) operator" do |
250 | 267 | phpize('1 & 0').should == '1 & 0' |
251 | 268 | phpize{ 1 & 0 }.should == '1 & 0' |
|
267 | 284 | phpize{ $a ^ $b }.should == '$a ^ $b' |
268 | 285 | end |
269 | 286 |
|
270 | | - it "should support the ~ (bitwise not) operator" do |
271 | | - phpize('~1').should == '~1' |
272 | | - phpize{ ~1 }.should == '~1' |
273 | | - phpize('~$x').should == '~$x' |
274 | | - phpize{ ~$x }.should == '~$x' |
275 | | - end |
276 | | - |
277 | 287 | #it "should support the << (bitwise left shift) operator" # TODO |
278 | 288 |
|
279 | 289 | it "should support the >> (bitwise right shift) operator" do |
|
361 | 371 | end |
362 | 372 | end |
363 | 373 |
|
364 | | - context "string operators" do |
365 | | - it "should support the . (concatenation) operator" do |
366 | | - phpize('"123" << "456"').should == '"123" . "456"' |
367 | | - phpize{ "123" << "456" }.should == '"123" . "456"' |
368 | | - end |
369 | | - end |
370 | | - |
371 | 374 | context "control structures" do |
372 | | - it "should support return statements" do |
373 | | - phpize('return').should == 'return' |
374 | | - phpize{ return }.should == 'return' |
375 | | - phpize('return nil').should == 'return NULL' |
376 | | - phpize{ return nil }.should == 'return NULL' |
377 | | - phpize('return true').should == 'return TRUE' |
378 | | - phpize{ return true }.should == 'return TRUE' |
379 | | - phpize('return 42').should == 'return 42' |
380 | | - phpize{ return 42 }.should == 'return 42' |
| 375 | + it "should support if statement modifiers" do |
| 376 | + phpize('return if true').should == 'if (TRUE) { return; }' |
| 377 | + phpize{ return if true }.should == 'if (TRUE) { return; }' |
381 | 378 | end |
382 | 379 |
|
383 | 380 | it "should support if statements with an empty then branch" do |
|
397 | 394 |
|
398 | 395 | #it "should support if/elseif statements" # TODO |
399 | 396 |
|
| 397 | + it "should support unless statement modifiers" do |
| 398 | + phpize('return unless true').should == 'if (!TRUE) { return; }' |
| 399 | + phpize{ return unless true }.should == 'if (!TRUE) { return; }' |
| 400 | + end |
| 401 | + |
400 | 402 | it "should support unless statements with an empty then branch" do |
401 | 403 | # FIXME: the parse tree for this is at present indistinguishable from |
402 | 404 | # "if true then end", so there probably is a bug in RubyParser: |
|
416 | 418 | phpize{ unless false then 1 else 0 end }.should == 'if (FALSE) { 0; } else { 1; }' |
417 | 419 | end |
418 | 420 |
|
419 | | - #it "should support while statements" # TODO |
| 421 | + it "should support while statements" do |
| 422 | + phpize('while true; sleep 1; end').should == 'while (TRUE) { sleep(1); }' |
| 423 | + phpize{ while true; sleep 1; end }.should == 'while (TRUE) { sleep(1); }' |
| 424 | + end |
| 425 | + |
| 426 | + it "should support until statements" do |
| 427 | + phpize('until true; sleep 1; end').should == 'while (!TRUE) { sleep(1); }' |
| 428 | + phpize{ until true; sleep 1; end }.should == 'while (!TRUE) { sleep(1); }' |
| 429 | + end |
| 430 | + |
420 | 431 | #it "should support do-while statements" # TODO |
421 | | - #it "should support for statements" # TODO |
422 | | - #it "should support foreach statements" # TODO |
| 432 | + |
| 433 | + it "should support for statements" do |
| 434 | + phpize('for $x in [1, 2, 3]; echo $x; end').should == 'foreach (array(1, 2, 3) as $x) { echo($x); }' |
| 435 | + phpize{ for $x in [1, 2, 3]; echo $x; end }.should == 'foreach (array(1, 2, 3) as $x) { echo($x); }' |
| 436 | + phpize('for $k, $v in {"a" => 1}; echo $k << $v; end').should == 'foreach (array("a" => 1) as $k => $v) { echo($k . $v); }' |
| 437 | + phpize{ for $k, $v in {"a" => 1}; echo $k << $v; end }.should == 'foreach (array("a" => 1) as $k => $v) { echo($k . $v); }' |
| 438 | + end |
| 439 | + |
423 | 440 | #it "should support break statements" # TODO |
424 | 441 | #it "should support continue statements" # TODO |
| 442 | + |
| 443 | + it "should support return statements" do |
| 444 | + phpize('return').should == 'return' |
| 445 | + phpize{ return }.should == 'return' |
| 446 | + phpize('return nil').should == 'return NULL' |
| 447 | + phpize{ return nil }.should == 'return NULL' |
| 448 | + phpize('return true').should == 'return TRUE' |
| 449 | + phpize{ return true }.should == 'return TRUE' |
| 450 | + phpize('return 42').should == 'return 42' |
| 451 | + phpize{ return 42 }.should == 'return 42' |
| 452 | + end |
| 453 | + |
425 | 454 | #it "should support switch statements" # TODO |
426 | 455 | end |
427 | 456 |
|
|
0 commit comments