From c1d69ba561fc37a73b536daa10d7c01dc0c0035f Mon Sep 17 00:00:00 2001 From: Clemens Solar Date: Sun, 4 Feb 2024 20:50:13 +0100 Subject: [PATCH] fix: `.16` should be interpreted as number --- src/lib/openSCAD/parseParameter.ts | 2 +- .../openSCADparseParameters.test.ts.snap | 41 +++++++++++++++++++ tests/fixtures/openSCAD/numbers.scad | 4 ++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/openSCAD/numbers.scad diff --git a/src/lib/openSCAD/parseParameter.ts b/src/lib/openSCAD/parseParameter.ts index 5ccf0c5..5a3eb24 100644 --- a/src/lib/openSCAD/parseParameter.ts +++ b/src/lib/openSCAD/parseParameter.ts @@ -183,7 +183,7 @@ function convertType(rawValue): { value: string | boolean | number; type: ParameterType; } { - if (/^-?\d+(\.\d+)?$/.test(rawValue)) { + if (/^-?\d*(\.\d+)?$/.test(rawValue)) { // Raw value matches something like `123.123` or `123`. return { value: parseFloat(rawValue), type: 'number' }; } else if (rawValue === 'true' || rawValue === 'false') { diff --git a/tests/__snapshots__/openSCADparseParameters.test.ts.snap b/tests/__snapshots__/openSCADparseParameters.test.ts.snap index 6c6ca67..9faa0c3 100644 --- a/tests/__snapshots__/openSCADparseParameters.test.ts.snap +++ b/tests/__snapshots__/openSCADparseParameters.test.ts.snap @@ -503,6 +503,47 @@ exports[`testing parameter parsing of openscad scripts testing newlineAboveVaria ] `; +exports[`testing parameter parsing of openscad scripts testing numbers.scad: numbers.scad 1`] = ` +[ + { + "description": undefined, + "group": undefined, + "name": "number1", + "options": undefined, + "range": undefined, + "type": "number", + "value": 0.16, + }, + { + "description": undefined, + "group": undefined, + "name": "number2", + "options": undefined, + "range": undefined, + "type": "number", + "value": 0.16, + }, + { + "description": undefined, + "group": undefined, + "name": "number3", + "options": undefined, + "range": undefined, + "type": "number", + "value": 0.16, + }, + { + "description": undefined, + "group": undefined, + "name": "number4", + "options": undefined, + "range": undefined, + "type": "number", + "value": 0.16, + }, +] +`; + exports[`testing parameter parsing of openscad scripts testing printables-513382.scad: printables-513382.scad 1`] = ` [ { diff --git a/tests/fixtures/openSCAD/numbers.scad b/tests/fixtures/openSCAD/numbers.scad new file mode 100644 index 0000000..24063a8 --- /dev/null +++ b/tests/fixtures/openSCAD/numbers.scad @@ -0,0 +1,4 @@ +number1 = 0.16; +number2=0.16; +number3=.16; +number4 = .16;