From be3d0b236573607f7490b640d71037b1cd0851d7 Mon Sep 17 00:00:00 2001 From: Joshua Kuestersteffen Date: Mon, 11 Jul 2022 09:37:33 -0500 Subject: [PATCH] Set fixed number of decimal points when passing number params to native --- src/extended-xpath.js | 2 +- test/integration/native/ceiling.spec.js | 1 + test/integration/native/floor.spec.js | 1 + test/unit/extended-xpath.spec.js | 8 ++++---- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/extended-xpath.js b/src/extended-xpath.js index a019e31..b7985ad 100644 --- a/src/extended-xpath.js +++ b/src/extended-xpath.js @@ -177,7 +177,7 @@ module.exports = function(wrapped, extensions) { case 'num': if (arg.v === Infinity) argString += '( 1 div 0)'; else if(arg.v === -Infinity) argString += '(-1 div 0)'; - else argString += arg.v; + else argString += arg.v.toFixed(20); // Prevent JS from converting to scientific notation break; case 'str': { const quote = arg.quote || (arg.v.indexOf('"') === -1 ? '"' : "'"); diff --git a/test/integration/native/ceiling.spec.js b/test/integration/native/ceiling.spec.js index 0a80673..e480fd0 100644 --- a/test/integration/native/ceiling.spec.js +++ b/test/integration/native/ceiling.spec.js @@ -9,6 +9,7 @@ describe('ceiling', () => { assertNumberValue("ceiling(5)", 5); assertNumberValue("ceiling(1.00)", 1); assertNumberValue("ceiling(-1.05)", -1); + assertNumberValue('ceiling(0.0000001)', 1); }); it('ceiling() fails when too many arguments are provided', () => { diff --git a/test/integration/native/floor.spec.js b/test/integration/native/floor.spec.js index 89b1eea..a24f5f7 100644 --- a/test/integration/native/floor.spec.js +++ b/test/integration/native/floor.spec.js @@ -12,6 +12,7 @@ describe('#floor()', () => { assertNumberValue('floor(5)', 5); assertNumberValue('floor(1.00)', 1); assertNumberValue('floor(-1.005)', -2); + assertNumberValue('floor(0.0000001)', 0); }); it('floor() fails when too many arguments are provided', () => { diff --git a/test/unit/extended-xpath.spec.js b/test/unit/extended-xpath.spec.js index e61e7c6..666dce4 100644 --- a/test/unit/extended-xpath.spec.js +++ b/test/unit/extended-xpath.spec.js @@ -70,21 +70,21 @@ var DATE_MATCH = '(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug 'native_function()': /^$/, 'native_function(3)': - /^$/, + /^$/, 'native_function("string-arg")': /^$/, 'native_function(\'string-with-escaped-"-arg\')': /^$/, 'native_function(1, 2, 3, "a", \'b\', "c")': - /^$/, + /^$/, 'native-function()': /^$/, 'native-function(3)': - /^$/, + /^$/, 'native-function("string-arg")': /^$/, 'native-function(1, 2, 3, "a", \'b\', "c")': - /^$/, + /^$/, /* // Not clear what to do here as correcting this requires knowledge of return types of native functions. 'native-function1(native-function2() + native-function3()) + native-function4(native-function5() + native-function6())':