Fix some graph tests
This commit is contained in:
committed by
Nick Cameron
parent
6b37bf1809
commit
987152e166
@ -10,6 +10,7 @@ import {
|
|||||||
VariableDeclarator,
|
VariableDeclarator,
|
||||||
SourceRange,
|
SourceRange,
|
||||||
topLevelRange,
|
topLevelRange,
|
||||||
|
CallExpressionKw,
|
||||||
} from '../wasm'
|
} from '../wasm'
|
||||||
import {
|
import {
|
||||||
EdgeTreatmentType,
|
EdgeTreatmentType,
|
||||||
@ -78,14 +79,14 @@ const runGetPathToExtrudeForSegmentSelectionTest = async (
|
|||||||
ast: Program,
|
ast: Program,
|
||||||
code: string,
|
code: string,
|
||||||
expectedExtrudeSnippet: string
|
expectedExtrudeSnippet: string
|
||||||
): CallExpression | PipeExpression | Error {
|
): CallExpression | CallExpressionKw | PipeExpression | Error {
|
||||||
const extrudeRange = topLevelRange(
|
const extrudeRange = topLevelRange(
|
||||||
code.indexOf(expectedExtrudeSnippet),
|
code.indexOf(expectedExtrudeSnippet),
|
||||||
code.indexOf(expectedExtrudeSnippet) + expectedExtrudeSnippet.length
|
code.indexOf(expectedExtrudeSnippet) + expectedExtrudeSnippet.length
|
||||||
)
|
)
|
||||||
const expectedExtrudePath = getNodePathFromSourceRange(ast, extrudeRange)
|
const expectedExtrudePath = getNodePathFromSourceRange(ast, extrudeRange)
|
||||||
const expectedExtrudeNodeResult = getNodeFromPath<
|
const expectedExtrudeNodeResult = getNodeFromPath<
|
||||||
VariableDeclarator | CallExpression
|
VariableDeclarator | CallExpression | CallExpressionKw
|
||||||
>(ast, expectedExtrudePath)
|
>(ast, expectedExtrudePath)
|
||||||
if (err(expectedExtrudeNodeResult)) {
|
if (err(expectedExtrudeNodeResult)) {
|
||||||
return expectedExtrudeNodeResult
|
return expectedExtrudeNodeResult
|
||||||
@ -93,7 +94,9 @@ const runGetPathToExtrudeForSegmentSelectionTest = async (
|
|||||||
const expectedExtrudeNode = expectedExtrudeNodeResult.node
|
const expectedExtrudeNode = expectedExtrudeNodeResult.node
|
||||||
|
|
||||||
// check whether extrude is in the sketch pipe
|
// check whether extrude is in the sketch pipe
|
||||||
const extrudeInSketchPipe = expectedExtrudeNode.type === 'CallExpression'
|
const extrudeInSketchPipe =
|
||||||
|
expectedExtrudeNode.type === 'CallExpression' ||
|
||||||
|
expectedExtrudeNode.type === 'CallExpressionKw'
|
||||||
if (extrudeInSketchPipe) {
|
if (extrudeInSketchPipe) {
|
||||||
return expectedExtrudeNode
|
return expectedExtrudeNode
|
||||||
}
|
}
|
||||||
@ -506,7 +509,7 @@ extrude001 = extrude(sketch001, length = -15)
|
|||||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||||
|> close()
|
|> close()
|
||||||
extrude001 = extrude(sketch001, length = -15)`
|
extrude001 = extrude(sketch001, length = -15)`
|
||||||
const segmentSnippets = ['line(end = [20, 0], %)', 'line([-20, 0])']
|
const segmentSnippets = ['line(end = [20, 0])', 'line(end = [-20, 0])']
|
||||||
const expectedCode = `sketch001 = startSketchOn('XY')
|
const expectedCode = `sketch001 = startSketchOn('XY')
|
||||||
|> startProfileAt([-10, 10], %)
|
|> startProfileAt([-10, 10], %)
|
||||||
|> line(end = [20, 0], tag = $seg01)
|
|> line(end = [20, 0], tag = $seg01)
|
||||||
@ -632,9 +635,11 @@ extrude001 = extrude(sketch001, length = -5)
|
|||||||
it('should correctly identify no edges', () => {
|
it('should correctly identify no edges', () => {
|
||||||
const ast = assertParse(code)
|
const ast = assertParse(code)
|
||||||
const lineOfInterest = `line(end = [-3.29, -13.85])`
|
const lineOfInterest = `line(end = [-3.29, -13.85])`
|
||||||
const range = topLevelRange(
|
const start = code.indexOf(lineOfInterest)
|
||||||
code.indexOf(lineOfInterest),
|
expect(start).toBeGreaterThan(-1)
|
||||||
code.indexOf(lineOfInterest) + lineOfInterest.length
|
const range = topLevelRange(
|
||||||
|
start,
|
||||||
|
start + lineOfInterest.length
|
||||||
)
|
)
|
||||||
const pathToNode = getNodePathFromSourceRange(ast, range)
|
const pathToNode = getNodePathFromSourceRange(ast, range)
|
||||||
if (err(pathToNode)) return
|
if (err(pathToNode)) return
|
||||||
@ -657,10 +662,12 @@ describe('Testing button states', () => {
|
|||||||
) => {
|
) => {
|
||||||
const ast = assertParse(code)
|
const ast = assertParse(code)
|
||||||
|
|
||||||
|
const start = code.indexOf(segmentSnippet)
|
||||||
|
expect(start).toBeGreaterThan(-1)
|
||||||
const range = segmentSnippet
|
const range = segmentSnippet
|
||||||
? topLevelRange(
|
? topLevelRange(
|
||||||
code.indexOf(segmentSnippet),
|
start,
|
||||||
code.indexOf(segmentSnippet) + segmentSnippet.length
|
start + segmentSnippet.length
|
||||||
)
|
)
|
||||||
: topLevelRange(ast.end, ast.end) // empty line in the end of the code
|
: topLevelRange(ast.end, ast.end) // empty line in the end of the code
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
ArtifactGraph,
|
ArtifactGraph,
|
||||||
CallExpression,
|
CallExpression,
|
||||||
|
CallExpressionKw,
|
||||||
Expr,
|
Expr,
|
||||||
Identifier,
|
Identifier,
|
||||||
ObjectExpression,
|
ObjectExpression,
|
||||||
@ -526,7 +527,7 @@ export const hasValidEdgeTreatmentSelection = ({
|
|||||||
traverse(ast, {
|
traverse(ast, {
|
||||||
enter(node) {
|
enter(node) {
|
||||||
if (
|
if (
|
||||||
node.type === 'CallExpression' &&
|
(node.type === 'CallExpression' || node.type == 'CallExpressionKw') &&
|
||||||
(node.callee.name === 'extrude' || node.callee.name === 'revolve')
|
(node.callee.name === 'extrude' || node.callee.name === 'revolve')
|
||||||
) {
|
) {
|
||||||
extrudeExists = true
|
extrudeExists = true
|
||||||
@ -548,13 +549,16 @@ export const hasValidEdgeTreatmentSelection = ({
|
|||||||
// selection exists:
|
// selection exists:
|
||||||
for (const selection of selectionRanges.graphSelections) {
|
for (const selection of selectionRanges.graphSelections) {
|
||||||
// check if all selections are in sketchLineHelperMap
|
// check if all selections are in sketchLineHelperMap
|
||||||
const segmentNode = getNodeFromPath<Node<CallExpression>>(
|
const segmentNode = getNodeFromPath<
|
||||||
ast,
|
Node<CallExpression | CallExpressionKw>
|
||||||
selection.codeRef.pathToNode,
|
>(ast, selection.codeRef.pathToNode, ['CallExpression', 'CallExpressionKw'])
|
||||||
'CallExpression'
|
|
||||||
)
|
|
||||||
if (err(segmentNode)) return false
|
if (err(segmentNode)) return false
|
||||||
if (segmentNode.node.type !== 'CallExpression') {
|
if (
|
||||||
|
!(
|
||||||
|
segmentNode.node.type === 'CallExpression' ||
|
||||||
|
segmentNode.node.type === 'CallExpressionKw'
|
||||||
|
)
|
||||||
|
) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (!(segmentNode.node.callee.name in sketchLineHelperMap)) {
|
if (!(segmentNode.node.callee.name in sketchLineHelperMap)) {
|
||||||
@ -597,7 +601,8 @@ export const hasValidEdgeTreatmentSelection = ({
|
|||||||
traverse(ast, {
|
traverse(ast, {
|
||||||
enter(node) {
|
enter(node) {
|
||||||
if (
|
if (
|
||||||
node.type === 'CallExpression' &&
|
(node.type === 'CallExpression' ||
|
||||||
|
node.type === 'CallExpressionKw') &&
|
||||||
isEdgeTreatmentType(node.callee.name)
|
isEdgeTreatmentType(node.callee.name)
|
||||||
) {
|
) {
|
||||||
inEdgeTreatment = true
|
inEdgeTreatment = true
|
||||||
@ -610,7 +615,8 @@ export const hasValidEdgeTreatmentSelection = ({
|
|||||||
},
|
},
|
||||||
leave(node) {
|
leave(node) {
|
||||||
if (
|
if (
|
||||||
node.type === 'CallExpression' &&
|
(node.type === 'CallExpression' ||
|
||||||
|
node.type === 'CallExpressionKw') &&
|
||||||
isEdgeTreatmentType(node.callee.name)
|
isEdgeTreatmentType(node.callee.name)
|
||||||
) {
|
) {
|
||||||
inEdgeTreatment = false
|
inEdgeTreatment = false
|
||||||
@ -650,7 +656,7 @@ export const isTagUsedInEdgeTreatment = ({
|
|||||||
enter: (node) => {
|
enter: (node) => {
|
||||||
// Check if we are entering an edge treatment call
|
// Check if we are entering an edge treatment call
|
||||||
if (
|
if (
|
||||||
node.type === 'CallExpression' &&
|
(node.type === 'CallExpression' || node.type === 'CallExpressionKw') &&
|
||||||
isEdgeTreatmentType(node.callee.name)
|
isEdgeTreatmentType(node.callee.name)
|
||||||
) {
|
) {
|
||||||
inEdgeTreatment = true
|
inEdgeTreatment = true
|
||||||
@ -668,7 +674,7 @@ export const isTagUsedInEdgeTreatment = ({
|
|||||||
if (
|
if (
|
||||||
inObj &&
|
inObj &&
|
||||||
inEdgeTreatment &&
|
inEdgeTreatment &&
|
||||||
node.type === 'CallExpression' &&
|
(node.type === 'CallExpression' || node.type === 'CallExpressionKw') &&
|
||||||
isEdgeType(node.callee.name)
|
isEdgeType(node.callee.name)
|
||||||
) {
|
) {
|
||||||
inTagHelper = node.callee.name
|
inTagHelper = node.callee.name
|
||||||
@ -694,7 +700,7 @@ export const isTagUsedInEdgeTreatment = ({
|
|||||||
},
|
},
|
||||||
leave: (node) => {
|
leave: (node) => {
|
||||||
if (
|
if (
|
||||||
node.type === 'CallExpression' &&
|
(node.type === 'CallExpression' || node.type === 'CallExpressionKw') &&
|
||||||
isEdgeTreatmentType(node.callee.name)
|
isEdgeTreatmentType(node.callee.name)
|
||||||
) {
|
) {
|
||||||
inEdgeTreatment = false
|
inEdgeTreatment = false
|
||||||
@ -712,7 +718,7 @@ export const isTagUsedInEdgeTreatment = ({
|
|||||||
if (
|
if (
|
||||||
inObj &&
|
inObj &&
|
||||||
inEdgeTreatment &&
|
inEdgeTreatment &&
|
||||||
node.type === 'CallExpression' &&
|
(node.type === 'CallExpression' || node.type === 'CallExpressionKw') &&
|
||||||
isEdgeType(node.callee.name)
|
isEdgeType(node.callee.name)
|
||||||
) {
|
) {
|
||||||
inTagHelper = ''
|
inTagHelper = ''
|
||||||
|
|||||||
@ -429,6 +429,7 @@ export function getNodePathFromSourceRange(
|
|||||||
previousPath: PathToNode = [['body', '']]
|
previousPath: PathToNode = [['body', '']]
|
||||||
): PathToNode {
|
): PathToNode {
|
||||||
const [start, end] = sourceRange || []
|
const [start, end] = sourceRange || []
|
||||||
|
expect(start).toBeGreaterThan(-1)
|
||||||
let path: PathToNode = [...previousPath]
|
let path: PathToNode = [...previousPath]
|
||||||
const _node = { ...node }
|
const _node = { ...node }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user