From 09dba374ce9475e5fb08eee4d99de59bd72a2c8b Mon Sep 17 00:00:00 2001 From: Andrew Coleman Date: Tue, 14 Jan 2025 14:23:23 +0000 Subject: [PATCH] $pad function to truncate fractional part of numeric argument Signed-off-by: Andrew Coleman --- src/functions.js | 1 + test/test-suite/groups/function-pad/case011.json | 6 ++++++ test/test-suite/groups/function-pad/case012.json | 6 ++++++ 3 files changed, 13 insertions(+) create mode 100644 test/test-suite/groups/function-pad/case011.json create mode 100644 test/test-suite/groups/function-pad/case012.json diff --git a/src/functions.js b/src/functions.js index d493c946..c3fff7a4 100644 --- a/src/functions.js +++ b/src/functions.js @@ -293,6 +293,7 @@ const functions = (() => { } var result; + width = Math.trunc(width); var padLength = Math.abs(width) - length(str); if (padLength > 0) { var padding = (new Array(padLength + 1)).join(char); diff --git a/test/test-suite/groups/function-pad/case011.json b/test/test-suite/groups/function-pad/case011.json new file mode 100644 index 00000000..f7dbc539 --- /dev/null +++ b/test/test-suite/groups/function-pad/case011.json @@ -0,0 +1,6 @@ +{ + "expr": "$pad('foo', 5.7, ' ')", + "dataset": null, + "bindings": {}, + "result": "foo " +} \ No newline at end of file diff --git a/test/test-suite/groups/function-pad/case012.json b/test/test-suite/groups/function-pad/case012.json new file mode 100644 index 00000000..502d0754 --- /dev/null +++ b/test/test-suite/groups/function-pad/case012.json @@ -0,0 +1,6 @@ +{ + "expr": "$pad('foo', -5.7, ' ')", + "dataset": null, + "bindings": {}, + "result": " foo" +} \ No newline at end of file