From bd0e31374ac1b0e06df543929e2fa11ab15aff11 Mon Sep 17 00:00:00 2001 From: Muqsit Date: Fri, 30 Sep 2022 13:50:00 +0000 Subject: [PATCH] Add test to check whether a call to a deterministic fn was resolved before evaluation --- tests/ExpressionTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/ExpressionTest.php b/tests/ExpressionTest.php index 5c52e01..871d966 100644 --- a/tests/ExpressionTest.php +++ b/tests/ExpressionTest.php @@ -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); + } } \ No newline at end of file