Exemple #1
0
 public function testFun()
 {
     $f = Ginq::fun(array('x,y' => 'x+y+z', 'z' => 4));
     $this->assertEquals(9, $f(2, 3));
     $f = Ginq::fun(array('x, x' => 'x'));
     $this->assertEquals(4, $f(5, 4));
     $f = Ginq::fun(array('x, x' => 'x', 'x' => 3));
     $this->assertEquals(3, $f(5, 4));
     $f = Ginq::fun(array('' => 'z', 'z' => 4));
     $this->assertEquals(4, $f());
     try {
         Ginq::fun("");
         $this->fail();
     } catch (InvalidArgumentException $e) {
         $this->assertTrue(true);
     }
     try {
         Ginq::fun(array());
         $this->fail();
     } catch (InvalidArgumentException $e) {
         $this->assertTrue(true);
     }
     try {
         Ginq::fun(array(',x,y' => 'x+y'));
         $this->fail();
     } catch (SyntaxError $e) {
         $this->assertTrue(true);
     }
     try {
         Ginq::fun(array(',x,y' => 'x+y'));
         $this->fail();
     } catch (SyntaxError $e) {
         $this->assertTrue(true);
     }
     try {
         Ginq::fun(array('x,y,' => 'x+y'));
         $this->fail();
     } catch (SyntaxError $e) {
         $this->assertTrue(true);
     }
     try {
         Ginq::fun(array('x,y' => 'x+y+z', 'a' => 4));
         $this->fail();
     } catch (SyntaxError $e) {
         $prev = $e->getPrevious();
         if ($prev instanceof \Symfony\Component\ExpressionLanguage\SyntaxError) {
             $this->assertTrue(true);
         } else {
             $this->fail();
         }
     }
 }