From 79208173ad07cf09dd04aff7cbf26defa63d70b3 Mon Sep 17 00:00:00 2001 From: Joyce Babu Date: Wed, 17 Jul 2024 00:06:48 +0530 Subject: [PATCH] fix: failing test --- example/advanced.php | 5 ++++- tests/advanced.phpt | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/example/advanced.php b/example/advanced.php index feb55ea..10d35ac 100644 --- a/example/advanced.php +++ b/example/advanced.php @@ -1,7 +1,9 @@ name} logged in at { $date->format("Y-m-d G:i:a") } {LT($date, $deadline) -> + # Select expression only allows string/numeric types as selector. + # We will use STR function to convert the boolean output of LT to string. + log-time = User { $user->name} logged in at { $date->format("Y-m-d G:i:a") } {STR(LT($date, $deadline)) -> [true] before *[false] after } deadline. @@ -30,6 +32,7 @@ function preProcess(string $resource): string $bundle->addFunction('LT', fn ($val1, $val2) => $val1 < $val2); $bundle->addFunction('GTE', fn ($val1, $val2) => $val1 >= $val2); $bundle->addFunction('LTE', fn ($val1, $val2) => $val1 <= $val2); + $bundle->addFunction('STR', fn ($val) => is_bool($val) ? ($val ? "true" : "false") : (string)$val); $bundle->addFunction('OBJ_PROP', fn ($obj, $prop) => $obj->{$prop}); $bundle->addFunction('OBJ_METHOD', fn ($obj, $method, ...$args) => $obj->{$method}(...$args)); diff --git a/tests/advanced.phpt b/tests/advanced.phpt index 1a66ca3..9507097 100644 --- a/tests/advanced.phpt +++ b/tests/advanced.phpt @@ -3,7 +3,7 @@ Advanced example with multiple functions --FILE-- name} logged in at { $date->format("Y-m-d G:i a") } {LT($date, $deadline) -> + log-time = User { $user->name} logged in at { $date->format("Y-m-d G:i a") } {STR(LT($date, $deadline)) -> [true] before *[false] after } deadline. @@ -32,6 +32,7 @@ try { $bundle->addFunction('LT', fn ($val1, $val2) => $val1 < $val2); $bundle->addFunction('GTE', fn ($val1, $val2) => $val1 >= $val2); $bundle->addFunction('LTE', fn ($val1, $val2) => $val1 <= $val2); + $bundle->addFunction('STR', fn ($val) => is_bool($val) ? ($val ? "true" : "false") : (string)$val); $bundle->addFunction('OBJ_PROP', fn ($obj, $prop) => $obj->{$prop}); $bundle->addFunction('OBJ_METHOD', fn ($obj, $method, ...$args) => $obj->{$method}(...$args));