mirror of
https://github.com/flextype/flextype.git
synced 2025-08-06 13:16:45 +02:00
feat(expressions): add new round
and abs
expressions
This commit is contained in:
@@ -26,6 +26,8 @@ class MathExpression implements ExpressionFunctionProviderInterface
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new ExpressionFunction('abs', static fn (int|float $num): mixed => '\abs($num)', static fn (array $arguments, int|float $num): mixed => \abs($num)),
|
||||
new ExpressionFunction('round', static fn (int|float $num, int $precision = 0, int $mode = 1): mixed => '\round($num, $precision, $mode)', static fn (array $arguments, int|float $num, int $precision = 0, int $mode = 1): mixed => \round($num, $precision, $mode)),
|
||||
new ExpressionFunction('ceil', static fn (int|float $num): mixed => '\ceil($num)', static fn (array $arguments, int|float $num): mixed => \ceil($num)),
|
||||
new ExpressionFunction('floor', static fn (int|float $num): mixed => '\floor($num)', static fn (array $arguments, int|float $num): mixed => \floor($num)),
|
||||
new ExpressionFunction('min', static fn (mixed ...$values): mixed => '\min($values)', static fn (array $arguments, mixed ...$values): mixed => \min($values)),
|
||||
|
@@ -30,4 +30,14 @@ test('min expression', function () {
|
||||
test('max expression', function () {
|
||||
entries()->create('max', ['test' => '[[ max(2, 3, 1, 6, 7) ]]']);
|
||||
expect(entries()->fetch('max')['test'])->toBe('7');
|
||||
});
|
||||
|
||||
test('abs expression', function () {
|
||||
entries()->create('abs', ['test' => '[[ abs(-4.2) ]]']);
|
||||
expect(entries()->fetch('abs')['test'])->toBe('4.2');
|
||||
});
|
||||
|
||||
test('round expression', function () {
|
||||
entries()->create('round', ['test' => '[[ round(3.4) ]]']);
|
||||
expect(entries()->fetch('round')['test'])->toBe('3');
|
||||
});
|
Reference in New Issue
Block a user