Fix up frontend unit tests
This commit is contained in:
@ -9,6 +9,7 @@ import {
|
||||
} from './wasm'
|
||||
import { ImportStatement } from 'wasm-lib/kcl/bindings/ImportStatement'
|
||||
import { Node } from 'wasm-lib/kcl/bindings/Node'
|
||||
import { ARG_INDEX_FIELD, LABELED_ARG_FIELD } from './queryAst'
|
||||
|
||||
function moreNodePathFromSourceRange(
|
||||
node: Node<
|
||||
@ -76,7 +77,8 @@ function moreNodePathFromSourceRange(
|
||||
const arg = args[argIndex].arg
|
||||
if (arg.start <= start && arg.end >= end) {
|
||||
path.push(['arguments', 'CallExpressionKw'])
|
||||
path.push([argIndex, 'index'])
|
||||
path.push([argIndex, ARG_INDEX_FIELD])
|
||||
path.push(['arg', LABELED_ARG_FIELD])
|
||||
return moreNodePathFromSourceRange(arg, sourceRange, path)
|
||||
}
|
||||
}
|
||||
|
||||
@ -882,7 +882,6 @@ describe('testing getConstraintInfo', () => {
|
||||
offset = 0 + 0
|
||||
}, %)
|
||||
|> tangentialArcTo([3.14 + 0, 13.14 + 0], %)`
|
||||
const ast = assertParse(code)
|
||||
test.each([
|
||||
[
|
||||
'line',
|
||||
|
||||
@ -148,10 +148,10 @@ const constrainInfo = (
|
||||
g === 'singleValue'
|
||||
? { type: 'singleValue' }
|
||||
: typeof g === 'number'
|
||||
? { type: 'arrayItem', index: g }
|
||||
: typeof g === 'string'
|
||||
? { type: 'objectProperty', key: g }
|
||||
: undefined,
|
||||
? { type: 'arrayItem', index: g }
|
||||
: typeof g === 'string'
|
||||
? { type: 'objectProperty', key: g }
|
||||
: undefined,
|
||||
pathToNode: e,
|
||||
stdLibFnName: f,
|
||||
})
|
||||
@ -226,39 +226,39 @@ const commonConstraintInfoHelper = (
|
||||
const pathToFirstArg: PathToNode = isArr
|
||||
? [...pathToArrayExpression, [0, 'index']]
|
||||
: [
|
||||
...pathToArrayExpression,
|
||||
[
|
||||
firstArg.properties.findIndex(
|
||||
(a) => a.key.name === abbreviatedInputs[0].objInput
|
||||
),
|
||||
'index',
|
||||
],
|
||||
['value', 'Property'],
|
||||
]
|
||||
...pathToArrayExpression,
|
||||
[
|
||||
firstArg.properties.findIndex(
|
||||
(a) => a.key.name === abbreviatedInputs[0].objInput
|
||||
),
|
||||
'index',
|
||||
],
|
||||
['value', 'Property'],
|
||||
]
|
||||
|
||||
const pathToSecondArg: PathToNode = isArr
|
||||
? [...pathToArrayExpression, [1, 'index']]
|
||||
: [
|
||||
...pathToArrayExpression,
|
||||
[
|
||||
firstArg.properties.findIndex(
|
||||
(a) => a.key.name === abbreviatedInputs[1].objInput
|
||||
),
|
||||
'index',
|
||||
],
|
||||
['value', 'Property'],
|
||||
]
|
||||
...pathToArrayExpression,
|
||||
[
|
||||
firstArg.properties.findIndex(
|
||||
(a) => a.key.name === abbreviatedInputs[1].objInput
|
||||
),
|
||||
'index',
|
||||
],
|
||||
['value', 'Property'],
|
||||
]
|
||||
|
||||
const input1 = isArr
|
||||
? firstArg.elements[0]
|
||||
: firstArg.properties.find(
|
||||
(a) => a.key.name === abbreviatedInputs[0].objInput
|
||||
)?.value
|
||||
(a) => a.key.name === abbreviatedInputs[0].objInput
|
||||
)?.value
|
||||
const input2 = isArr
|
||||
? firstArg.elements[1]
|
||||
: firstArg.properties.find(
|
||||
(a) => a.key.name === abbreviatedInputs[1].objInput
|
||||
)?.value
|
||||
(a) => a.key.name === abbreviatedInputs[1].objInput
|
||||
)?.value
|
||||
|
||||
const constraints: ConstrainInfo[] = []
|
||||
if (input1)
|
||||
@ -1807,7 +1807,7 @@ export const angledLineThatIntersects: SketchLineHelper = {
|
||||
const intersectTag =
|
||||
firstArg.type === 'ObjectExpression'
|
||||
? firstArg.properties.find((p) => p.key.name === 'intersectTag')
|
||||
?.value || createLiteral('')
|
||||
?.value || createLiteral('')
|
||||
: createLiteral('')
|
||||
const intersectTagName =
|
||||
intersectTag.type === 'Identifier' ? intersectTag.name : ''
|
||||
@ -1998,13 +1998,13 @@ export function changeSketchArguments(
|
||||
programMemory: ProgramMemory,
|
||||
sourceRangeOrPath:
|
||||
| {
|
||||
type: 'sourceRange'
|
||||
sourceRange: SourceRange
|
||||
}
|
||||
type: 'sourceRange'
|
||||
sourceRange: SourceRange
|
||||
}
|
||||
| {
|
||||
type: 'path'
|
||||
pathToNode: PathToNode
|
||||
},
|
||||
type: 'path'
|
||||
pathToNode: PathToNode
|
||||
},
|
||||
input: SegmentInputs
|
||||
): { modifiedAst: Node<Program>; pathToNode: PathToNode } | Error {
|
||||
const _node = { ...node }
|
||||
@ -2020,7 +2020,8 @@ export function changeSketchArguments(
|
||||
|
||||
const { node: callExpression, shallowPath } = nodeMeta
|
||||
|
||||
if (callExpression?.callee?.name in sketchLineHelperMap) {
|
||||
const fnName = callExpression?.callee?.name
|
||||
if (fnName in sketchLineHelperMap) {
|
||||
const { updateArgs } = sketchLineHelperMap[callExpression.callee.name]
|
||||
if (!updateArgs) {
|
||||
return new Error('not a sketch line helper')
|
||||
@ -2033,8 +2034,10 @@ export function changeSketchArguments(
|
||||
input,
|
||||
})
|
||||
}
|
||||
if (callExpression?.callee?.name in sketchLineHelperMapKw) {
|
||||
const { updateArgs } = sketchLineHelperMapKw[callExpression.callee.name]
|
||||
if (fnName in sketchLineHelperMapKw) {
|
||||
const isAbsolute = callExpression.type === 'CallExpressionKw' && findKwArg('endAbsolute', callExpression) !== undefined
|
||||
const correctFnName = fnName === 'line' && isAbsolute ? 'lineTo' : fnName
|
||||
const { updateArgs } = sketchLineHelperMapKw[correctFnName]
|
||||
if (!updateArgs) {
|
||||
return new Error('not a sketch line keyword helper')
|
||||
}
|
||||
@ -2047,7 +2050,7 @@ export function changeSketchArguments(
|
||||
})
|
||||
}
|
||||
|
||||
return new Error(`not a sketch line helper: ${callExpression?.callee?.name}`)
|
||||
return new Error(`not a sketch line helper: ${fnName}`)
|
||||
}
|
||||
|
||||
export function getConstraintInfo(
|
||||
@ -2122,9 +2125,9 @@ export function addNewSketchLn({
|
||||
spliceBetween = false,
|
||||
}: CreateLineFnCallArgs):
|
||||
| {
|
||||
modifiedAst: Node<Program>
|
||||
pathToNode: PathToNode
|
||||
}
|
||||
modifiedAst: Node<Program>
|
||||
pathToNode: PathToNode
|
||||
}
|
||||
| Error {
|
||||
const node = structuredClone(_node)
|
||||
const { add, updateArgs } =
|
||||
@ -2219,10 +2222,10 @@ export function replaceSketchLine({
|
||||
referencedSegment?: Path
|
||||
}):
|
||||
| {
|
||||
modifiedAst: Node<Program>
|
||||
valueUsedInTransform?: number
|
||||
pathToNode: PathToNode
|
||||
}
|
||||
modifiedAst: Node<Program>
|
||||
valueUsedInTransform?: number
|
||||
pathToNode: PathToNode
|
||||
}
|
||||
| Error {
|
||||
if (![...toolTips, 'intersect', 'circle'].includes(fnName)) {
|
||||
return new Error(`The following function name is not tooltip: ${fnName}`)
|
||||
@ -2274,9 +2277,9 @@ function addTagToChamfer(
|
||||
edgeCutMeta: EdgeCutInfo
|
||||
):
|
||||
| {
|
||||
modifiedAst: Node<Program>
|
||||
tag: string
|
||||
}
|
||||
modifiedAst: Node<Program>
|
||||
tag: string
|
||||
}
|
||||
| Error {
|
||||
const _node = structuredClone(tagInfo.node)
|
||||
let pipeIndex = 0
|
||||
@ -2401,9 +2404,9 @@ export function addTagForSketchOnFace(
|
||||
edgeCutMeta: EdgeCutInfo | null
|
||||
):
|
||||
| {
|
||||
modifiedAst: Node<Program>
|
||||
tag: string
|
||||
}
|
||||
modifiedAst: Node<Program>
|
||||
tag: string
|
||||
}
|
||||
| Error {
|
||||
if (expressionName === 'close') {
|
||||
return addTagKw()(tagInfo)
|
||||
@ -2442,10 +2445,10 @@ function isAngleLiteral(lineArugement: Expr): boolean {
|
||||
return lineArugement?.type === 'ArrayExpression'
|
||||
? isLiteralArrayOrStatic(lineArugement.elements[0])
|
||||
: lineArugement?.type === 'ObjectExpression'
|
||||
? isLiteralArrayOrStatic(
|
||||
? isLiteralArrayOrStatic(
|
||||
lineArugement.properties.find(({ key }) => key.name === 'angle')?.value
|
||||
)
|
||||
: false
|
||||
: false
|
||||
}
|
||||
|
||||
type addTagFn = (
|
||||
@ -2506,13 +2509,13 @@ function addTagKw(): addTagFn {
|
||||
callExpr.node.type === 'CallExpressionKw'
|
||||
? callExpr.node
|
||||
: {
|
||||
type: 'CallExpressionKw',
|
||||
callee: callExpr.node.callee,
|
||||
unlabeled: callExpr.node.arguments.length
|
||||
? callExpr.node.arguments[0]
|
||||
: null,
|
||||
arguments: [],
|
||||
}
|
||||
type: 'CallExpressionKw',
|
||||
callee: callExpr.node.callee,
|
||||
unlabeled: callExpr.node.arguments.length
|
||||
? callExpr.node.arguments[0]
|
||||
: null,
|
||||
arguments: [],
|
||||
}
|
||||
const tagArg = findKwArg(ARG_TAG, primaryCallExp)
|
||||
const tagDeclarator =
|
||||
tagArg || createTagDeclarator(findUniqueName(_node, 'seg', 2))
|
||||
@ -2566,9 +2569,9 @@ export function getXComponent(
|
||||
|
||||
function getFirstArgValuesForXYFns(callExpression: CallExpression):
|
||||
| {
|
||||
val: [Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
val: [Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
| Error {
|
||||
// used for lineTo, line
|
||||
const firstArg = callExpression.arguments[0]
|
||||
@ -2577,9 +2580,9 @@ function getFirstArgValuesForXYFns(callExpression: CallExpression):
|
||||
|
||||
function getValuesForXYFns(arg: Expr):
|
||||
| {
|
||||
val: [Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
val: [Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
| Error {
|
||||
if (arg.type === 'ArrayExpression') {
|
||||
return { val: [arg.elements[0], arg.elements[1]] }
|
||||
@ -2597,9 +2600,9 @@ function getValuesForXYFns(arg: Expr):
|
||||
|
||||
function getFirstArgValuesForAngleFns(callExpression: CallExpression):
|
||||
| {
|
||||
val: [Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
val: [Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
| Error {
|
||||
// used for angledLine, angledLineOfXLength, angledLineToX, angledLineOfYLength, angledLineToY
|
||||
const firstArg = callExpression.arguments[0]
|
||||
@ -2656,9 +2659,9 @@ const getCircle = (
|
||||
callExp: CallExpression
|
||||
):
|
||||
| {
|
||||
val: [Expr, Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
val: [Expr, Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
| Error => {
|
||||
const firstArg = callExp.arguments[0]
|
||||
if (firstArg.type === 'ObjectExpression') {
|
||||
@ -2682,9 +2685,9 @@ const getAngledLineThatIntersects = (
|
||||
callExp: CallExpression
|
||||
):
|
||||
| {
|
||||
val: [Expr, Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
val: [Expr, Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
| Error => {
|
||||
const firstArg = callExp.arguments[0]
|
||||
if (firstArg.type === 'ObjectExpression') {
|
||||
@ -2728,9 +2731,9 @@ Get the argument corresponding to 'end' or 'endAbsolute' or wherever the line ac
|
||||
*/
|
||||
export function getArgForEnd(lineCall: CallExpressionKw):
|
||||
| {
|
||||
val: Expr | [Expr, Expr] | [Expr, Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
val: Expr | [Expr, Expr] | [Expr, Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
| Error {
|
||||
const name = lineCall?.callee?.name
|
||||
let arg
|
||||
@ -2747,9 +2750,9 @@ export function getArgForEnd(lineCall: CallExpressionKw):
|
||||
|
||||
export function getFirstArg(callExp: CallExpression):
|
||||
| {
|
||||
val: Expr | [Expr, Expr] | [Expr, Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
val: Expr | [Expr, Expr] | [Expr, Expr, Expr]
|
||||
tag?: Expr
|
||||
}
|
||||
| Error {
|
||||
const name = callExp?.callee?.name
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user