simple test fixups

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-01-27 09:24:21 +13:00
parent ef8131f33d
commit 665ec8a6b5
3 changed files with 37 additions and 9 deletions

View File

@ -334,7 +334,7 @@ test.describe('Testing segment overlays', () => {
constraintType: 'yAbsolute',
expectBeforeUnconstrained:
'line(endAbsolute = [5 + 33, 20 + 11.5 + 0])',
expectAfterUnconstrained: 'line(endAbsolute = [5 + 33, 31.5], %)',
expectAfterUnconstrained: 'line(endAbsolute = [5 + 33, 31.5])',
expectFinal: 'line(endAbsolute = [5 + 33, yAbs001])',
steps: 8,
ang: ang + 180,

View File

@ -595,7 +595,7 @@ describe('Testing removeSingleConstraintInfo', () => {
'objectProperty',
'angle',
],
['line(endAbsolute = [6.14, 3.14 + 0])', 'arrayIndex', 0],
['line(endAbsolute = [6.14 + 0, 3.14 + 0])', 'arrayIndex', 0],
['xLineTo(8, %)', '', ''],
['yLineTo(5, %)', '', ''],
['yLine(3.14, %, $a)', '', ''],

View File

@ -170,7 +170,10 @@ export function modifyAstWithEdgeTreatmentAndTag(
let pathToEdgeTreatmentNode: PathToNode
if (extrudeDeclarator.init.type === 'CallExpression') {
if (
extrudeDeclarator.init.type === 'CallExpression' ||
extrudeDeclarator.init.type === 'CallExpressionKw'
) {
// 1. case when no edge treatment exists
// modify ast with new edge treatment call by mutating the extrude node
@ -315,7 +318,12 @@ export function mutateAstWithTagForSketchSegment(
if (err(segmentNode)) return segmentNode
// Check whether selection is a valid segment
if (!(segmentNode.node.callee.name in sketchLineHelperMap)) {
if (
!(
segmentNode.node.callee.name in sketchLineHelperMap ||
segmentNode.node.callee.name in sketchLineHelperMapKw
)
) {
return new Error('Selection is not a sketch segment')
}
@ -338,7 +346,7 @@ export function mutateAstWithTagForSketchSegment(
export function getEdgeTagCall(
tag: string,
artifact: Artifact
): Node<Identifier | CallExpression> {
): Node<Identifier | CallExpression | CallExpressionKw> {
let tagCall: Expr = createIdentifier(tag)
// Modify the tag based on selectionType
@ -374,6 +382,7 @@ function locateExtrudeDeclarator(
if (
extrudeInit.type !== 'CallExpression' &&
extrudeInit.type !== 'CallExpressionKw' &&
extrudeInit.type !== 'PipeExpression'
) {
return new Error('Extrude must be a PipeExpression or CallExpression')
@ -385,7 +394,7 @@ function locateExtrudeDeclarator(
function getPathToNodeOfEdgeTreatmentLiteral(
pathToExtrudeNode: PathToNode,
extrudeDeclarator: VariableDeclarator,
tag: Identifier | CallExpression,
tag: Identifier | CallExpression | CallExpressionKw,
parameters: EdgeTreatmentParameters
): PathToNode {
let pathToEdgeTreatmentObj: PathToNode = []
@ -394,7 +403,7 @@ function getPathToNodeOfEdgeTreatmentLiteral(
traverse(extrudeDeclarator.init, {
enter(node, path) {
if (
node.type === 'CallExpression' &&
(node.type === 'CallExpression' || node.type === 'CallExpressionKw') &&
node.callee.name === parameters.type
) {
inEdgeTreatment = true
@ -410,7 +419,7 @@ function getPathToNodeOfEdgeTreatmentLiteral(
},
leave(node) {
if (
node.type === 'CallExpression' &&
(node.type === 'CallExpression' || node.type === 'CallExpressionKw') &&
node.callee.name === parameters.type
) {
inEdgeTreatment = false
@ -434,7 +443,7 @@ function getPathToNodeOfEdgeTreatmentLiteral(
function hasTag(
node: ObjectExpression,
tag: Identifier | CallExpression
tag: Identifier | CallExpression | CallExpressionKw
): boolean {
return node.properties.some((prop) => {
if (prop.key.name === 'tags' && prop.value.type === 'ArrayExpression') {
@ -456,6 +465,25 @@ function hasTag(
element.arguments[0].name === tag.arguments[0].name // tag name
)
}
if (tag.type === 'CallExpressionKw') {
return prop.value.elements.some((element) => {
if (element.type !== 'CallExpressionKw') {
return false
}
const elementTag = findKwArg(ARG_TAG, element)
const tagTag = findKwArg(ARG_TAG, tag)
return (
element.callee.name === tag.callee.name && // edge location
elementTag !== undefined &&
elementTag.type === 'Identifier' &&
tagTag !== undefined &&
tagTag.type === 'Identifier' &&
elementTag.name === tagTag.name
)
})
}
}
return false
})