Skip to content

Commit

Permalink
fix: .16 should be interpreted as number
Browse files Browse the repository at this point in the history
  • Loading branch information
seasick committed Feb 4, 2024
1 parent aec2430 commit c1d69ba
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/openSCAD/parseParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
41 changes: 41 additions & 0 deletions tests/__snapshots__/openSCADparseParameters.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
[
{
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/openSCAD/numbers.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
number1 = 0.16;
number2=0.16;
number3=.16;
number4 = .16;

0 comments on commit c1d69ba

Please sign in to comment.