Update test KCL
This commit is contained in:
committed by
Nick Cameron
parent
cc9a14ddd9
commit
e917eb9af6
@ -11,8 +11,8 @@ describe('testing artifacts', () => {
|
||||
const code = `
|
||||
const mySketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> lineTo([-1.59, -1.54], %)
|
||||
|> lineTo([0.46, -5.82], %)
|
||||
|> line(endAbsolute = [-1.59, -1.54])
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
// |> rx(45, %)`
|
||||
const execState = await enginelessExecutor(assertParse(code))
|
||||
// @ts-ignore
|
||||
@ -66,10 +66,10 @@ const mySketch001 = startSketchOn('XY')
|
||||
const code = `
|
||||
const mySketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> lineTo([-1.59, -1.54], %)
|
||||
|> lineTo([0.46, -5.82], %)
|
||||
|> line(endAbsolute = [-1.59, -1.54])
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
// |> rx(45, %)
|
||||
|> extrude(2, %)`
|
||||
|> extrude(length = 2)`
|
||||
const execState = await enginelessExecutor(assertParse(code))
|
||||
// @ts-ignore
|
||||
const sketch001 = execState.memory.get('mySketch001')
|
||||
@ -142,21 +142,21 @@ const mySketch001 = startSketchOn('XY')
|
||||
const code = `
|
||||
const sk1 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> lineTo([-2.5, 0], %)
|
||||
|> lineTo([0, 10], %, $p)
|
||||
|> lineTo([2.5, 0], %)
|
||||
|> line(endAbsolute = [-2.5, 0])
|
||||
|> line(endAbsolute = [0, 10], tag = $p)
|
||||
|> line(endAbsolute = [2.5, 0])
|
||||
// |> rx(45, %)
|
||||
// |> translate([1,0,1], %)
|
||||
// |> ry(5, %)
|
||||
const theExtrude = extrude(2, sk1)
|
||||
const theExtrude = extrude(sk1, length = 2)
|
||||
// const theTransf = getExtrudeWallTransform('p', theExtrude)
|
||||
const sk2 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> lineTo([-2.5, 0], %)
|
||||
|> lineTo([0, 3], %, $o)
|
||||
|> lineTo([2.5, 0], %)
|
||||
|> line(endAbsolute = [-2.5, 0])
|
||||
|> line(endAbsolute = [0, 3], tag = $o)
|
||||
|> line(endAbsolute = [2.5, 0])
|
||||
// |> transform(theTransf, %)
|
||||
|> extrude(2, %)
|
||||
|> extrude(length = 2)
|
||||
|
||||
`
|
||||
const execState = await enginelessExecutor(assertParse(code))
|
||||
|
@ -53,10 +53,10 @@ const newVar = myVar + 1`
|
||||
it('sketch declaration', async () => {
|
||||
let code = `const mySketch = startSketchOn('XY')
|
||||
|> startProfileAt([0,0], %)
|
||||
|> lineTo([0,2], %, $myPath)
|
||||
|> lineTo([2,3], %)
|
||||
|> lineTo([5,-1], %, $rightPath)
|
||||
// |> close(%)
|
||||
|> line(endAbsolute = [0,2], tag = $myPath)
|
||||
|> line(endAbsolute = [2,3])
|
||||
|> line(endAbsolute = [5,-1], tag = $rightPath)
|
||||
// |> close()
|
||||
`
|
||||
const mem = await exe(code)
|
||||
// geo is three js buffer geometry and is very bloated to have in tests
|
||||
@ -124,9 +124,9 @@ const newVar = myVar + 1`
|
||||
// it('rotated sketch', async () => {
|
||||
// const code = [
|
||||
// 'const mySk1 = startSketchAt([0,0])',
|
||||
// ' |> lineTo([1,1], %)',
|
||||
// ' |> lineTo([0, 1], %, "myPath")',
|
||||
// ' |> lineTo([1, 1], %)',
|
||||
// ' |> line(endAbsolute = [1,1])',
|
||||
// ' |> line(endAbsolute = [0, 1], tag = "myPath")',
|
||||
// ' |> line(endAbsolute = [1, 1])',
|
||||
// 'const rotated = rx(90, mySk1)',
|
||||
// ].join('\n')
|
||||
// const mem = await exe(code)
|
||||
@ -151,9 +151,9 @@ const newVar = myVar + 1`
|
||||
const code = [
|
||||
"const mySk1 = startSketchOn('XY')",
|
||||
' |> startProfileAt([0,0], %)',
|
||||
' |> lineTo([1,1], %)',
|
||||
' |> lineTo([0, 1], %, $myPath)',
|
||||
' |> lineTo([1,1], %)',
|
||||
' |> line(endAbsolute = [1,1])',
|
||||
' |> line(endAbsolute = [0, 1], tag = $myPath)',
|
||||
' |> line(endAbsolute = [1,1])',
|
||||
// ' |> rx(90, %)',
|
||||
].join('\n')
|
||||
const mem = await exe(code)
|
||||
@ -421,7 +421,7 @@ describe('testing math operators', () => {
|
||||
const code = [
|
||||
"const part001 = startSketchOn('XY')",
|
||||
' |> startProfileAt([0, 0], %)',
|
||||
'|> line([-2.21, -legLen(5, min(3, 999))], %)',
|
||||
'|> line(end = [-2.21, -legLen(5, min(3, 999))])',
|
||||
].join('\n')
|
||||
const mem = await exe(code)
|
||||
const sketch = sketchFromKclValue(mem.get('part001'), 'part001')
|
||||
@ -434,7 +434,7 @@ describe('testing math operators', () => {
|
||||
`const myVar = 3`,
|
||||
`const part001 = startSketchOn('XY')`,
|
||||
` |> startProfileAt([0, 0], %)`,
|
||||
` |> line([3, 4], %, $seg01)`,
|
||||
` |> line(end = [3, 4], tag = $seg01)`,
|
||||
` |> line([`,
|
||||
` min(segLen(seg01), myVar),`,
|
||||
` -legLen(segLen(seg01), myVar)`,
|
||||
@ -476,11 +476,11 @@ describe('Testing Errors', () => {
|
||||
const code = `const myVar = 5
|
||||
const theExtrude = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([-2.4, 5], %)
|
||||
|> line(myVarZ, %)
|
||||
|> line([5,5], %)
|
||||
|> close(%)
|
||||
|> extrude(4, %)`
|
||||
|> line(end = [-2.4, 5])
|
||||
|> line(end = myVarZ)
|
||||
|> line(end = [5,5])
|
||||
|> close()
|
||||
|> extrude(length = 4)`
|
||||
await expect(exe(code)).rejects.toEqual(
|
||||
new KCLError(
|
||||
'undefined_value',
|
||||
|
@ -18,11 +18,11 @@ describe('testing getNodePathFromSourceRange', () => {
|
||||
const code = `
|
||||
const myVar = 5
|
||||
const sk3 = startSketchAt([0, 0])
|
||||
|> lineTo([1, 2], %)
|
||||
|> lineTo([3, 4], %, $yo)
|
||||
|> close(%)
|
||||
|> line(endAbsolute = [1, 2])
|
||||
|> line(endAbsolute = [3, 4], tag = $yo)
|
||||
|> close()
|
||||
`
|
||||
const subStr = 'lineTo([3, 4], %, $yo)'
|
||||
const subStr = 'line(endAbsolute = [3, 4], tag = $yo)'
|
||||
const lineToSubstringIndex = code.indexOf(subStr)
|
||||
const sourceRange = topLevelRange(
|
||||
lineToSubstringIndex,
|
||||
@ -41,9 +41,9 @@ const sk3 = startSketchAt([0, 0])
|
||||
it('gets path right for function definition params', () => {
|
||||
const code = `fn cube = (pos, scale) => {
|
||||
const sg = startSketchAt(pos)
|
||||
|> line([0, scale], %)
|
||||
|> line([scale, 0], %)
|
||||
|> line([0, -scale], %)
|
||||
|> line(end = [0, scale])
|
||||
|> line(end = [scale, 0])
|
||||
|> line(end = [0, -scale])
|
||||
|
||||
return sg
|
||||
}
|
||||
@ -73,9 +73,9 @@ const b1 = cube([0,0], 10)`
|
||||
it('gets path right for deep within function definition body', () => {
|
||||
const code = `fn cube = (pos, scale) => {
|
||||
const sg = startSketchAt(pos)
|
||||
|> line([0, scale], %)
|
||||
|> line([scale, 0], %)
|
||||
|> line([0, -scale], %)
|
||||
|> line(end = [0, scale])
|
||||
|> line(end = [scale, 0])
|
||||
|> line(end = [0, -scale])
|
||||
|
||||
return sg
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ describe('Testing addSketchTo', () => {
|
||||
const str = recast(result.modifiedAst)
|
||||
expect(str).toBe(`sketch001 = startSketchOn('YZ')
|
||||
|> startProfileAt('default', %)
|
||||
|> line('default', %)
|
||||
|> line(end = 'default')
|
||||
`)
|
||||
})
|
||||
})
|
||||
@ -167,34 +167,34 @@ function giveSketchFnCallTagTestHelper(
|
||||
describe('Testing giveSketchFnCallTag', () => {
|
||||
const code = `part001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([-2.57, -0.13], %)
|
||||
|> line([0, 0.83], %)
|
||||
|> line([0.82, 0.34], %)`
|
||||
|> line(end = [-2.57, -0.13])
|
||||
|> line(end = [0, 0.83])
|
||||
|> line(end = [0.82, 0.34])`
|
||||
it('Should add tag to a sketch function call', () => {
|
||||
const { newCode, tag, isTagExisting } = giveSketchFnCallTagTestHelper(
|
||||
code,
|
||||
'line([0, 0.83], %)'
|
||||
'line(end = [0, 0.83])'
|
||||
)
|
||||
expect(newCode).toContain('line([0, 0.83], %, $seg01)')
|
||||
expect(newCode).toContain('line(end = [0, 0.83], tag = $seg01)')
|
||||
expect(tag).toBe('seg01')
|
||||
expect(isTagExisting).toBe(false)
|
||||
})
|
||||
it('Should create a unique tag if seg01 already exists', () => {
|
||||
let _code = code.replace(
|
||||
'line([-2.57, -0.13], %)',
|
||||
'line([-2.57, -0.13], %, $seg01)'
|
||||
'line(end = [-2.57, -0.13])',
|
||||
'line(end = [-2.57, -0.13], tag = $seg01)'
|
||||
)
|
||||
const { newCode, tag, isTagExisting } = giveSketchFnCallTagTestHelper(
|
||||
_code,
|
||||
'line([0, 0.83], %)'
|
||||
'line(end = [0, 0.83])'
|
||||
)
|
||||
expect(newCode).toContain('line([0, 0.83], %, $seg02)')
|
||||
expect(newCode).toContain('line(end = [0, 0.83], tag = $seg02)')
|
||||
expect(tag).toBe('seg02')
|
||||
expect(isTagExisting).toBe(false)
|
||||
})
|
||||
it('Should return existing tag if it already exists', () => {
|
||||
const lineButWithTag = 'line([-2.57, -0.13], %, $butts)'
|
||||
let _code = code.replace('line([-2.57, -0.13], %)', lineButWithTag)
|
||||
const lineButWithTag = 'line(end = [-2.57, -0.13], tag = $butts)'
|
||||
let _code = code.replace('line(end = [-2.57, -0.13])', lineButWithTag)
|
||||
const { newCode, tag, isTagExisting } = giveSketchFnCallTagTestHelper(
|
||||
_code,
|
||||
lineButWithTag
|
||||
@ -219,7 +219,7 @@ const identifierGuy = 5
|
||||
yo = 5 + 6
|
||||
part001 = startSketchOn('XY')
|
||||
|> startProfileAt([-1.2, 4.83], %)
|
||||
|> line([2.8, 0], %)
|
||||
|> line(end = [2.8, 0])
|
||||
|> angledLine([100 + 100, 3.09], %)
|
||||
|> angledLine([abc, 3.09], %)
|
||||
|> angledLine([def(yo), 3.09], %)
|
||||
@ -252,7 +252,7 @@ yo2 = hmm([identifierGuy + 5])`
|
||||
)
|
||||
const newCode = recast(modifiedAst)
|
||||
expect(newCode).toContain(`newVar = 2.8`)
|
||||
expect(newCode).toContain(`line([newVar, 0], %)`)
|
||||
expect(newCode).toContain(`line(end = [newVar, 0])`)
|
||||
})
|
||||
it('should move a callExpression into a new variable', async () => {
|
||||
const ast = assertParse(code)
|
||||
@ -302,19 +302,19 @@ describe('testing sketchOnExtrudedFace', () => {
|
||||
test('it should be able to extrude on regular segments', async () => {
|
||||
const code = `part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> line([9.7, 9.19], %)
|
||||
|> line([8.62, -9.57], %)
|
||||
|> close(%)
|
||||
|> extrude(5 + 7, %)`
|
||||
|> line(end = [9.7, 9.19])
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close()
|
||||
|> extrude(length = 5 + 7)`
|
||||
const ast = assertParse(code)
|
||||
|
||||
const segmentSnippet = `line([9.7, 9.19], %)`
|
||||
const segmentSnippet = `line(end = [9.7, 9.19])`
|
||||
const segmentRange = topLevelRange(
|
||||
code.indexOf(segmentSnippet),
|
||||
code.indexOf(segmentSnippet) + segmentSnippet.length
|
||||
)
|
||||
const segmentPathToNode = getNodePathFromSourceRange(ast, segmentRange)
|
||||
const extrudeSnippet = `extrude(5 + 7, %)`
|
||||
const extrudeSnippet = `extrude(length = 5 + 7)`
|
||||
const extrudeRange = topLevelRange(
|
||||
code.indexOf(extrudeSnippet),
|
||||
code.indexOf(extrudeSnippet) + extrudeSnippet.length
|
||||
@ -332,27 +332,27 @@ describe('testing sketchOnExtrudedFace', () => {
|
||||
const newCode = recast(modifiedAst)
|
||||
expect(newCode).toContain(`part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> line([9.7, 9.19], %, $seg01)
|
||||
|> line([8.62, -9.57], %)
|
||||
|> close(%)
|
||||
|> extrude(5 + 7, %)
|
||||
|> line(end = [9.7, 9.19], tag = $seg01)
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close()
|
||||
|> extrude(length = 5 + 7)
|
||||
sketch001 = startSketchOn(part001, seg01)`)
|
||||
})
|
||||
test('it should be able to extrude on close segments', async () => {
|
||||
const code = `part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> line([9.7, 9.19], %)
|
||||
|> line([8.62, -9.57], %)
|
||||
|> close(%)
|
||||
|> extrude(5 + 7, %)`
|
||||
|> line(end = [9.7, 9.19])
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close()
|
||||
|> extrude(length = 5 + 7)`
|
||||
const ast = assertParse(code)
|
||||
const segmentSnippet = `close(%)`
|
||||
const segmentSnippet = `close()`
|
||||
const segmentRange = topLevelRange(
|
||||
code.indexOf(segmentSnippet),
|
||||
code.indexOf(segmentSnippet) + segmentSnippet.length
|
||||
)
|
||||
const segmentPathToNode = getNodePathFromSourceRange(ast, segmentRange)
|
||||
const extrudeSnippet = `extrude(5 + 7, %)`
|
||||
const extrudeSnippet = `extrude(length = 5 + 7)`
|
||||
const extrudeRange = topLevelRange(
|
||||
code.indexOf(extrudeSnippet),
|
||||
code.indexOf(extrudeSnippet) + extrudeSnippet.length
|
||||
@ -370,19 +370,19 @@ sketch001 = startSketchOn(part001, seg01)`)
|
||||
const newCode = recast(modifiedAst)
|
||||
expect(newCode).toContain(`part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> line([9.7, 9.19], %)
|
||||
|> line([8.62, -9.57], %)
|
||||
|> close(%, $seg01)
|
||||
|> extrude(5 + 7, %)
|
||||
|> line(end = [9.7, 9.19])
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close(tag = $seg01)
|
||||
|> extrude(length = 5 + 7)
|
||||
sketch001 = startSketchOn(part001, seg01)`)
|
||||
})
|
||||
test('it should be able to extrude on start-end caps', async () => {
|
||||
const code = `part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> line([9.7, 9.19], %)
|
||||
|> line([8.62, -9.57], %)
|
||||
|> close(%)
|
||||
|> extrude(5 + 7, %)`
|
||||
|> line(end = [9.7, 9.19])
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close()
|
||||
|> extrude(length = 5 + 7)`
|
||||
const ast = assertParse(code)
|
||||
const sketchSnippet = `startProfileAt([3.58, 2.06], %)`
|
||||
const sketchRange = topLevelRange(
|
||||
@ -390,7 +390,7 @@ sketch001 = startSketchOn(part001, seg01)`)
|
||||
code.indexOf(sketchSnippet) + sketchSnippet.length
|
||||
)
|
||||
const sketchPathToNode = getNodePathFromSourceRange(ast, sketchRange)
|
||||
const extrudeSnippet = `extrude(5 + 7, %)`
|
||||
const extrudeSnippet = `extrude(length = 5 + 7)`
|
||||
const extrudeRange = topLevelRange(
|
||||
code.indexOf(extrudeSnippet),
|
||||
code.indexOf(extrudeSnippet) + extrudeSnippet.length
|
||||
@ -409,35 +409,35 @@ sketch001 = startSketchOn(part001, seg01)`)
|
||||
const newCode = recast(modifiedAst)
|
||||
expect(newCode).toContain(`part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([3.58, 2.06], %)
|
||||
|> line([9.7, 9.19], %)
|
||||
|> line([8.62, -9.57], %)
|
||||
|> close(%)
|
||||
|> extrude(5 + 7, %)
|
||||
|> line(end = [9.7, 9.19])
|
||||
|> line(end = [8.62, -9.57])
|
||||
|> close()
|
||||
|> extrude(length = 5 + 7)
|
||||
sketch001 = startSketchOn(part001, 'END')`)
|
||||
})
|
||||
test('it should ensure that the new sketch is inserted after the extrude', async () => {
|
||||
const code = `sketch001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> line([2.48, 2.44], %)
|
||||
|> line([2.66, 1.17], %)
|
||||
|> line([3.75, 0.46], %)
|
||||
|> line([4.99, -0.46], %)
|
||||
|> line([3.3, -2.12], %)
|
||||
|> line([2.16, -3.33], %)
|
||||
|> line([0.85, -3.08], %)
|
||||
|> line([-0.18, -3.36], %)
|
||||
|> line([-3.86, -2.73], %)
|
||||
|> line([-17.67, 0.85], %)
|
||||
|> close(%)
|
||||
part001 = extrude(5 + 7, sketch001)`
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [2.66, 1.17])
|
||||
|> line(end = [3.75, 0.46])
|
||||
|> line(end = [4.99, -0.46])
|
||||
|> line(end = [3.3, -2.12])
|
||||
|> line(end = [2.16, -3.33])
|
||||
|> line(end = [0.85, -3.08])
|
||||
|> line(end = [-0.18, -3.36])
|
||||
|> line(end = [-3.86, -2.73])
|
||||
|> line(end = [-17.67, 0.85])
|
||||
|> close()
|
||||
part001 = extrude(sketch001, length = 5 + 7)`
|
||||
const ast = assertParse(code)
|
||||
const segmentSnippet = `line([4.99, -0.46], %)`
|
||||
const segmentSnippet = `line(end = [4.99, -0.46])`
|
||||
const segmentRange = topLevelRange(
|
||||
code.indexOf(segmentSnippet),
|
||||
code.indexOf(segmentSnippet) + segmentSnippet.length
|
||||
)
|
||||
const segmentPathToNode = getNodePathFromSourceRange(ast, segmentRange)
|
||||
const extrudeSnippet = `extrude(5 + 7, sketch001)`
|
||||
const extrudeSnippet = `extrude(sketch001, length = 5 + 7)`
|
||||
const extrudeRange = topLevelRange(
|
||||
code.indexOf(extrudeSnippet),
|
||||
code.indexOf(extrudeSnippet) + extrudeSnippet.length
|
||||
@ -451,7 +451,7 @@ sketch001 = startSketchOn(part001, 'END')`)
|
||||
)
|
||||
if (err(updatedAst)) throw updatedAst
|
||||
const newCode = recast(updatedAst.modifiedAst)
|
||||
expect(newCode).toContain(`part001 = extrude(5 + 7, sketch001)
|
||||
expect(newCode).toContain(`part001 = extrude(sketch001, length = 5 + 7)
|
||||
sketch002 = startSketchOn(part001, seg01)`)
|
||||
})
|
||||
})
|
||||
@ -460,12 +460,12 @@ describe('Testing deleteSegmentFromPipeExpression', () => {
|
||||
it('Should delete a segment withOUT any dependent segments', async () => {
|
||||
const code = `part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([54.78, -95.91], %)
|
||||
|> line([306.21, 198.82], %)
|
||||
|> line([306.21, 198.85], %, $a)
|
||||
|> line([306.21, 198.87], %)`
|
||||
|> line(end = [306.21, 198.82])
|
||||
|> line(end = [306.21, 198.85], tag = $a)
|
||||
|> line(end = [306.21, 198.87])`
|
||||
const ast = assertParse(code)
|
||||
const execState = await enginelessExecutor(ast)
|
||||
const lineOfInterest = 'line([306.21, 198.85], %, $a)'
|
||||
const lineOfInterest = 'line(end = [306.21, 198.85], tag = $a)'
|
||||
const range = topLevelRange(
|
||||
code.indexOf(lineOfInterest),
|
||||
code.indexOf(lineOfInterest) + lineOfInterest.length
|
||||
@ -482,8 +482,8 @@ describe('Testing deleteSegmentFromPipeExpression', () => {
|
||||
const newCode = recast(modifiedAst)
|
||||
expect(newCode).toBe(`part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([54.78, -95.91], %)
|
||||
|> line([306.21, 198.82], %)
|
||||
|> line([306.21, 198.87], %)
|
||||
|> line(end = [306.21, 198.82])
|
||||
|> line(end = [306.21, 198.87])
|
||||
`)
|
||||
})
|
||||
describe('Should delete a segment WITH any dependent segments, unconstraining the dependent parts', () => {
|
||||
@ -493,17 +493,17 @@ describe('Testing deleteSegmentFromPipeExpression', () => {
|
||||
replace2 = ''
|
||||
) => `part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([54.78, -95.91], %)
|
||||
|> line([306.21, 198.82], %, $b)
|
||||
|> line(end = [306.21, 198.82], tag = $b)
|
||||
${!replace1 ? ` |> ${line}\n` : ''} |> angledLine([-65, ${
|
||||
!replace1 ? 'segLen(a)' : replace1
|
||||
}], %)
|
||||
|> line([306.21, 198.87], %)
|
||||
|> line(end = [306.21, 198.87])
|
||||
|> angledLine([65, ${!replace2 ? 'segAng(a)' : replace2}], %)
|
||||
|> line([-963.39, -154.67], %)
|
||||
|> line(end = [-963.39, -154.67])
|
||||
`
|
||||
test.each([
|
||||
['line', 'line([306.21, 198.85], %, $a)', ['365.11', '33']],
|
||||
['lineTo', 'lineTo([306.21, 198.85], %, $a)', ['110.48', '119.73']],
|
||||
['line', 'line(end = [306.21, 198.85], tag = $a)', ['365.11', '33']],
|
||||
['lineTo', 'line(endAbsolute = [306.21, 198.85], tag = $a)', ['110.48', '119.73']],
|
||||
['yLine', 'yLine(198.85, %, $a)', ['198.85', '90']],
|
||||
['xLine', 'xLine(198.85, %, $a)', ['198.85', '0']],
|
||||
['yLineTo', 'yLineTo(198.85, %, $a)', ['95.94', '90']],
|
||||
@ -567,9 +567,9 @@ describe('Testing removeSingleConstraintInfo', () => {
|
||||
describe('with mostly object notation', () => {
|
||||
const code = `part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([3 + 0, 4 + 0], %)
|
||||
|> line(end = [3 + 0, 4 + 0])
|
||||
|> angledLine({ angle = 3 + 0, length = 3.14 + 0 }, %)
|
||||
|> lineTo([6.14 + 0, 3.14 + 0], %)
|
||||
|> line(endAbsolute = [6.14 + 0, 3.14 + 0])
|
||||
|> xLineTo(8 + 0, %)
|
||||
|> yLineTo(5 + 0, %)
|
||||
|> yLine(3.14 + 0, %, $a)
|
||||
@ -585,13 +585,13 @@ describe('Testing removeSingleConstraintInfo', () => {
|
||||
}, %)
|
||||
|> tangentialArcTo([3.14 + 0, 13.14 + 0], %)`
|
||||
test.each([
|
||||
[' line([3 + 0, 4], %)', 'arrayIndex', 1],
|
||||
[' line(end = [3 + 0, 4])', 'arrayIndex', 1],
|
||||
[
|
||||
'angledLine({ angle = 3, length = 3.14 + 0 }, %)',
|
||||
'objectProperty',
|
||||
'angle',
|
||||
],
|
||||
['lineTo([6.14, 3.14 + 0], %)', 'arrayIndex', 0],
|
||||
['line(endAbsolute = [6.14, 3.14 + 0])', 'arrayIndex', 0],
|
||||
['xLineTo(8, %)', '', ''],
|
||||
['yLineTo(5, %)', '', ''],
|
||||
['yLine(3.14, %, $a)', '', ''],
|
||||
@ -724,12 +724,12 @@ describe('Testing deleteFromSelection', () => {
|
||||
codeBefore: `myVar = 5
|
||||
sketch003 = startSketchOn('XZ')
|
||||
|> startProfileAt([3.82, 13.6], %)
|
||||
|> line([-2.94, 2.7], %)
|
||||
|> line([7.7, 0.16], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)`,
|
||||
|> line(end = [-2.94, 2.7])
|
||||
|> line(end = [7.7, 0.16])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()`,
|
||||
codeAfter: `myVar = 5\n`,
|
||||
lineOfInterest: 'line([-2.94, 2.7], %)',
|
||||
lineOfInterest: 'line(end = [-2.94, 2.7])',
|
||||
type: 'segment',
|
||||
},
|
||||
],
|
||||
@ -738,24 +738,24 @@ sketch003 = startSketchOn('XZ')
|
||||
{
|
||||
codeBefore: `sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> line([2.48, 2.44], %)
|
||||
|> line([2.66, 1.17], %)
|
||||
|> line([3.75, 0.46], %)
|
||||
|> line([4.99, -0.46], %, $seg01)
|
||||
|> line([-3.86, -2.73], %)
|
||||
|> line([-17.67, 0.85], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(10, sketch001)`,
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [2.66, 1.17])
|
||||
|> line(end = [3.75, 0.46])
|
||||
|> line(end = [4.99, -0.46], tag = $seg01)
|
||||
|> line(end = [-3.86, -2.73])
|
||||
|> line(end = [-17.67, 0.85])
|
||||
|> close()
|
||||
const extrude001 = extrude(sketch001, length = 10)`,
|
||||
codeAfter: `sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> line([2.48, 2.44], %)
|
||||
|> line([2.66, 1.17], %)
|
||||
|> line([3.75, 0.46], %)
|
||||
|> line([4.99, -0.46], %, $seg01)
|
||||
|> line([-3.86, -2.73], %)
|
||||
|> line([-17.67, 0.85], %)
|
||||
|> close(%)\n`,
|
||||
lineOfInterest: 'line([2.66, 1.17], %)',
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [2.66, 1.17])
|
||||
|> line(end = [3.75, 0.46])
|
||||
|> line(end = [4.99, -0.46], tag = $seg01)
|
||||
|> line(end = [-3.86, -2.73])
|
||||
|> line(end = [-17.67, 0.85])
|
||||
|> close()\n`,
|
||||
lineOfInterest: 'line(end = [2.66, 1.17])',
|
||||
type: 'wall',
|
||||
},
|
||||
],
|
||||
@ -765,35 +765,35 @@ const extrude001 = extrude(10, sketch001)`,
|
||||
codeBefore: `myVar = 5
|
||||
sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([4.46, 5.12], %, $tag)
|
||||
|> line([0.08, myVar], %)
|
||||
|> line([13.03, 2.02], %, $seg01)
|
||||
|> line([3.9, -7.6], %)
|
||||
|> line([-11.18, -2.15], %)
|
||||
|> line([5.41, -9.61], %)
|
||||
|> line([-8.54, -2.51], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(5, sketch001)
|
||||
|> line(end = [0.08, myVar])
|
||||
|> line(end = [13.03, 2.02], tag = $seg01)
|
||||
|> line(end = [3.9, -7.6])
|
||||
|> line(end = [-11.18, -2.15])
|
||||
|> line(end = [5.41, -9.61])
|
||||
|> line(end = [-8.54, -2.51])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
const extrude001 = extrude(sketch001, length = 5)
|
||||
sketch002 = startSketchOn(extrude001, seg01)
|
||||
|> startProfileAt([-12.55, 2.89], %)
|
||||
|> line([3.02, 1.9], %)
|
||||
|> line([1.82, -1.49], %, $seg02)
|
||||
|> line(end = [3.02, 1.9])
|
||||
|> line(end = [1.82, -1.49], tag = $seg02)
|
||||
|> angledLine([-86, segLen(seg02)], %)
|
||||
|> line([-3.97, -0.53], %)
|
||||
|> line([0.3, 0.84], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)`,
|
||||
|> line(end = [-3.97, -0.53])
|
||||
|> line(end = [0.3, 0.84])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()`,
|
||||
codeAfter: `myVar = 5
|
||||
sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([4.46, 5.12], %, $tag)
|
||||
|> line([0.08, myVar], %)
|
||||
|> line([13.03, 2.02], %, $seg01)
|
||||
|> line([3.9, -7.6], %)
|
||||
|> line([-11.18, -2.15], %)
|
||||
|> line([5.41, -9.61], %)
|
||||
|> line([-8.54, -2.51], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [0.08, myVar])
|
||||
|> line(end = [13.03, 2.02], tag = $seg01)
|
||||
|> line(end = [3.9, -7.6])
|
||||
|> line(end = [-11.18, -2.15])
|
||||
|> line(end = [5.41, -9.61])
|
||||
|> line(end = [-8.54, -2.51])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch002 = startSketchOn({
|
||||
plane = {
|
||||
origin = { x = 1, y = 2, z = 3 },
|
||||
@ -803,15 +803,15 @@ sketch002 = startSketchOn({
|
||||
}
|
||||
})
|
||||
|> startProfileAt([-12.55, 2.89], %)
|
||||
|> line([3.02, 1.9], %)
|
||||
|> line([1.82, -1.49], %, $seg02)
|
||||
|> line(end = [3.02, 1.9])
|
||||
|> line(end = [1.82, -1.49], tag = $seg02)
|
||||
|> angledLine([-86, segLen(seg02)], %)
|
||||
|> line([-3.97, -0.53], %)
|
||||
|> line([0.3, 0.84], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [-3.97, -0.53])
|
||||
|> line(end = [0.3, 0.84])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
`,
|
||||
lineOfInterest: 'line([-11.18, -2.15], %)',
|
||||
lineOfInterest: 'line(end = [-11.18, -2.15])',
|
||||
type: 'wall',
|
||||
},
|
||||
],
|
||||
@ -821,35 +821,35 @@ sketch002 = startSketchOn({
|
||||
codeBefore: `myVar = 5
|
||||
sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([4.46, 5.12], %, $tag)
|
||||
|> line([0.08, myVar], %)
|
||||
|> line([13.03, 2.02], %, $seg01)
|
||||
|> line([3.9, -7.6], %)
|
||||
|> line([-11.18, -2.15], %)
|
||||
|> line([5.41, -9.61], %)
|
||||
|> line([-8.54, -2.51], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(5, sketch001)
|
||||
|> line(end = [0.08, myVar])
|
||||
|> line(end = [13.03, 2.02], tag = $seg01)
|
||||
|> line(end = [3.9, -7.6])
|
||||
|> line(end = [-11.18, -2.15])
|
||||
|> line(end = [5.41, -9.61])
|
||||
|> line(end = [-8.54, -2.51])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
const extrude001 = extrude(sketch001, length = 5)
|
||||
sketch002 = startSketchOn(extrude001, seg01)
|
||||
|> startProfileAt([-12.55, 2.89], %)
|
||||
|> line([3.02, 1.9], %)
|
||||
|> line([1.82, -1.49], %, $seg02)
|
||||
|> line(end = [3.02, 1.9])
|
||||
|> line(end = [1.82, -1.49], tag = $seg02)
|
||||
|> angledLine([-86, segLen(seg02)], %)
|
||||
|> line([-3.97, -0.53], %)
|
||||
|> line([0.3, 0.84], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)`,
|
||||
|> line(end = [-3.97, -0.53])
|
||||
|> line(end = [0.3, 0.84])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()`,
|
||||
codeAfter: `myVar = 5
|
||||
sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([4.46, 5.12], %, $tag)
|
||||
|> line([0.08, myVar], %)
|
||||
|> line([13.03, 2.02], %, $seg01)
|
||||
|> line([3.9, -7.6], %)
|
||||
|> line([-11.18, -2.15], %)
|
||||
|> line([5.41, -9.61], %)
|
||||
|> line([-8.54, -2.51], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [0.08, myVar])
|
||||
|> line(end = [13.03, 2.02], tag = $seg01)
|
||||
|> line(end = [3.9, -7.6])
|
||||
|> line(end = [-11.18, -2.15])
|
||||
|> line(end = [5.41, -9.61])
|
||||
|> line(end = [-8.54, -2.51])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch002 = startSketchOn({
|
||||
plane = {
|
||||
origin = { x = 1, y = 2, z = 3 },
|
||||
@ -859,13 +859,13 @@ sketch002 = startSketchOn({
|
||||
}
|
||||
})
|
||||
|> startProfileAt([-12.55, 2.89], %)
|
||||
|> line([3.02, 1.9], %)
|
||||
|> line([1.82, -1.49], %, $seg02)
|
||||
|> line(end = [3.02, 1.9])
|
||||
|> line(end = [1.82, -1.49], tag = $seg02)
|
||||
|> angledLine([-86, segLen(seg02)], %)
|
||||
|> line([-3.97, -0.53], %)
|
||||
|> line([0.3, 0.84], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [-3.97, -0.53])
|
||||
|> line(end = [0.3, 0.84])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
`,
|
||||
lineOfInterest: 'startProfileAt([4.46, 5.12], %, $tag)',
|
||||
type: 'cap',
|
||||
@ -875,7 +875,7 @@ sketch002 = startSketchOn({
|
||||
test.each(cases)(
|
||||
'%s',
|
||||
async (name, { codeBefore, codeAfter, lineOfInterest, type }) => {
|
||||
// const lineOfInterest = 'line([-2.94, 2.7], %)'
|
||||
// const lineOfInterest = 'line(end = [-2.94, 2.7])'
|
||||
const ast = assertParse(codeBefore)
|
||||
const execState = await enginelessExecutor(ast)
|
||||
|
||||
|
@ -152,14 +152,14 @@ describe('Testing getPathToExtrudeForSegmentSelection', () => {
|
||||
it('should return the correct paths for a valid selection and extrusion', async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)`
|
||||
const selectedSegmentSnippet = `line([20, 0], %)`
|
||||
const expectedExtrudeSnippet = `extrude001 = extrude(-15, sketch001)`
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)`
|
||||
const selectedSegmentSnippet = `line(end = [20, 0])`
|
||||
const expectedExtrudeSnippet = `extrude001 = extrude(sketch001, length = -15)`
|
||||
await runGetPathToExtrudeForSegmentSelectionTest(
|
||||
code,
|
||||
selectedSegmentSnippet,
|
||||
@ -169,14 +169,14 @@ extrude001 = extrude(-15, sketch001)`
|
||||
it('should return the correct paths when extrusion occurs within the sketch pipe', async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> extrude(15, %)`
|
||||
const selectedSegmentSnippet = `line([20, 0], %)`
|
||||
const expectedExtrudeSnippet = `extrude(15, %)`
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
|> extrude(length = 15)`
|
||||
const selectedSegmentSnippet = `line(end = [20, 0])`
|
||||
const expectedExtrudeSnippet = `extrude(length = 15)`
|
||||
await runGetPathToExtrudeForSegmentSelectionTest(
|
||||
code,
|
||||
selectedSegmentSnippet,
|
||||
@ -186,30 +186,30 @@ extrude001 = extrude(-15, sketch001)`
|
||||
it('should return the correct paths for a valid selection and extrusion in case of several extrusions and sketches', async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-30, 30], %)
|
||||
|> line([15, 0], %)
|
||||
|> line([0, -15], %)
|
||||
|> line([-15, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [15, 0])
|
||||
|> line(end = [0, -15])
|
||||
|> line(end = [-15, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch002 = startSketchOn('XY')
|
||||
|> startProfileAt([30, 30], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch003 = startSketchOn('XY')
|
||||
|> startProfileAt([30, -30], %)
|
||||
|> line([25, 0], %)
|
||||
|> line([0, -25], %)
|
||||
|> line([-25, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
extrude002 = extrude(-15, sketch002)
|
||||
extrude003 = extrude(-15, sketch003)`
|
||||
const selectedSegmentSnippet = `line([20, 0], %)`
|
||||
const expectedExtrudeSnippet = `extrude002 = extrude(-15, sketch002)`
|
||||
|> line(end = [25, 0])
|
||||
|> line(end = [0, -25])
|
||||
|> line(end = [-25, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
extrude002 = extrude(sketch002, length = -15)
|
||||
extrude003 = extrude(sketch003, length = -15)`
|
||||
const selectedSegmentSnippet = `line(end = [20, 0])`
|
||||
const expectedExtrudeSnippet = `extrude002 = extrude(sketch002, length = -15)`
|
||||
await runGetPathToExtrudeForSegmentSelectionTest(
|
||||
code,
|
||||
selectedSegmentSnippet,
|
||||
@ -219,28 +219,28 @@ extrude003 = extrude(-15, sketch003)`
|
||||
it('should not return any path for missing extrusion', async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-30, 30], %)
|
||||
|> line([15, 0], %)
|
||||
|> line([0, -15], %)
|
||||
|> line([-15, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [15, 0])
|
||||
|> line(end = [0, -15])
|
||||
|> line(end = [-15, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch002 = startSketchOn('XY')
|
||||
|> startProfileAt([30, 30], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch003 = startSketchOn('XY')
|
||||
|> startProfileAt([30, -30], %)
|
||||
|> line([25, 0], %)
|
||||
|> line([0, -25], %)
|
||||
|> line([-25, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
extrude003 = extrude(-15, sketch003)`
|
||||
const selectedSegmentSnippet = `line([20, 0], %)`
|
||||
|> line(end = [25, 0])
|
||||
|> line(end = [0, -25])
|
||||
|> line(end = [-25, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
extrude003 = extrude(sketch003, length = -15)`
|
||||
const selectedSegmentSnippet = `line(end = [20, 0])`
|
||||
const expectedExtrudeSnippet = ``
|
||||
await runGetPathToExtrudeForSegmentSelectionTest(
|
||||
code,
|
||||
@ -334,21 +334,21 @@ Object.values(EdgeTreatmentType).forEach(
|
||||
it(`should add a ${edgeTreatmentType} to a specific segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)`
|
||||
const segmentSnippets = ['line([0, -20], %)']
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)`
|
||||
const segmentSnippets = ['line(end = [0, -20])']
|
||||
const expectedCode = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %, $seg01)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20], tag = $seg01)
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
|> ${edgeTreatmentType}({ ${parameterName} = 3, tags = [seg01] }, %)`
|
||||
|
||||
await runModifyAstCloneWithEdgeTreatmentAndTag(
|
||||
@ -361,21 +361,21 @@ extrude001 = extrude(-15, sketch001)
|
||||
it(`should add a ${edgeTreatmentType} to the sketch pipe`, async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> extrude(-15, %)`
|
||||
const segmentSnippets = ['line([0, -20], %)']
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
|> extrude(length = -15)`
|
||||
const segmentSnippets = ['line(end = [0, -20])']
|
||||
const expectedCode = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %, $seg01)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> extrude(-15, %)
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20], tag = $seg01)
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
|> extrude(length = -15)
|
||||
|> ${edgeTreatmentType}({ ${parameterName} = 3, tags = [seg01] }, %)`
|
||||
|
||||
await runModifyAstCloneWithEdgeTreatmentAndTag(
|
||||
@ -388,21 +388,21 @@ extrude001 = extrude(-15, sketch001)
|
||||
it(`should add a ${edgeTreatmentType} to an already tagged segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %, $seg01)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)`
|
||||
const segmentSnippets = ['line([0, -20], %, $seg01)']
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20], tag = $seg01)
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)`
|
||||
const segmentSnippets = ['line(end = [0, -20], tag = $seg01)']
|
||||
const expectedCode = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %, $seg01)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20], tag = $seg01)
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
|> ${edgeTreatmentType}({ ${parameterName} = 3, tags = [seg01] }, %)`
|
||||
|
||||
await runModifyAstCloneWithEdgeTreatmentAndTag(
|
||||
@ -415,21 +415,21 @@ extrude001 = extrude(-15, sketch001)
|
||||
it(`should add a ${edgeTreatmentType} with existing tag on other segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %, $seg01)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)`
|
||||
const segmentSnippets = ['line([-20, 0], %)']
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)`
|
||||
const segmentSnippets = ['line(end = [-20, 0])']
|
||||
const expectedCode = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %, $seg01)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %, $seg02)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
|> ${edgeTreatmentType}({ ${parameterName} = 3, tags = [seg02] }, %)`
|
||||
|
||||
await runModifyAstCloneWithEdgeTreatmentAndTag(
|
||||
@ -442,22 +442,22 @@ extrude001 = extrude(-15, sketch001)
|
||||
it(`should add a ${edgeTreatmentType} with existing fillet on other segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %, $seg01)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
|> fillet({ radius = 5, tags = [seg01] }, %)`
|
||||
const segmentSnippets = ['line([-20, 0], %)']
|
||||
const segmentSnippets = ['line(end = [-20, 0])']
|
||||
const expectedCode = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %, $seg01)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %, $seg02)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
|> fillet({ radius = 5, tags = [seg01] }, %)
|
||||
|> ${edgeTreatmentType}({ ${parameterName} = 3, tags = [seg02] }, %)`
|
||||
|
||||
@ -471,22 +471,22 @@ extrude001 = extrude(-15, sketch001)
|
||||
it(`should add a ${edgeTreatmentType} with existing chamfer on other segment`, async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %, $seg01)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
|> chamfer({ length = 5, tags = [seg01] }, %)`
|
||||
const segmentSnippets = ['line([-20, 0], %)']
|
||||
const segmentSnippets = ['line(end = [-20, 0])']
|
||||
const expectedCode = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %, $seg01)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %, $seg02)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
|> chamfer({ length = 5, tags = [seg01] }, %)
|
||||
|> ${edgeTreatmentType}({ ${parameterName} = 3, tags = [seg02] }, %)`
|
||||
|
||||
@ -500,21 +500,21 @@ extrude001 = extrude(-15, sketch001)
|
||||
it(`should add a ${edgeTreatmentType} to two segments of a single extrusion`, async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)`
|
||||
const segmentSnippets = ['line([20, 0], %)', 'line([-20, 0], %)']
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)`
|
||||
const segmentSnippets = ['line(end = [20, 0], %)', 'line([-20, 0])']
|
||||
const expectedCode = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %, $seg01)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %, $seg02)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
|> ${edgeTreatmentType}({ ${parameterName} = 3, tags = [seg01, seg02] }, %)`
|
||||
|
||||
await runModifyAstCloneWithEdgeTreatmentAndTag(
|
||||
@ -527,42 +527,42 @@ extrude001 = extrude(-15, sketch001)
|
||||
it(`should add ${edgeTreatmentType}s to two bodies`, async () => {
|
||||
const code = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
sketch002 = startSketchOn('XY')
|
||||
|> startProfileAt([30, 10], %)
|
||||
|> line([15, 0], %)
|
||||
|> line([0, -15], %)
|
||||
|> line([-15, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude002 = extrude(-25, sketch002)` // <--- body 2
|
||||
|> line(end = [15, 0])
|
||||
|> line(end = [0, -15])
|
||||
|> line(end = [-15, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude002 = extrude(sketch002, length = -25)` // <--- body 2
|
||||
const segmentSnippets = [
|
||||
'line([20, 0], %)',
|
||||
'line([-20, 0], %)',
|
||||
'line([0, -15], %)',
|
||||
'line(end = [20, 0])',
|
||||
'line(end = [-20, 0])',
|
||||
'line(end = [0, -15])',
|
||||
]
|
||||
const expectedCode = `sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %, $seg01)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %, $seg02)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-15, sketch001)
|
||||
|> line(end = [20, 0], tag = $seg01)
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0], tag = $seg02)
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -15)
|
||||
|> ${edgeTreatmentType}({ ${parameterName} = 3, tags = [seg01, seg02] }, %)
|
||||
sketch002 = startSketchOn('XY')
|
||||
|> startProfileAt([30, 10], %)
|
||||
|> line([15, 0], %)
|
||||
|> line([0, -15], %, $seg03)
|
||||
|> line([-15, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude002 = extrude(-25, sketch002)
|
||||
|> line(end = [15, 0])
|
||||
|> line(end = [0, -15], tag = $seg03)
|
||||
|> line(end = [-15, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude002 = extrude(sketch002, length = -25)
|
||||
|> ${edgeTreatmentType}({ ${parameterName} = 3, tags = [seg03] }, %)` // <-- able to add a new one
|
||||
|
||||
await runModifyAstCloneWithEdgeTreatmentAndTag(
|
||||
@ -579,11 +579,11 @@ extrude002 = extrude(-25, sketch002)
|
||||
describe('Testing isTagUsedInEdgeTreatment', () => {
|
||||
const code = `sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([7.72, 4.13], %)
|
||||
|> line([7.11, 3.48], %, $seg01)
|
||||
|> line([-3.29, -13.85], %)
|
||||
|> line([-6.37, 3.88], %, $seg02)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-5, sketch001)
|
||||
|> line(end = [7.11, 3.48], tag = $seg01)
|
||||
|> line(end = [-3.29, -13.85])
|
||||
|> line(end = [-6.37, 3.88], tag = $seg02)
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -5)
|
||||
|> fillet({
|
||||
radius = 1.11,
|
||||
tags = [
|
||||
@ -595,7 +595,7 @@ extrude001 = extrude(-5, sketch001)
|
||||
`
|
||||
it('should correctly identify getOppositeEdge and baseEdge edges', () => {
|
||||
const ast = assertParse(code)
|
||||
const lineOfInterest = `line([7.11, 3.48], %, $seg01)`
|
||||
const lineOfInterest = `line(end = [7.11, 3.48], tag = $seg01)`
|
||||
const range = topLevelRange(
|
||||
code.indexOf(lineOfInterest),
|
||||
code.indexOf(lineOfInterest) + lineOfInterest.length
|
||||
@ -613,7 +613,7 @@ extrude001 = extrude(-5, sketch001)
|
||||
})
|
||||
it('should correctly identify getPreviousAdjacentEdge edges', () => {
|
||||
const ast = assertParse(code)
|
||||
const lineOfInterest = `line([-6.37, 3.88], %, $seg02)`
|
||||
const lineOfInterest = `line(end = [-6.37, 3.88], tag = $seg02)`
|
||||
const range = topLevelRange(
|
||||
code.indexOf(lineOfInterest),
|
||||
code.indexOf(lineOfInterest) + lineOfInterest.length
|
||||
@ -631,7 +631,7 @@ extrude001 = extrude(-5, sketch001)
|
||||
})
|
||||
it('should correctly identify no edges', () => {
|
||||
const ast = assertParse(code)
|
||||
const lineOfInterest = `line([-3.29, -13.85], %)`
|
||||
const lineOfInterest = `line(end = [-3.29, -13.85])`
|
||||
const range = topLevelRange(
|
||||
code.indexOf(lineOfInterest),
|
||||
code.indexOf(lineOfInterest) + lineOfInterest.length
|
||||
@ -685,28 +685,28 @@ describe('Testing button states', () => {
|
||||
const codeWithBody: string = `
|
||||
sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-20, -5], %)
|
||||
|> line([0, 10], %)
|
||||
|> line([10, 0], %)
|
||||
|> line([0, -10], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(-10, sketch001)
|
||||
|> line(end = [0, 10])
|
||||
|> line(end = [10, 0])
|
||||
|> line(end = [0, -10])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = -10)
|
||||
`
|
||||
const codeWithoutBodies: string = `
|
||||
sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-20, -5], %)
|
||||
|> line([0, 10], %)
|
||||
|> line([10, 0], %)
|
||||
|> line([0, -10], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [0, 10])
|
||||
|> line(end = [10, 0])
|
||||
|> line(end = [0, -10])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
`
|
||||
// body is missing
|
||||
it('should return false when body is missing and nothing is selected', async () => {
|
||||
await runButtonStateTest(codeWithoutBodies, '', false)
|
||||
})
|
||||
it('should return false when body is missing and segment is selected', async () => {
|
||||
await runButtonStateTest(codeWithoutBodies, `line([10, 0], %)`, false)
|
||||
await runButtonStateTest(codeWithoutBodies, `line(end = [10, 0])`, false)
|
||||
})
|
||||
|
||||
// body exists
|
||||
@ -714,9 +714,9 @@ describe('Testing button states', () => {
|
||||
await runButtonStateTest(codeWithBody, '', true)
|
||||
})
|
||||
it('should return true when body exists and segment is selected', async () => {
|
||||
await runButtonStateTest(codeWithBody, `line([10, 0], %)`, true)
|
||||
await runButtonStateTest(codeWithBody, `line(end = [10, 0])`, true)
|
||||
})
|
||||
it('should return false when body exists and not a segment is selected', async () => {
|
||||
await runButtonStateTest(codeWithBody, `close(%)`, false)
|
||||
await runButtonStateTest(codeWithBody, `close()`, false)
|
||||
})
|
||||
})
|
||||
|
@ -77,7 +77,7 @@ variableBelowShouldNotBeIncluded = 3
|
||||
describe('testing argIsNotIdentifier', () => {
|
||||
const code = `part001 = startSketchOn('XY')
|
||||
|> startProfileAt([-1.2, 4.83], %)
|
||||
|> line([2.8, 0], %)
|
||||
|> line(end = [2.8, 0])
|
||||
|> angledLine([100 + 100, 3.09], %)
|
||||
|> angledLine([abc, 3.09], %)
|
||||
|> angledLine([def('yo'), 3.09], %)
|
||||
@ -150,7 +150,7 @@ yo2 = hmm([identifierGuy + 5])`
|
||||
expect(result.isSafe).toBe(false)
|
||||
expect(result.value?.type).toBe('CallExpression')
|
||||
expect(code.slice(result.value.start, result.value.end)).toBe(
|
||||
'line([2.8, 0], %)'
|
||||
'line(end = [2.8, 0])'
|
||||
)
|
||||
})
|
||||
it("find a safe BinaryExpression that's assigned to a variable", () => {
|
||||
@ -237,10 +237,10 @@ yo2 = hmm([identifierGuy + 5])`
|
||||
describe('testing getNodePathFromSourceRange', () => {
|
||||
const code = `part001 = startSketchOn('XY')
|
||||
|> startProfileAt([0.39, -0.05], %)
|
||||
|> line([0.94, 2.61], %)
|
||||
|> line([-0.21, -1.4], %)`
|
||||
|> line(end = [0.94, 2.61])
|
||||
|> line(end = [-0.21, -1.4])`
|
||||
it('finds the second line when cursor is put at the end', () => {
|
||||
const searchLn = `line([0.94, 2.61], %)`
|
||||
const searchLn = `line(end = [0.94, 2.61])`
|
||||
const sourceIndex = code.indexOf(searchLn) + searchLn.length
|
||||
const ast = assertParse(code)
|
||||
|
||||
@ -258,7 +258,7 @@ describe('testing getNodePathFromSourceRange', () => {
|
||||
])
|
||||
})
|
||||
it('finds the last line when cursor is put at the end', () => {
|
||||
const searchLn = `line([-0.21, -1.4], %)`
|
||||
const searchLn = `line(end = [-0.21, -1.4])`
|
||||
const sourceIndex = code.indexOf(searchLn) + searchLn.length
|
||||
const ast = assertParse(code)
|
||||
|
||||
@ -380,9 +380,9 @@ describe('testing hasExtrudeSketch', () => {
|
||||
it('find sketch', async () => {
|
||||
const exampleCode = `length001 = 2
|
||||
part001 = startSketchAt([-1.41, 3.46])
|
||||
|> line([19.49, 1.16], %, $seg01)
|
||||
|> line(end = [19.49, 1.16], tag = $seg01)
|
||||
|> angledLine([-35, length001], %)
|
||||
|> line([-3.22, -7.36], %)
|
||||
|> line(end = [-3.22, -7.36])
|
||||
|> angledLine([-175, segLen(seg01)], %)`
|
||||
const ast = assertParse(exampleCode)
|
||||
|
||||
@ -399,11 +399,11 @@ part001 = startSketchAt([-1.41, 3.46])
|
||||
it('find solid', async () => {
|
||||
const exampleCode = `length001 = 2
|
||||
part001 = startSketchAt([-1.41, 3.46])
|
||||
|> line([19.49, 1.16], %, $seg01)
|
||||
|> line(end = [19.49, 1.16], tag = $seg01)
|
||||
|> angledLine([-35, length001], %)
|
||||
|> line([-3.22, -7.36], %)
|
||||
|> line(end = [-3.22, -7.36])
|
||||
|> angledLine([-175, segLen(seg01)], %)
|
||||
|> extrude(1, %)`
|
||||
|> extrude(length = 1)`
|
||||
const ast = assertParse(exampleCode)
|
||||
|
||||
const execState = await enginelessExecutor(ast)
|
||||
@ -435,10 +435,10 @@ part001 = startSketchAt([-1.41, 3.46])
|
||||
describe('Testing findUsesOfTagInPipe', () => {
|
||||
const exampleCode = `part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([68.12, 156.65], %)
|
||||
|> line([306.21, 198.82], %)
|
||||
|> line([306.21, 198.85], %, $seg01)
|
||||
|> line(end = [306.21, 198.82])
|
||||
|> line(end = [306.21, 198.85], tag = $seg01)
|
||||
|> angledLine([-65, segLen(seg01)], %)
|
||||
|> line([306.21, 198.87], %)
|
||||
|> line(end = [306.21, 198.87])
|
||||
|> angledLine([65, segLen(seg01)], %)`
|
||||
it('finds the current segment', async () => {
|
||||
const ast = assertParse(exampleCode)
|
||||
@ -459,7 +459,7 @@ describe('Testing findUsesOfTagInPipe', () => {
|
||||
it('find no tag if line has no tag', () => {
|
||||
const ast = assertParse(exampleCode)
|
||||
|
||||
const lineOfInterest = `line([306.21, 198.82], %)`
|
||||
const lineOfInterest = `line(end = [306.21, 198.82])`
|
||||
const characterIndex =
|
||||
exampleCode.indexOf(lineOfInterest) + lineOfInterest.length
|
||||
const pathToNode = getNodePathFromSourceRange(
|
||||
@ -474,39 +474,39 @@ describe('Testing findUsesOfTagInPipe', () => {
|
||||
describe('Testing hasSketchPipeBeenExtruded', () => {
|
||||
const exampleCode = `sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> line([2.48, 2.44], %)
|
||||
|> line([2.66, 1.17], %)
|
||||
|> line([3.75, 0.46], %)
|
||||
|> line([4.99, -0.46], %, $seg01)
|
||||
|> line([3.3, -2.12], %)
|
||||
|> line([2.16, -3.33], %)
|
||||
|> line([0.85, -3.08], %)
|
||||
|> line([-0.18, -3.36], %)
|
||||
|> line([-3.86, -2.73], %)
|
||||
|> line([-17.67, 0.85], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(10, sketch001)
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [2.66, 1.17])
|
||||
|> line(end = [3.75, 0.46])
|
||||
|> line(end = [4.99, -0.46], tag = $seg01)
|
||||
|> line(end = [3.3, -2.12])
|
||||
|> line(end = [2.16, -3.33])
|
||||
|> line(end = [0.85, -3.08])
|
||||
|> line(end = [-0.18, -3.36])
|
||||
|> line(end = [-3.86, -2.73])
|
||||
|> line(end = [-17.67, 0.85])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = 10)
|
||||
sketch002 = startSketchOn(extrude001, seg01)
|
||||
|> startProfileAt([-12.94, 6.6], %)
|
||||
|> line([2.45, -0.2], %)
|
||||
|> line([-2, -1.25], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [2.45, -0.2])
|
||||
|> line(end = [-2, -1.25])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
sketch003 = startSketchOn(extrude001, 'END')
|
||||
|> startProfileAt([8.14, 2.8], %)
|
||||
|> line([-1.24, 4.39], %)
|
||||
|> line([3.79, 1.91], %)
|
||||
|> line([1.77, -2.95], %)
|
||||
|> line([3.12, 1.74], %)
|
||||
|> line([1.91, -4.09], %)
|
||||
|> line([-5.6, -2.75], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> extrude(3.14, %)
|
||||
|> line(end = [-1.24, 4.39])
|
||||
|> line(end = [3.79, 1.91])
|
||||
|> line(end = [1.77, -2.95])
|
||||
|> line(end = [3.12, 1.74])
|
||||
|> line(end = [1.91, -4.09])
|
||||
|> line(end = [-5.6, -2.75])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
|> extrude(length = 3.14)
|
||||
`
|
||||
it('identifies sketch001 pipe as extruded (extrusion after pipe)', async () => {
|
||||
const ast = assertParse(exampleCode)
|
||||
const lineOfInterest = `line([4.99, -0.46], %, $seg01)`
|
||||
const lineOfInterest = `line(end = [4.99, -0.46], tag = $seg01)`
|
||||
const characterIndex =
|
||||
exampleCode.indexOf(lineOfInterest) + lineOfInterest.length
|
||||
const extruded = hasSketchPipeBeenExtruded(
|
||||
@ -522,7 +522,7 @@ sketch003 = startSketchOn(extrude001, 'END')
|
||||
})
|
||||
it('identifies sketch002 pipe as not extruded', async () => {
|
||||
const ast = assertParse(exampleCode)
|
||||
const lineOfInterest = `line([2.45, -0.2], %)`
|
||||
const lineOfInterest = `line(end = [2.45, -0.2])`
|
||||
const characterIndex =
|
||||
exampleCode.indexOf(lineOfInterest) + lineOfInterest.length
|
||||
const extruded = hasSketchPipeBeenExtruded(
|
||||
@ -538,7 +538,7 @@ sketch003 = startSketchOn(extrude001, 'END')
|
||||
})
|
||||
it('identifies sketch003 pipe as extruded (extrusion within pipe)', async () => {
|
||||
const ast = assertParse(exampleCode)
|
||||
const lineOfInterest = `|> line([3.12, 1.74], %)`
|
||||
const lineOfInterest = `|> line(end = [3.12, 1.74])`
|
||||
const characterIndex =
|
||||
exampleCode.indexOf(lineOfInterest) + lineOfInterest.length
|
||||
const extruded = hasSketchPipeBeenExtruded(
|
||||
@ -558,17 +558,17 @@ describe('Testing doesSceneHaveSweepableSketch', () => {
|
||||
it('finds sketch001 pipe to be extruded', async () => {
|
||||
const exampleCode = `sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> line([2.48, 2.44], %)
|
||||
|> line([-3.86, -2.73], %)
|
||||
|> line([-17.67, 0.85], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(10, sketch001)
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [-3.86, -2.73])
|
||||
|> line(end = [-17.67, 0.85])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = 10)
|
||||
sketch002 = startSketchOn(extrude001, $seg01)
|
||||
|> startProfileAt([-12.94, 6.6], %)
|
||||
|> line([2.45, -0.2], %)
|
||||
|> line([-2, -1.25], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(end = [2.45, -0.2])
|
||||
|> line(end = [-2, -1.25])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
`
|
||||
const ast = assertParse(exampleCode)
|
||||
const extrudable = doesSceneHaveSweepableSketch(ast)
|
||||
@ -588,11 +588,11 @@ sketch002 = startSketchOn(plane001)
|
||||
it('find sketch002 NOT pipe to be extruded', async () => {
|
||||
const exampleCode = `sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> line([2.48, 2.44], %)
|
||||
|> line([-3.86, -2.73], %)
|
||||
|> line([-17.67, 0.85], %)
|
||||
|> close(%)
|
||||
extrude001 = extrude(10, sketch001)
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [-3.86, -2.73])
|
||||
|> line(end = [-17.67, 0.85])
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = 10)
|
||||
`
|
||||
const ast = assertParse(exampleCode)
|
||||
const extrudable = doesSceneHaveSweepableSketch(ast)
|
||||
@ -604,7 +604,7 @@ describe('Testing doesSceneHaveExtrudedSketch', () => {
|
||||
it('finds extruded sketch as variable', async () => {
|
||||
const exampleCode = `sketch001 = startSketchOn('XZ')
|
||||
|> circle({ center = [0, 0], radius = 1 }, %)
|
||||
extrude001 = extrude(1, sketch001)
|
||||
extrude001 = extrude(sketch001, length = 1)
|
||||
`
|
||||
const ast = assertParse(exampleCode)
|
||||
if (err(ast)) throw ast
|
||||
@ -614,7 +614,7 @@ extrude001 = extrude(1, sketch001)
|
||||
it('finds extruded sketch in pipe', async () => {
|
||||
const exampleCode = `extrude001 = startSketchOn('XZ')
|
||||
|> circle({ center = [0, 0], radius = 1 }, %)
|
||||
|> extrude(1, %)
|
||||
|> extrude(length = 1)
|
||||
`
|
||||
const ast = assertParse(exampleCode)
|
||||
if (err(ast)) throw ast
|
||||
@ -643,10 +643,10 @@ describe('Testing traverse and pathToNode', () => {
|
||||
const code = `myVar = 5
|
||||
sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([3.29, 7.86], %)
|
||||
|> line([2.48, 2.44], %)
|
||||
|> line([-3.86, -2.73], %)
|
||||
|> line([-17.67, 0.85], %)
|
||||
|> close(%)
|
||||
|> line(end = [2.48, 2.44])
|
||||
|> line(end = [-3.86, -2.73])
|
||||
|> line(end = [-17.67, 0.85])
|
||||
|> close()
|
||||
bing = { yo: 55 }
|
||||
myNestedVar = [
|
||||
{
|
||||
|
@ -76,10 +76,10 @@ log(5, myVar)
|
||||
})
|
||||
it('recast sketch declaration', () => {
|
||||
let code = `mySketch = startSketchAt([0, 0])
|
||||
|> lineTo([0, 1], %, $myPath)
|
||||
|> lineTo([1, 1], %)
|
||||
|> lineTo([1, 0], %, $rightPath)
|
||||
|> close(%)
|
||||
|> line(endAbsolute = [0, 1], tag = $myPath)
|
||||
|> line(endAbsolute = [1, 1])
|
||||
|> line(endAbsolute = [1, 0], tag = $rightPath)
|
||||
|> close()
|
||||
`
|
||||
const { ast } = code2ast(code)
|
||||
const recasted = recast(ast)
|
||||
@ -89,9 +89,9 @@ log(5, myVar)
|
||||
it('sketch piped into callExpression', () => {
|
||||
const code = [
|
||||
'mySk1 = startSketchAt([0, 0])',
|
||||
' |> lineTo([1, 1], %)',
|
||||
' |> lineTo([0, 1], %, $myTag)',
|
||||
' |> lineTo([1, 1], %)',
|
||||
' |> line(endAbsolute = [1, 1])',
|
||||
' |> line(endAbsolute = [0, 1], tag = $myTag)',
|
||||
' |> line(endAbsolute = [1, 1])',
|
||||
' |> rx(90, %)',
|
||||
].join('\n')
|
||||
const { ast } = code2ast(code)
|
||||
@ -263,9 +263,9 @@ key = 'c'
|
||||
it('comments in a pipe expression', () => {
|
||||
const code = [
|
||||
'mySk1 = startSketchAt([0, 0])',
|
||||
' |> lineTo([1, 1], %)',
|
||||
' |> lineTo([0, 1], %, $myTag)',
|
||||
' |> lineTo([1, 1], %)',
|
||||
' |> line(endAbsolute = [1, 1])',
|
||||
' |> line(endAbsolute = [0, 1], tag = $myTag)',
|
||||
' |> line(endAbsolute = [1, 1])',
|
||||
' // a comment',
|
||||
' |> rx(90, %)',
|
||||
].join('\n')
|
||||
@ -279,10 +279,10 @@ key = 'c'
|
||||
/* comment at start */
|
||||
|
||||
mySk1 = startSketchAt([0, 0])
|
||||
|> lineTo([1, 1], %)
|
||||
|> line(endAbsolute = [1, 1])
|
||||
// comment here
|
||||
|> lineTo([0, 1], %, $myTag)
|
||||
|> lineTo([1, 1], %) /* and
|
||||
|> line(endAbsolute = [0, 1], tag = $myTag)
|
||||
|> line(endAbsolute = [1, 1]) /* and
|
||||
here
|
||||
*/
|
||||
// a comment between pipe expression statements
|
||||
@ -302,10 +302,10 @@ one more for good measure
|
||||
expect(recasted).toBe(`/* comment at start */
|
||||
|
||||
mySk1 = startSketchAt([0, 0])
|
||||
|> lineTo([1, 1], %)
|
||||
|> line(endAbsolute = [1, 1])
|
||||
// comment here
|
||||
|> lineTo([0, 1], %, $myTag)
|
||||
|> lineTo([1, 1], %) /* and
|
||||
|> line(endAbsolute = [0, 1], tag = $myTag)
|
||||
|> line(endAbsolute = [1, 1]) /* and
|
||||
here */
|
||||
// a comment between pipe expression statements
|
||||
|> rx(90, %)
|
||||
@ -342,7 +342,7 @@ describe('testing call Expressions in BinaryExpressions and UnaryExpressions', (
|
||||
it('with unaryExpression in sketch situation', () => {
|
||||
const code = [
|
||||
'part001 = startSketchAt([0, 0])',
|
||||
' |> line([-2.21, -legLen(5, min(3, 999))], %)',
|
||||
' |> line(end = [-2.21, -legLen(5, min(3, 999))])',
|
||||
].join('\n')
|
||||
const { ast } = code2ast(code)
|
||||
const recasted = recast(ast)
|
||||
@ -354,14 +354,14 @@ describe('testing call Expressions in BinaryExpressions and UnaryExpressions', (
|
||||
describe('it recasts wrapped object expressions in pipe bodies with correct indentation', () => {
|
||||
it('with a single line', () => {
|
||||
const code = `part001 = startSketchAt([-0.01, -0.08])
|
||||
|> line([0.62, 4.15], %, $seg01)
|
||||
|> line([2.77, -1.24], %)
|
||||
|> line(end = [0.62, 4.15], tag = $seg01)
|
||||
|> line(end = [2.77, -1.24])
|
||||
|> angledLineThatIntersects({
|
||||
angle = 201,
|
||||
offset = -1.35,
|
||||
intersectTag = $seg01
|
||||
}, %)
|
||||
|> line([-0.42, -1.72], %)
|
||||
|> line(end = [-0.42, -1.72])
|
||||
`
|
||||
const { ast } = code2ast(code)
|
||||
const recasted = recast(ast)
|
||||
|
@ -103,14 +103,14 @@ describe('testing getXComponent', () => {
|
||||
})
|
||||
|
||||
describe('testing changeSketchArguments', () => {
|
||||
const lineToChange = 'lineTo([-1.59, -1.54], %)'
|
||||
const lineAfterChange = 'lineTo([2, 3], %)'
|
||||
const lineToChange = 'line(endAbsolute = [-1.59, -1.54])'
|
||||
const lineAfterChange = 'line(endAbsolute = [2, 3])'
|
||||
test('changeSketchArguments', async () => {
|
||||
// Enable rotations #152
|
||||
const genCode = (line: string) => `mySketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> ${line}
|
||||
|> lineTo([0.46, -5.82], %)
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
// |> rx(45, %)
|
||||
`
|
||||
const code = genCode(lineToChange)
|
||||
@ -141,15 +141,15 @@ describe('testing changeSketchArguments', () => {
|
||||
})
|
||||
|
||||
describe('testing addNewSketchLn', () => {
|
||||
const lineToChange = 'lineTo([-1.59, -1.54], %)'
|
||||
const lineToChange = 'line(endAbsolute = [-1.59, -1.54])'
|
||||
test('addNewSketchLn', async () => {
|
||||
// Enable rotations #152
|
||||
const code = `
|
||||
mySketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
// |> rx(45, %)
|
||||
|> lineTo([-1.59, -1.54], %)
|
||||
|> lineTo([0.46, -5.82], %)`
|
||||
|> line(endAbsolute = [-1.59, -1.54])
|
||||
|> line(endAbsolute = [0.46, -5.82])`
|
||||
const ast = assertParse(code)
|
||||
|
||||
const execState = await enginelessExecutor(ast)
|
||||
@ -177,9 +177,9 @@ mySketch001 = startSketchOn('XY')
|
||||
let expectedCode = `mySketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
// |> rx(45, %)
|
||||
|> lineTo([-1.59, -1.54], %)
|
||||
|> lineTo([0.46, -5.82], %)
|
||||
|> lineTo([2, 3], %)
|
||||
|> line(endAbsolute = [-1.59, -1.54])
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
|> line(endAbsolute = [2, 3])
|
||||
`
|
||||
|
||||
const { modifiedAst } = newSketchLnRetVal
|
||||
@ -200,9 +200,9 @@ mySketch001 = startSketchOn('XY')
|
||||
expectedCode = `mySketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
// |> rx(45, %)
|
||||
|> lineTo([-1.59, -1.54], %)
|
||||
|> lineTo([0.46, -5.82], %)
|
||||
|> close(%)
|
||||
|> line(endAbsolute = [-1.59, -1.54])
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
|> close()
|
||||
`
|
||||
expect(recast(modifiedAst2)).toBe(expectedCode)
|
||||
})
|
||||
@ -210,13 +210,13 @@ mySketch001 = startSketchOn('XY')
|
||||
|
||||
describe('testing addTagForSketchOnFace', () => {
|
||||
it('needs to be in it', async () => {
|
||||
const originalLine = 'lineTo([-1.59, -1.54], %)'
|
||||
const originalLine = 'line(endAbsolute = [-1.59, -1.54])'
|
||||
// Enable rotations #152
|
||||
const genCode = (line: string) => `mySketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
// |> rx(45, %)
|
||||
|> ${line}
|
||||
|> lineTo([0.46, -5.82], %)
|
||||
|> line(endAbsolute = [0.46, -5.82])
|
||||
`
|
||||
const code = genCode(originalLine)
|
||||
const ast = assertParse(code)
|
||||
@ -240,7 +240,7 @@ describe('testing addTagForSketchOnFace', () => {
|
||||
if (err(sketchOnFaceRetVal)) return sketchOnFaceRetVal
|
||||
|
||||
const { modifiedAst } = sketchOnFaceRetVal
|
||||
const expectedCode = genCode('lineTo([-1.59, -1.54], %, $seg01)')
|
||||
const expectedCode = genCode('line(endAbsolute = [-1.59, -1.54], tag = $seg01)')
|
||||
expect(recast(modifiedAst)).toBe(expectedCode)
|
||||
})
|
||||
const chamferTestCases = [
|
||||
@ -284,9 +284,9 @@ describe('testing addTagForSketchOnFace', () => {
|
||||
segAng(rectangleSegmentA001),
|
||||
-segLen(rectangleSegmentA001)
|
||||
], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %, $seg02)
|
||||
|> close(%)
|
||||
extrude001 = extrude(100, sketch001)
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)], tag = $seg02)
|
||||
|> close()
|
||||
extrude001 = extrude(sketch001, length = 100)
|
||||
${insertCode}
|
||||
`
|
||||
const code = genCode(originalChamfer)
|
||||
@ -326,12 +326,12 @@ describe('testing getConstraintInfo', () => {
|
||||
describe('object notation', () => {
|
||||
const code = `const part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([0,0], %)
|
||||
|> line([3, 4], %)
|
||||
|> line(end = [3, 4])
|
||||
|> angledLine({
|
||||
angle = 3.14,
|
||||
length = 3.14,
|
||||
}, %)
|
||||
|> lineTo([6.14, 3.14], %)
|
||||
|> line(endAbsolute = [6.14, 3.14])
|
||||
|> xLineTo(8, %)
|
||||
|> yLineTo(5, %)
|
||||
|> yLine(3.14, %, $a)
|
||||
@ -700,9 +700,9 @@ describe('testing getConstraintInfo', () => {
|
||||
describe('array notation', () => {
|
||||
const code = `const part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([3, 4], %)
|
||||
|> line(end = [3, 4])
|
||||
|> angledLine([3.14, 3.14], %)
|
||||
|> lineTo([6.14, 3.14], %)
|
||||
|> line(endAbsolute = [6.14, 3.14])
|
||||
|> xLineTo(8, %)
|
||||
|> yLineTo(5, %)
|
||||
|> yLine(3.14, %, $a)
|
||||
@ -854,9 +854,9 @@ describe('testing getConstraintInfo', () => {
|
||||
describe('constrained', () => {
|
||||
const code = `const part001 = startSketchOn('-XZ')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([3 + 0, 4 + 0], %)
|
||||
|> line(end = [3 + 0, 4 + 0])
|
||||
|> angledLine({ angle = 3.14 + 0, length = 3.14 + 0 }, %)
|
||||
|> lineTo([6.14 + 0, 3.14 + 0], %)
|
||||
|> line(endAbsolute = [6.14 + 0, 3.14 + 0])
|
||||
|> xLineTo(8 + 0, %)
|
||||
|> yLineTo(5 + 0, %)
|
||||
|> yLine(3.14 + 0, %, $a)
|
||||
|
@ -73,8 +73,8 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => {
|
||||
const bigExampleArr = [
|
||||
`part001 = startSketchOn('XY')`,
|
||||
` |> startProfileAt([0, 0], %)`,
|
||||
` |> lineTo([1, 1], %, $abc1)`,
|
||||
` |> line([-2.04, -0.7], %, $abc2)`,
|
||||
` |> line(endAbsolute = [1, 1], tag = $abc1)`,
|
||||
` |> line(end = [-2.04, -0.7], tag = $abc2)`,
|
||||
` |> angledLine({ angle = 157, length = 1.69 }, %, $abc3)`,
|
||||
` |> angledLineOfXLength({ angle = 217, length = 0.86 }, %, $abc4)`,
|
||||
` |> angledLineOfYLength({ angle = 104, length = 1.58 }, %, $abc5)`,
|
||||
@ -84,8 +84,8 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => {
|
||||
` |> yLine(1.57, %, $abc9)`,
|
||||
` |> xLineTo(1.49, %, $abc10)`,
|
||||
` |> yLineTo(2.64, %, $abc11)`,
|
||||
` |> lineTo([2.55, 3.58], %) // lineTo`,
|
||||
` |> line([0.73, -0.75], %)`,
|
||||
` |> line(endAbsolute = [2.55, 3.58]) // lineTo`,
|
||||
` |> line(end = [0.73, -0.75])`,
|
||||
` |> angledLine([63, 1.38], %) // angledLine`,
|
||||
` |> angledLineOfXLength([319, 1.15], %) // angledLineOfXLength`,
|
||||
` |> angledLineOfYLength([50, 1.35], %) // angledLineOfYLength`,
|
||||
@ -98,7 +98,7 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => {
|
||||
]
|
||||
const bigExample = bigExampleArr.join('\n')
|
||||
it('line with tag converts to xLine', async () => {
|
||||
const callToSwap = 'line([-2.04, -0.7], %, $abc2)'
|
||||
const callToSwap = 'line(end = [-2.04, -0.7], tag = $abc2)'
|
||||
const expectedLine = 'xLine(-2.04, %, $abc2)'
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
@ -110,7 +110,7 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => {
|
||||
expect(originalRange[0]).toBe(newCode.indexOf(expectedLine))
|
||||
})
|
||||
it('line w/o tag converts to xLine', async () => {
|
||||
const callToSwap = 'line([0.73, -0.75], %)'
|
||||
const callToSwap = 'line(end = [0.73, -0.75])'
|
||||
const expectedLine = 'xLine(0.73, %)'
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
@ -124,7 +124,7 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => {
|
||||
it('lineTo with tag converts to xLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: 'lineTo([1, 1], %, $abc1)',
|
||||
callToSwap: 'line(endAbsolute = [1, 1], tag = $abc1)',
|
||||
constraintType: 'horizontal',
|
||||
})
|
||||
const expectedLine = 'xLineTo(1, %, $abc1)'
|
||||
@ -135,7 +135,7 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => {
|
||||
it('lineTo w/o tag converts to xLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: bigExample,
|
||||
callToSwap: 'lineTo([2.55, 3.58], %)',
|
||||
callToSwap: 'line(endAbsolute = [2.55, 3.58])',
|
||||
constraintType: 'horizontal',
|
||||
})
|
||||
const expectedLine = 'xLineTo(2.55, %) // lineTo'
|
||||
@ -272,21 +272,21 @@ describe('testing swapping out sketch calls with xLine/xLineTo while keeping var
|
||||
`part001 = startSketchOn('XY')`,
|
||||
` |> startProfileAt([0, 0], %)`,
|
||||
// ` |> rx(90, %)`,
|
||||
` |> lineTo([1, 1], %)`,
|
||||
` |> line([lineX, 2.13], %)`,
|
||||
` |> lineTo([lineToX, 2.85], %)`,
|
||||
` |> line(endAbsolute = [1, 1])`,
|
||||
` |> line(end = [lineX, 2.13])`,
|
||||
` |> line(endAbsolute = [lineToX, 2.85])`,
|
||||
` |> angledLine([angledLineAngle, 1.64], %)`,
|
||||
` |> angledLineOfXLength([329, angledLineOfXLengthX], %)`,
|
||||
` |> angledLineOfYLength([222, angledLineOfYLengthY], %)`,
|
||||
` |> angledLineToX([330, angledLineToXx], %)`,
|
||||
` |> angledLineToY([217, angledLineToYy], %)`,
|
||||
` |> line([0.89, -0.1], %)`,
|
||||
` |> line(end = [0.89, -0.1])`,
|
||||
]
|
||||
const varExample = variablesExampleArr.join('\n')
|
||||
it('line keeps variable when converted to xLine', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: varExample,
|
||||
callToSwap: 'line([lineX, 2.13], %)',
|
||||
callToSwap: 'line(end = [lineX, 2.13])',
|
||||
constraintType: 'horizontal',
|
||||
})
|
||||
const expectedLine = 'xLine(lineX, %)'
|
||||
@ -297,7 +297,7 @@ describe('testing swapping out sketch calls with xLine/xLineTo while keeping var
|
||||
it('lineTo keeps variable when converted to xLineTo', async () => {
|
||||
const { newCode, originalRange } = await testingSwapSketchFnCall({
|
||||
inputCode: varExample,
|
||||
callToSwap: 'lineTo([lineToX, 2.85], %)',
|
||||
callToSwap: 'line(endAbsolute = [lineToX, 2.85])',
|
||||
constraintType: 'horizontal',
|
||||
})
|
||||
const expectedLine = 'xLineTo(lineToX, %)'
|
||||
@ -365,9 +365,9 @@ describe('testing getSketchSegmentIndexFromSourceRange', () => {
|
||||
const code = `
|
||||
part001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0.04], %) // segment-in-start
|
||||
|> line([0, 0.4], %)
|
||||
|> line(end = [0, 0.4])
|
||||
|> xLine(3.48, %)
|
||||
|> line([2.14, 1.35], %) // normal-segment
|
||||
|> line(end = [2.14, 1.35]) // normal-segment
|
||||
|> xLine(3.54, %)`
|
||||
it('normal case works', async () => {
|
||||
const execState = await enginelessExecutor(assertParse(code))
|
||||
|
@ -28,12 +28,12 @@ beforeAll(async () => {
|
||||
describe('testing getConstraintType', () => {
|
||||
const helper = getConstraintTypeFromSourceHelper
|
||||
it('testing line', () => {
|
||||
expect(helper(`line([5, myVar], %)`)).toBe('yRelative')
|
||||
expect(helper(`line([myVar, 5], %)`)).toBe('xRelative')
|
||||
expect(helper(`line(end = [5, myVar])`)).toBe('yRelative')
|
||||
expect(helper(`line(end = [myVar, 5])`)).toBe('xRelative')
|
||||
})
|
||||
it('testing lineTo', () => {
|
||||
expect(helper(`lineTo([5, myVar], %)`)).toBe('yAbsolute')
|
||||
expect(helper(`lineTo([myVar, 5], %)`)).toBe('xAbsolute')
|
||||
expect(helper(`line(endAbsolute = [5, myVar])`)).toBe('yAbsolute')
|
||||
expect(helper(`line(endAbsolute = [myVar, 5])`)).toBe('xAbsolute')
|
||||
})
|
||||
it('testing angledLine', () => {
|
||||
expect(helper(`angledLine([5, myVar], %)`)).toBe('length')
|
||||
@ -105,17 +105,17 @@ describe('testing transformAstForSketchLines for equal length constraint', () =>
|
||||
describe(`should always reorder selections to have the base selection first`, () => {
|
||||
const inputScript = `sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([5, 5], %)
|
||||
|> line([-2, 5], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)`
|
||||
|> line(end = [5, 5])
|
||||
|> line(end = [-2, 5])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()`
|
||||
|
||||
const expectedModifiedScript = `sketch001 = startSketchOn('XZ')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([5, 5], %, $seg01)
|
||||
|> line(end = [5, 5], tag = $seg01)
|
||||
|> angledLine([112, segLen(seg01)], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
`
|
||||
|
||||
const selectLine = (
|
||||
@ -193,26 +193,26 @@ myAng = 40
|
||||
myAng2 = 134
|
||||
part001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([1, 3.82], %) // ln-should-get-tag
|
||||
|> lineTo([myVar, 1], %) // ln-lineTo-xAbsolute should use angleToMatchLengthX helper
|
||||
|> lineTo([1, myVar], %) // ln-lineTo-yAbsolute should use angleToMatchLengthY helper
|
||||
|> lineTo([2, 4], %) // ln-lineTo-free should become angledLine
|
||||
|> line(end = [1, 3.82]) // ln-should-get-tag
|
||||
|> line(endAbsolute = [myVar, 1]) // ln-lineTo-xAbsolute should use angleToMatchLengthX helper
|
||||
|> line(endAbsolute = [1, myVar]) // ln-lineTo-yAbsolute should use angleToMatchLengthY helper
|
||||
|> line(endAbsolute = [2, 4]) // ln-lineTo-free should become angledLine
|
||||
|> angledLineToX([45, 2.5], %) // ln-angledLineToX-free should become angledLine
|
||||
|> angledLineToX([myAng, 3], %) // ln-angledLineToX-angle should become angledLine
|
||||
|> angledLineToX([45, myVar2], %) // ln-angledLineToX-xAbsolute should use angleToMatchLengthX to get angle
|
||||
|> angledLineToY([135, 5], %) // ln-angledLineToY-free should become angledLine
|
||||
|> angledLineToY([myAng2, 4], %) // ln-angledLineToY-angle should become angledLine
|
||||
|> angledLineToY([45, myVar3], %) // ln-angledLineToY-yAbsolute should use angleToMatchLengthY to get angle
|
||||
|> line([myVar, 1], %) // ln-should use legLen for y
|
||||
|> line([myVar, -1], %) // ln-legLen but negative
|
||||
|> line([-0.62, -1.54], %) // ln-should become angledLine
|
||||
|> line(end = [myVar, 1]) // ln-should use legLen for y
|
||||
|> line(end = [myVar, -1]) // ln-legLen but negative
|
||||
|> line(end = [-0.62, -1.54]) // ln-should become angledLine
|
||||
|> angledLine([myVar, 1.04], %) // ln-use segLen for second arg
|
||||
|> angledLine([45, 1.04], %) // ln-segLen again
|
||||
|> angledLineOfXLength([54, 2.35], %) // ln-should be transformed to angledLine
|
||||
|> angledLineOfXLength([50, myVar], %) // ln-should use legAngX to calculate angle
|
||||
|> angledLineOfXLength([209, myVar], %) // ln-same as above but should have + 180 to match original quadrant
|
||||
|> line([1, myVar], %) // ln-legLen again but yRelative
|
||||
|> line([-1, myVar], %) // ln-negative legLen yRelative
|
||||
|> line(end = [1, myVar]) // ln-legLen again but yRelative
|
||||
|> line(end = [-1, myVar]) // ln-negative legLen yRelative
|
||||
|> angledLineOfYLength([58, 0.7], %) // ln-angledLineOfYLength-free should become angledLine
|
||||
|> angledLineOfYLength([myAng, 0.7], %) // ln-angledLineOfYLength-angle should become angledLine
|
||||
|> angledLineOfYLength([35, myVar], %) // ln-angledLineOfYLength-yRelative use legAngY
|
||||
@ -229,7 +229,7 @@ myAng = 40
|
||||
myAng2 = 134
|
||||
part001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([1, 3.82], %, $seg01) // ln-should-get-tag
|
||||
|> line(end = [1, 3.82], tag = $seg01) // ln-should-get-tag
|
||||
|> angledLineToX([
|
||||
-angleToMatchLengthX(seg01, myVar, %),
|
||||
myVar
|
||||
@ -334,15 +334,15 @@ myVar2 = 12
|
||||
myVar3 = -10
|
||||
part001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> lineTo([1, 1], %)
|
||||
|> line([-6.28, 1.4], %) // select for horizontal constraint 1
|
||||
|> line([-1.07, myVar], %) // select for vertical constraint 1
|
||||
|> line([myVar, 4.32], %) // select for horizontal constraint 2
|
||||
|> line([6.35, -1.12], %) // select for vertical constraint 2
|
||||
|> lineTo([5, 8], %) // select for horizontal constraint 3
|
||||
|> lineTo([3, 11], %) // select for vertical constraint 3
|
||||
|> lineTo([myVar2, 12.63], %) // select for horizontal constraint 4
|
||||
|> lineTo([4.08, myVar2], %) // select for vertical constraint 4
|
||||
|> line(endAbsolute = [1, 1])
|
||||
|> line(end = [-6.28, 1.4]) // select for horizontal constraint 1
|
||||
|> line(end = [-1.07, myVar]) // select for vertical constraint 1
|
||||
|> line(end = [myVar, 4.32]) // select for horizontal constraint 2
|
||||
|> line(end = [6.35, -1.12]) // select for vertical constraint 2
|
||||
|> line(endAbsolute = [5, 8]) // select for horizontal constraint 3
|
||||
|> line(endAbsolute = [3, 11]) // select for vertical constraint 3
|
||||
|> line(endAbsolute = [myVar2, 12.63]) // select for horizontal constraint 4
|
||||
|> line(endAbsolute = [4.08, myVar2]) // select for vertical constraint 4
|
||||
|> angledLine([156, 1.34], %) // select for horizontal constraint 5
|
||||
|> angledLine([103, 1.44], %) // select for vertical constraint 5
|
||||
|> angledLine([-178, myVar], %) // select for horizontal constraint 6
|
||||
@ -362,15 +362,15 @@ myVar2 = 12
|
||||
myVar3 = -10
|
||||
part001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> lineTo([1, 1], %)
|
||||
|> line(endAbsolute = [1, 1])
|
||||
|> xLine(-6.28, %) // select for horizontal constraint 1
|
||||
|> line([-1.07, myVar], %) // select for vertical constraint 1
|
||||
|> line(end = [-1.07, myVar]) // select for vertical constraint 1
|
||||
|> xLine(myVar, %) // select for horizontal constraint 2
|
||||
|> line([6.35, -1.12], %) // select for vertical constraint 2
|
||||
|> line(end = [6.35, -1.12]) // select for vertical constraint 2
|
||||
|> xLineTo(5, %) // select for horizontal constraint 3
|
||||
|> lineTo([3, 11], %) // select for vertical constraint 3
|
||||
|> line(endAbsolute = [3, 11]) // select for vertical constraint 3
|
||||
|> xLineTo(myVar2, %) // select for horizontal constraint 4
|
||||
|> lineTo([4.08, myVar2], %) // select for vertical constraint 4
|
||||
|> line(endAbsolute = [4.08, myVar2]) // select for vertical constraint 4
|
||||
|> xLine(-1.22, %) // select for horizontal constraint 5
|
||||
|> angledLine([103, 1.44], %) // select for vertical constraint 5
|
||||
|> xLine(-myVar, %) // select for horizontal constraint 6
|
||||
@ -422,14 +422,14 @@ myVar2 = 12
|
||||
myVar3 = -10
|
||||
part001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> lineTo([1, 1], %)
|
||||
|> line([-6.28, 1.4], %) // select for horizontal constraint 1
|
||||
|> line(endAbsolute = [1, 1])
|
||||
|> line(end = [-6.28, 1.4]) // select for horizontal constraint 1
|
||||
|> yLine(myVar, %) // select for vertical constraint 1
|
||||
|> line([myVar, 4.32], %) // select for horizontal constraint 2
|
||||
|> line(end = [myVar, 4.32]) // select for horizontal constraint 2
|
||||
|> yLine(-1.12, %) // select for vertical constraint 2
|
||||
|> lineTo([5, 8], %) // select for horizontal constraint 3
|
||||
|> line(endAbsolute = [5, 8]) // select for horizontal constraint 3
|
||||
|> yLineTo(11, %) // select for vertical constraint 3
|
||||
|> lineTo([myVar2, 12.63], %) // select for horizontal constraint 4
|
||||
|> line(endAbsolute = [myVar2, 12.63]) // select for horizontal constraint 4
|
||||
|> yLineTo(myVar2, %) // select for vertical constraint 4
|
||||
|> angledLine([156, 1.34], %) // select for horizontal constraint 5
|
||||
|> yLine(1.4, %) // select for vertical constraint 5
|
||||
@ -483,11 +483,11 @@ describe('testing transformAstForSketchLines for vertical and horizontal distanc
|
||||
const inputScript = `myVar = 1
|
||||
part001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> line([0.31, 1.67], %) // base selection
|
||||
|> line([0.45, 1.46], %)
|
||||
|> line([0.45, 1.46], %) // free
|
||||
|> line([myVar, 0.01], %) // xRelative
|
||||
|> line([0.7, myVar], %) // yRelative
|
||||
|> line(end = [0.31, 1.67]) // base selection
|
||||
|> line(end = [0.45, 1.46])
|
||||
|> line(end = [0.45, 1.46]) // free
|
||||
|> line(end = [myVar, 0.01]) // xRelative
|
||||
|> line(end = [0.7, myVar]) // yRelative
|
||||
`
|
||||
it('testing for free to horizontal and vertical distance', async () => {
|
||||
const expectedHorizontalCode = await helperThing(
|
||||
@ -501,10 +501,10 @@ part001 = startSketchOn('XY')
|
||||
'setVertDistance'
|
||||
)
|
||||
expect(expectedHorizontalCode).toContain(
|
||||
`lineTo([segEndX(seg01) + 0.9, 4.59], %) // free`
|
||||
`line(endAbsolute = [segEndX(seg01) + 0.9, 4.59]) // free`
|
||||
)
|
||||
expect(expectedVerticalCode).toContain(
|
||||
`lineTo([1.21, segEndY(seg01) + 2.92], %) // free`
|
||||
`line(endAbsolute = [1.21, segEndY(seg01) + 2.92]) // free`
|
||||
)
|
||||
})
|
||||
it('testing for xRelative to vertical distance', async () => {
|
||||
|
@ -9,8 +9,8 @@ describe('testing angledLineThatIntersects', () => {
|
||||
it('angledLineThatIntersects should intersect with another line', async () => {
|
||||
const code = (offset: string) => `part001 = startSketchOn('XY')
|
||||
|> startProfileAt([0, 0], %)
|
||||
|> lineTo([2, 2], %, $yo)
|
||||
|> lineTo([3, 1], %)
|
||||
|> line(endAbsolute = [2, 2], tag = $yo)
|
||||
|> line(endAbsolute = [3, 1])
|
||||
|> angledLineThatIntersects({
|
||||
angle: 180,
|
||||
intersectTag: yo,
|
||||
|
@ -4,38 +4,38 @@ test('normaliseKclNumbers', () => {
|
||||
expect(
|
||||
normaliseKclNumbers(`sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(-15, sketch001)`)
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
const extrude001 = extrude(sketch001, length = -15)`)
|
||||
).toBe(`sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-12.34, 12.34], %)
|
||||
|> line([12.34, 0], %)
|
||||
|> line([0, -12.34], %)
|
||||
|> line([-12.34, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(-12.34, sketch001)`)
|
||||
|> line(end = [12.34, 0])
|
||||
|> line(end = [0, -12.34])
|
||||
|> line(end = [-12.34, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
const extrude001 = extrude(sketch001, length = -12.34)`)
|
||||
expect(
|
||||
normaliseKclNumbers(
|
||||
`sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-10, 10], %)
|
||||
|> line([20, 0], %)
|
||||
|> line([0, -20], %)
|
||||
|> line([-20, 0], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(-15, sketch001)`,
|
||||
|> line(end = [20, 0])
|
||||
|> line(end = [0, -20])
|
||||
|> line(end = [-20, 0])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
const extrude001 = extrude(sketch001, length = -15)`,
|
||||
false
|
||||
)
|
||||
).toBe(`sketch001 = startSketchOn('XY')
|
||||
|> startProfileAt([-12.34, 12.34], %)
|
||||
|> line([12.34, 12.34], %)
|
||||
|> line([12.34, -12.34], %)
|
||||
|> line([-12.34, 12.34], %)
|
||||
|> lineTo([profileStartX(%), profileStartY(%)], %)
|
||||
|> close(%)
|
||||
const extrude001 = extrude(-12.34, sketch001)`)
|
||||
|> line(end = [12.34, 12.34])
|
||||
|> line(end = [12.34, -12.34])
|
||||
|> line(end = [-12.34, 12.34])
|
||||
|> line(endAbsolute = [profileStartX(%), profileStartY(%)])
|
||||
|> close()
|
||||
const extrude001 = extrude(sketch001, length = -12.34)`)
|
||||
})
|
||||
|
Reference in New Issue
Block a user