Skip to content

Commit

Permalink
Add test to check whether a call to a deterministic fn was resolved b…
Browse files Browse the repository at this point in the history
…efore evaluation
  • Loading branch information
Muqsit committed Sep 30, 2022
1 parent f270fb7 commit bd0e313
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/ExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,19 @@ public function testFunctionCallOrder() : void{
$do_capture(static fn() => $fcall_order_test_fn(1) + $fcall_order_test_fn(2, $fcall_order_test_fn(3), $fcall_order_test_fn(4)) ** $fcall_order_test_fn(5, $fcall_order_test_fn(6)))
);
}

public function testDeterministicFunctionCall() : void{
$disable_fcall = false;
$deterministic_fn = static function(int $value) use(&$disable_fcall) : int{
if($disable_fcall){
throw new RuntimeException("Attempted to call disabled function");
}
return $value;
};

$this->getParser()->getFunctionRegistry()->register("deterministic_fn", $deterministic_fn, true);
$expression = $this->getParser()->parse("2 ** deterministic_fn(2) + deterministic_fn(deterministic_fn(4))");
$disable_fcall = true;
$this->assertEquals($expression->evaluate(), 2 ** 2 + 4);
}
}

0 comments on commit bd0e313

Please sign in to comment.