Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.58 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /* This class is part of the XP framework
  3.  *
  4.  * $Id$
  5.  */
  6.  
  7.   $package= 'net.xp_lang.tests.execution.source';
  8.  
  9.   uses('net.xp_lang.tests.execution.source.ExecutionTest');
  10.  
  11.   /**
  12.    * Tests null-safe object operator ?.
  13.    *
  14.    */
  15.   class net·xp_lang·tests·execution·source·NullSafeObjectOperatorTest extends ExecutionTest {
  16.    
  17.     /**
  18.      * Test
  19.      *
  20.      */
  21.     #[@test]
  22.     public function nullDotMethod() {
  23.       $this->assertNull($this->run('$instance= null; return $instance?.method();'));
  24.     }
  25.  
  26.     /**
  27.      * Test
  28.      *
  29.      */
  30.     #[@test]
  31.     public function nullReturnedFromMethod() {
  32.       $this->assertNull($this->run('$v= new util.collections.Vector<var>(); $v.add(null); return $v.get(0)?.hashCode();'));
  33.     }
  34.  
  35.     /**
  36.      * Test
  37.      *
  38.      */
  39.     #[@test]
  40.     public function nullNotReturnedFromMethod() {
  41.       $this->assertNotEquals(NULL, $this->run('$v= new util.collections.Vector<var>(); $v.add($this); return $v.get(0)?.hashCode();'));
  42.     }
  43.  
  44.     /**
  45.      * Test
  46.      *
  47.      */
  48.     #[@test]
  49.     public function twoNullSafeObjectOperatorsInOneChain() {
  50.       $this->assertNull($this->run('$v= new util.collections.Vector<var>(); $v.add(null); return $v?.get(0)?.hashCode();'));
  51.     }
  52.  
  53.     /**
  54.      * Test
  55.      *
  56.      */
  57.     #[@test]
  58.     public function nullDotProperty() {
  59.       $this->assertNull($this->run('$instance= null; return $instance?.property;'));
  60.     }
  61.  
  62.     /**
  63.      * Test
  64.      *
  65.      */
  66.     #[@test, @ignore('Generates syntax error, unexpected ")"')]
  67.     public function nullDotInvoke() {
  68.       $this->compile('$instance= null; return $instance?.();');
  69.     }
  70.   }
  71. ?>