Fix the last test

Test was looking for `lineTo` as a substring of the input KCL program.
But there's no more lineTo function, so I changed it to look for
line() with an endAbsolute arg, which is the new equivalent.

Also changed the getConstraintInfo code to look up the lineTo if using
line with endAbsolute.
This commit is contained in:
Adam Chalmers
2025-01-15 15:38:15 -06:00
committed by Nick Cameron
parent 99866b5f9a
commit 10c446151b
3 changed files with 9 additions and 6 deletions

View File

@ -881,7 +881,7 @@ describe('testing getConstraintInfo', () => {
offset = 0 + 0
}, %)
|> tangentialArcTo([3.14 + 0, 13.14 + 0], %)`
test.each([
test.only.each([
[
'line',
[
@ -929,7 +929,7 @@ describe('testing getConstraintInfo', () => {
],
],
[
'lineTo',
'line(endAbsolute',
[
{
type: 'xAbsolute',
@ -938,7 +938,7 @@ describe('testing getConstraintInfo', () => {
sourceRange: [expect.any(Number), expect.any(Number), true],
argPosition: { type: 'arrayItem', index: 0 },
pathToNode: expect.any(Array),
stdLibFnName: 'lineTo',
stdLibFnName: 'line',
},
{
type: 'yAbsolute',
@ -947,7 +947,7 @@ describe('testing getConstraintInfo', () => {
sourceRange: [expect.any(Number), expect.any(Number), true],
argPosition: { type: 'arrayItem', index: 1 },
pathToNode: expect.any(Array),
stdLibFnName: 'lineTo',
stdLibFnName: 'line',
},
],
],

View File

@ -631,7 +631,7 @@ export const lineTo: SketchLineHelperKw = {
getConstraintInfo: (callExp, ...args) =>
commonConstraintInfoHelper(
callExp,
['xRelative', 'yRelative'],
['xAbsolute', 'yAbsolute'],
'line',
[{ arrayInput: 0 }, { arrayInput: 1 }],
...args
@ -2053,8 +2053,10 @@ export function getConstraintInfoKw(
pathToNode: PathToNode
): ConstrainInfo[] {
const fnName = callExpression?.callee?.name || ''
const isAbsolute = findKwArg('endAbsolute', callExpression) !== undefined
if (!(fnName in sketchLineHelperMapKw)) return []
return sketchLineHelperMapKw[fnName].getConstraintInfo(
const correctFnName = fnName === 'line' && isAbsolute ? 'lineTo' : fnName
return sketchLineHelperMapKw[correctFnName].getConstraintInfo(
callExpression,
code,
pathToNode

View File

@ -245,6 +245,7 @@ export const parse = (code: string | Error): ParseResult | Error => {
return new ParseResult(parsed[0], errs.errors, errs.warnings)
} catch (e: any) {
// throw e
console.error(e.toString())
const parsed: RustKclError = JSON.parse(e.toString())
return new KCLError(
parsed.kind,