Compare commits

...

8 Commits

Author SHA1 Message Date
921bf2aa47 Change const to let in artifactGraph.test.ts code 2024-09-25 12:14:31 -05:00
925d8df3d5 Format code 2024-09-25 12:02:49 -05:00
0568663ff4 Change over more code 2024-09-25 11:58:28 -05:00
2a85ea26ad More tests 2024-09-25 11:55:33 -05:00
94b6ad2e68 More tests 2024-09-25 11:53:01 -05:00
5274ae80db More tests 2024-09-25 11:49:06 -05:00
d5475eab81 Update tests 2024-09-25 11:42:15 -05:00
38c1278948 KCL: Recast const as let
KCL is a functional language where values are immutable. As such there is
no difference between const and let. So we should encourage users to write
let instead of const, because it's shorter and nicer.
2024-09-25 10:23:07 -05:00
16 changed files with 253 additions and 250 deletions

View File

@ -129,7 +129,7 @@ describe('Testing addSketchTo', () => {
'yz'
)
const str = recast(result.modifiedAst)
expect(str).toBe(`const sketch001 = startSketchOn('YZ')
expect(str).toBe(`let sketch001 = startSketchOn('YZ')
|> startProfileAt('default', %)
|> line('default', %)
`)
@ -156,7 +156,7 @@ function giveSketchFnCallTagTestHelper(
}
describe('Testing giveSketchFnCallTag', () => {
const code = `const part001 = startSketchOn('XY')
const code = `let part001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([-2.57, -0.13], %)
|> line([0, 0.83], %)
@ -205,10 +205,10 @@ describe('Testing moveValueIntoNewVariable', () => {
fn ghi = (x) => {
return 2
}
const abc = 3
const identifierGuy = 5
const yo = 5 + 6
const part001 = startSketchOn('XY')
let abc = 3
let identifierGuy = 5
let yo = 5 + 6
let part001 = startSketchOn('XY')
|> startProfileAt([-1.2, 4.83], %)
|> line([2.8, 0], %)
|> angledLine([100 + 100, 3.09], %)
@ -216,7 +216,7 @@ const part001 = startSketchOn('XY')
|> angledLine([def(yo), 3.09], %)
|> angledLine([ghi(%), 3.09], %)
|> angledLine([jkl(yo) + 2, 3.09], %)
const yo2 = hmm([identifierGuy + 5])`
let yo2 = hmm([identifierGuy + 5])`
it('should move a binary expression into a new variable', async () => {
const ast = parse(code)
if (err(ast)) throw ast
@ -229,7 +229,7 @@ const yo2 = hmm([identifierGuy + 5])`
'newVar'
)
const newCode = recast(modifiedAst)
expect(newCode).toContain(`const newVar = 100 + 100`)
expect(newCode).toContain(`let newVar = 100 + 100`)
expect(newCode).toContain(`angledLine([newVar, 3.09], %)`)
})
it('should move a value into a new variable', async () => {
@ -244,7 +244,7 @@ const yo2 = hmm([identifierGuy + 5])`
'newVar'
)
const newCode = recast(modifiedAst)
expect(newCode).toContain(`const newVar = 2.8`)
expect(newCode).toContain(`let newVar = 2.8`)
expect(newCode).toContain(`line([newVar, 0], %)`)
})
it('should move a callExpression into a new variable', async () => {
@ -259,7 +259,7 @@ const yo2 = hmm([identifierGuy + 5])`
'newVar'
)
const newCode = recast(modifiedAst)
expect(newCode).toContain(`const newVar = def(yo)`)
expect(newCode).toContain(`let newVar = def(yo)`)
expect(newCode).toContain(`angledLine([newVar, 3.09], %)`)
})
it('should move a binary expression with call expression into a new variable', async () => {
@ -274,7 +274,7 @@ const yo2 = hmm([identifierGuy + 5])`
'newVar'
)
const newCode = recast(modifiedAst)
expect(newCode).toContain(`const newVar = jkl(yo) + 2`)
expect(newCode).toContain(`let newVar = jkl(yo) + 2`)
expect(newCode).toContain(`angledLine([newVar, 3.09], %)`)
})
it('should move a identifier into a new variable', async () => {
@ -289,14 +289,14 @@ const yo2 = hmm([identifierGuy + 5])`
'newVar'
)
const newCode = recast(modifiedAst)
expect(newCode).toContain(`const newVar = identifierGuy + 5`)
expect(newCode).toContain(`const yo2 = hmm([newVar])`)
expect(newCode).toContain(`let newVar = identifierGuy + 5`)
expect(newCode).toContain(`let yo2 = hmm([newVar])`)
})
})
describe('testing sketchOnExtrudedFace', () => {
test('it should be able to extrude on regular segments', async () => {
const code = `const part001 = startSketchOn('-XZ')
const code = `let part001 = startSketchOn('-XZ')
|> startProfileAt([3.58, 2.06], %)
|> line([9.7, 9.19], %)
|> line([8.62, -9.57], %)
@ -327,16 +327,16 @@ describe('testing sketchOnExtrudedFace', () => {
const { modifiedAst } = extruded
const newCode = recast(modifiedAst)
expect(newCode).toContain(`const part001 = startSketchOn('-XZ')
expect(newCode).toContain(`let part001 = startSketchOn('-XZ')
|> startProfileAt([3.58, 2.06], %)
|> line([9.7, 9.19], %, $seg01)
|> line([8.62, -9.57], %)
|> close(%)
|> extrude(5 + 7, %)
const sketch001 = startSketchOn(part001, seg01)`)
let sketch001 = startSketchOn(part001, seg01)`)
})
test('it should be able to extrude on close segments', async () => {
const code = `const part001 = startSketchOn('-XZ')
const code = `let part001 = startSketchOn('-XZ')
|> startProfileAt([3.58, 2.06], %)
|> line([9.7, 9.19], %)
|> line([8.62, -9.57], %)
@ -366,16 +366,16 @@ const sketch001 = startSketchOn(part001, seg01)`)
const { modifiedAst } = extruded
const newCode = recast(modifiedAst)
expect(newCode).toContain(`const part001 = startSketchOn('-XZ')
expect(newCode).toContain(`let part001 = startSketchOn('-XZ')
|> startProfileAt([3.58, 2.06], %)
|> line([9.7, 9.19], %)
|> line([8.62, -9.57], %)
|> close(%, $seg01)
|> extrude(5 + 7, %)
const sketch001 = startSketchOn(part001, seg01)`)
let sketch001 = startSketchOn(part001, seg01)`)
})
test('it should be able to extrude on start-end caps', async () => {
const code = `const part001 = startSketchOn('-XZ')
const code = `let part001 = startSketchOn('-XZ')
|> startProfileAt([3.58, 2.06], %)
|> line([9.7, 9.19], %)
|> line([8.62, -9.57], %)
@ -406,16 +406,16 @@ const sketch001 = startSketchOn(part001, seg01)`)
const { modifiedAst } = extruded
const newCode = recast(modifiedAst)
expect(newCode).toContain(`const part001 = startSketchOn('-XZ')
expect(newCode).toContain(`let part001 = startSketchOn('-XZ')
|> startProfileAt([3.58, 2.06], %)
|> line([9.7, 9.19], %)
|> line([8.62, -9.57], %)
|> close(%)
|> extrude(5 + 7, %)
const sketch001 = startSketchOn(part001, 'END')`)
let sketch001 = startSketchOn(part001, 'END')`)
})
test('it should ensure that the new sketch is inserted after the extrude', async () => {
const code = `const sketch001 = startSketchOn('-XZ')
const code = `let sketch001 = startSketchOn('-XZ')
|> startProfileAt([3.29, 7.86], %)
|> line([2.48, 2.44], %)
|> line([2.66, 1.17], %)
@ -428,7 +428,7 @@ const sketch001 = startSketchOn(part001, 'END')`)
|> line([-3.86, -2.73], %)
|> line([-17.67, 0.85], %)
|> close(%)
const part001 = extrude(5 + 7, sketch001)`
let part001 = extrude(5 + 7, sketch001)`
const ast = parse(code)
if (err(ast)) throw ast
const segmentSnippet = `line([4.99, -0.46], %)`
@ -451,14 +451,14 @@ const sketch001 = startSketchOn(part001, 'END')`)
)
if (err(updatedAst)) throw updatedAst
const newCode = recast(updatedAst.modifiedAst)
expect(newCode).toContain(`const part001 = extrude(5 + 7, sketch001)
const sketch002 = startSketchOn(part001, seg01)`)
expect(newCode).toContain(`let part001 = extrude(5 + 7, sketch001)
let sketch002 = startSketchOn(part001, seg01)`)
})
})
describe('Testing deleteSegmentFromPipeExpression', () => {
it('Should delete a segment withOUT any dependent segments', async () => {
const code = `const part001 = startSketchOn('-XZ')
const code = `let part001 = startSketchOn('-XZ')
|> startProfileAt([54.78, -95.91], %)
|> line([306.21, 198.82], %)
|> line([306.21, 198.85], %, $a)
@ -481,7 +481,7 @@ describe('Testing deleteSegmentFromPipeExpression', () => {
)
if (err(modifiedAst)) throw modifiedAst
const newCode = recast(modifiedAst)
expect(newCode).toBe(`const part001 = startSketchOn('-XZ')
expect(newCode).toBe(`let part001 = startSketchOn('-XZ')
|> startProfileAt([54.78, -95.91], %)
|> line([306.21, 198.82], %)
|> line([306.21, 198.87], %)
@ -492,7 +492,7 @@ describe('Testing deleteSegmentFromPipeExpression', () => {
line: string,
replace1 = '',
replace2 = ''
) => `const part001 = startSketchOn('-XZ')
) => `let part001 = startSketchOn('-XZ')
|> startProfileAt([54.78, -95.91], %)
|> line([306.21, 198.82], %, $b)
${!replace1 ? ` |> ${line}\n` : ''} |> angledLine([-65, ${
@ -567,7 +567,7 @@ ${!replace1 ? ` |> ${line}\n` : ''} |> angledLine([-65, ${
describe('Testing removeSingleConstraintInfo', () => {
describe('with mostly object notation', () => {
const code = `const part001 = startSketchOn('-XZ')
const code = `let part001 = startSketchOn('-XZ')
|> startProfileAt([0, 0], %)
|> line([3 + 0, 4 + 0], %)
|> angledLine({ angle: 3 + 0, length: 3.14 + 0 }, %)
@ -669,7 +669,7 @@ describe('Testing removeSingleConstraintInfo', () => {
})
})
describe('with array notation', () => {
const code = `const part001 = startSketchOn('-XZ')
const code = `let part001 = startSketchOn('-XZ')
|> startProfileAt([0, 0], %)
|> angledLine([3.14 + 0, 3.14 + 0], %)
|> angledLineOfXLength([3 + 0, 3.14 + 0], %)
@ -725,14 +725,14 @@ describe('Testing deleteFromSelection', () => {
[
'basicCase',
{
codeBefore: `const myVar = 5
const sketch003 = startSketchOn('XZ')
codeBefore: `let myVar = 5
let sketch003 = startSketchOn('XZ')
|> startProfileAt([3.82, 13.6], %)
|> line([-2.94, 2.7], %)
|> line([7.7, 0.16], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`,
codeAfter: `const myVar = 5\n`,
codeAfter: `let myVar = 5\n`,
lineOfInterest: 'line([-2.94, 2.7], %)',
type: 'default',
},
@ -740,7 +740,7 @@ const sketch003 = startSketchOn('XZ')
[
'delete extrude',
{
codeBefore: `const sketch001 = startSketchOn('XZ')
codeBefore: `let sketch001 = startSketchOn('XZ')
|> startProfileAt([3.29, 7.86], %)
|> line([2.48, 2.44], %)
|> line([2.66, 1.17], %)
@ -750,7 +750,7 @@ const sketch003 = startSketchOn('XZ')
|> line([-17.67, 0.85], %)
|> close(%)
const extrude001 = extrude(10, sketch001)`,
codeAfter: `const sketch001 = startSketchOn('XZ')
codeAfter: `let sketch001 = startSketchOn('XZ')
|> startProfileAt([3.29, 7.86], %)
|> line([2.48, 2.44], %)
|> line([2.66, 1.17], %)
@ -766,8 +766,8 @@ const extrude001 = extrude(10, sketch001)`,
[
'delete extrude with sketch on it',
{
codeBefore: `const myVar = 5
const sketch001 = startSketchOn('XZ')
codeBefore: `let myVar = 5
let sketch001 = startSketchOn('XZ')
|> startProfileAt([4.46, 5.12], %, $tag)
|> line([0.08, myVar], %)
|> line([13.03, 2.02], %, $seg01)
@ -778,7 +778,7 @@ const sketch001 = startSketchOn('XZ')
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(5, sketch001)
const sketch002 = startSketchOn(extrude001, seg01)
let sketch002 = startSketchOn(extrude001, seg01)
|> startProfileAt([-12.55, 2.89], %)
|> line([3.02, 1.9], %)
|> line([1.82, -1.49], %, $seg02)
@ -787,8 +787,8 @@ const sketch002 = startSketchOn(extrude001, seg01)
|> line([0.3, 0.84], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`,
codeAfter: `const myVar = 5
const sketch001 = startSketchOn('XZ')
codeAfter: `let myVar = 5
let sketch001 = startSketchOn('XZ')
|> startProfileAt([4.46, 5.12], %, $tag)
|> line([0.08, myVar], %)
|> line([13.03, 2.02], %, $seg01)
@ -798,7 +798,7 @@ const sketch001 = startSketchOn('XZ')
|> line([-8.54, -2.51], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const sketch002 = startSketchOn({
let sketch002 = startSketchOn({
plane: {
origin: { x: 1, y: 2, z: 3 },
x_axis: { x: 4, y: 5, z: 6 },
@ -822,8 +822,8 @@ const sketch002 = startSketchOn({
[
'delete extrude with sketch on it',
{
codeBefore: `const myVar = 5
const sketch001 = startSketchOn('XZ')
codeBefore: `let myVar = 5
let sketch001 = startSketchOn('XZ')
|> startProfileAt([4.46, 5.12], %, $tag)
|> line([0.08, myVar], %)
|> line([13.03, 2.02], %, $seg01)
@ -834,7 +834,7 @@ const sketch001 = startSketchOn('XZ')
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(5, sketch001)
const sketch002 = startSketchOn(extrude001, seg01)
let sketch002 = startSketchOn(extrude001, seg01)
|> startProfileAt([-12.55, 2.89], %)
|> line([3.02, 1.9], %)
|> line([1.82, -1.49], %, $seg02)
@ -843,8 +843,8 @@ const sketch002 = startSketchOn(extrude001, seg01)
|> line([0.3, 0.84], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)`,
codeAfter: `const myVar = 5
const sketch001 = startSketchOn('XZ')
codeAfter: `let myVar = 5
let sketch001 = startSketchOn('XZ')
|> startProfileAt([4.46, 5.12], %, $tag)
|> line([0.08, myVar], %)
|> line([13.03, 2.02], %, $seg01)
@ -854,7 +854,7 @@ const sketch001 = startSketchOn('XZ')
|> line([-8.54, -2.51], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const sketch002 = startSketchOn({
let sketch002 = startSketchOn({
plane: {
origin: { x: 1, y: 2, z: 3 },
x_axis: { x: 4, y: 5, z: 6 },

View File

@ -147,16 +147,16 @@ const runGetPathToExtrudeForSegmentSelectionTest = async (
}
describe('Testing getPathToExtrudeForSegmentSelection', () => {
it('should return the correct paths for a valid selection and extrusion', async () => {
const code = `const sketch001 = startSketchOn('XY')
const code = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-10, 10], %)
|> line([20, 0], %)
|> line([0, -20], %)
|> line([-20, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)`
let extrude001 = extrude(-15, sketch001)`
const selectedSegmentSnippet = `line([20, 0], %)`
const expectedExtrudeSnippet = `const extrude001 = extrude(-15, sketch001)`
const expectedExtrudeSnippet = `let extrude001 = extrude(-15, sketch001)`
await runGetPathToExtrudeForSegmentSelectionTest(
code,
selectedSegmentSnippet,
@ -164,32 +164,32 @@ const extrude001 = extrude(-15, sketch001)`
)
}, 5_000)
it('should return the correct paths for a valid selection and extrusion in case of several extrusions and sketches', async () => {
const code = `const sketch001 = startSketchOn('XY')
const code = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-30, 30], %)
|> line([15, 0], %)
|> line([0, -15], %)
|> line([-15, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const sketch002 = startSketchOn('XY')
let sketch002 = startSketchOn('XY')
|> startProfileAt([30, 30], %)
|> line([20, 0], %)
|> line([0, -20], %)
|> line([-20, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const sketch003 = startSketchOn('XY')
let sketch003 = startSketchOn('XY')
|> startProfileAt([30, -30], %)
|> line([25, 0], %)
|> line([0, -25], %)
|> line([-25, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)
const extrude002 = extrude(-15, sketch002)
const extrude003 = extrude(-15, sketch003)`
let extrude001 = extrude(-15, sketch001)
let extrude002 = extrude(-15, sketch002)
let extrude003 = extrude(-15, sketch003)`
const selectedSegmentSnippet = `line([20, 0], %)`
const expectedExtrudeSnippet = `const extrude002 = extrude(-15, sketch002)`
const expectedExtrudeSnippet = `let extrude002 = extrude(-15, sketch002)`
await runGetPathToExtrudeForSegmentSelectionTest(
code,
selectedSegmentSnippet,
@ -197,29 +197,29 @@ const extrude003 = extrude(-15, sketch003)`
)
})
it('should not return any path for missing extrusion', async () => {
const code = `const sketch001 = startSketchOn('XY')
const code = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-30, 30], %)
|> line([15, 0], %)
|> line([0, -15], %)
|> line([-15, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const sketch002 = startSketchOn('XY')
let sketch002 = startSketchOn('XY')
|> startProfileAt([30, 30], %)
|> line([20, 0], %)
|> line([0, -20], %)
|> line([-20, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const sketch003 = startSketchOn('XY')
let sketch003 = startSketchOn('XY')
|> startProfileAt([30, -30], %)
|> line([25, 0], %)
|> line([0, -25], %)
|> line([-25, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)
const extrude003 = extrude(-15, sketch003)`
let extrude001 = extrude(-15, sketch001)
let extrude003 = extrude(-15, sketch003)`
const selectedSegmentSnippet = `line([20, 0], %)`
const expectedExtrudeSnippet = ``
await runGetPathToExtrudeForSegmentSelectionTest(
@ -282,7 +282,7 @@ describe('Testing addFillet', () => {
it('should add a fillet to a specific segment after extrusion, clean', async () => {
const code = `
const sketch001 = startSketchOn('XZ')
let sketch001 = startSketchOn('XZ')
|> startProfileAt([2.16, 49.67], %)
|> line([101.49, 139.93], %)
|> line([60.04, -55.72], %)
@ -292,12 +292,12 @@ describe('Testing addFillet', () => {
|> tangentialArcTo([14.68, -104.52], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(50, sketch001)
let extrude001 = extrude(50, sketch001)
`
const segmentSnippet = `line([60.04, -55.72], %)`
const extrudeSnippet = `const extrude001 = extrude(50, sketch001)`
const extrudeSnippet = `let extrude001 = extrude(50, sketch001)`
const radius = createLiteral(5)
const expectedCode = `const sketch001 = startSketchOn('XZ')
const expectedCode = `let sketch001 = startSketchOn('XZ')
|> startProfileAt([2.16, 49.67], %)
|> line([101.49, 139.93], %)
|> line([60.04, -55.72], %, $seg01)
@ -307,7 +307,7 @@ describe('Testing addFillet', () => {
|> tangentialArcTo([14.68, -104.52], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(50, sketch001)
let extrude001 = extrude(50, sketch001)
|> fillet({ radius: 5, tags: [seg01] }, %)`
await runFilletTest(
@ -325,7 +325,7 @@ const extrude001 = extrude(50, sketch001)
it('should add a fillet to a specific segment after extrusion with existing tag in any other line', async () => {
const code = `
const sketch001 = startSketchOn('XZ')
let sketch001 = startSketchOn('XZ')
|> startProfileAt([2.16, 49.67], %)
|> line([101.49, 139.93], %)
|> line([60.04, -55.72], %)
@ -335,12 +335,12 @@ const extrude001 = extrude(50, sketch001)
|> tangentialArcTo([14.68, -104.52], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(50, sketch001)
let extrude001 = extrude(50, sketch001)
`
const segmentSnippet = `line([60.04, -55.72], %)`
const extrudeSnippet = `const extrude001 = extrude(50, sketch001)`
const extrudeSnippet = `let extrude001 = extrude(50, sketch001)`
const radius = createLiteral(5)
const expectedCode = `const sketch001 = startSketchOn('XZ')
const expectedCode = `let sketch001 = startSketchOn('XZ')
|> startProfileAt([2.16, 49.67], %)
|> line([101.49, 139.93], %)
|> line([60.04, -55.72], %, $seg02)
@ -350,7 +350,7 @@ const extrude001 = extrude(50, sketch001)
|> tangentialArcTo([14.68, -104.52], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(50, sketch001)
let extrude001 = extrude(50, sketch001)
|> fillet({ radius: 5, tags: [seg02] }, %)`
await runFilletTest(
@ -368,7 +368,7 @@ const extrude001 = extrude(50, sketch001)
it('should add a fillet to a specific segment after extrusion with existing tag in that exact line', async () => {
const code = `
const sketch001 = startSketchOn('XZ')
let sketch001 = startSketchOn('XZ')
|> startProfileAt([2.16, 49.67], %)
|> line([101.49, 139.93], %)
|> line([60.04, -55.72], %)
@ -378,12 +378,12 @@ const extrude001 = extrude(50, sketch001)
|> tangentialArcTo([14.68, -104.52], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(50, sketch001)
let extrude001 = extrude(50, sketch001)
`
const segmentSnippet = `line([-87.24, -47.08], %, $seg03)`
const extrudeSnippet = `const extrude001 = extrude(50, sketch001)`
const extrudeSnippet = `let extrude001 = extrude(50, sketch001)`
const radius = createLiteral(5)
const expectedCode = `const sketch001 = startSketchOn('XZ')
const expectedCode = `let sketch001 = startSketchOn('XZ')
|> startProfileAt([2.16, 49.67], %)
|> line([101.49, 139.93], %)
|> line([60.04, -55.72], %)
@ -393,7 +393,7 @@ const extrude001 = extrude(50, sketch001)
|> tangentialArcTo([14.68, -104.52], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(50, sketch001)
let extrude001 = extrude(50, sketch001)
|> fillet({ radius: 5, tags: [seg03] }, %)`
await runFilletTest(
@ -410,7 +410,7 @@ const extrude001 = extrude(50, sketch001)
*/
it('should add another fillet after the existing fillet', async () => {
const code = `const sketch001 = startSketchOn('XZ')
const code = `let sketch001 = startSketchOn('XZ')
|> startProfileAt([2.16, 49.67], %)
|> line([101.49, 139.93], %)
|> line([60.04, -55.72], %)
@ -420,12 +420,12 @@ const extrude001 = extrude(50, sketch001)
|> tangentialArcTo([14.68, -104.52], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(50, sketch001)
let extrude001 = extrude(50, sketch001)
|> fillet({ radius: 10, tags: [seg03] }, %)`
const segmentSnippet = `line([60.04, -55.72], %)`
const extrudeSnippet = `const extrude001 = extrude(50, sketch001)`
const extrudeSnippet = `let extrude001 = extrude(50, sketch001)`
const radius = createLiteral(5)
const expectedCode = `const sketch001 = startSketchOn('XZ')
const expectedCode = `let sketch001 = startSketchOn('XZ')
|> startProfileAt([2.16, 49.67], %)
|> line([101.49, 139.93], %)
|> line([60.04, -55.72], %, $seg01)
@ -435,7 +435,7 @@ const extrude001 = extrude(50, sketch001)
|> tangentialArcTo([14.68, -104.52], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(50, sketch001)
let extrude001 = extrude(50, sketch001)
|> fillet({ radius: 10, tags: [seg03] }, %)
|> fillet({ radius: 5, tags: [seg01] }, %)`
@ -500,24 +500,24 @@ const runModifyAstWithFilletAndTagTest = async (
}
describe('Testing applyFilletToSelection', () => {
it('should add a fillet to a specific segment after extrusion', async () => {
const code = `const sketch001 = startSketchOn('XY')
const code = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-10, 10], %)
|> line([20, 0], %)
|> line([0, -20], %)
|> line([-20, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)`
let extrude001 = extrude(-15, sketch001)`
const segmentSnippets = ['line([0, -20], %)']
const radiusValue = 3
const expectedCode = `const sketch001 = startSketchOn('XY')
const expectedCode = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-10, 10], %)
|> line([20, 0], %)
|> line([0, -20], %, $seg01)
|> line([-20, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)
let extrude001 = extrude(-15, sketch001)
|> fillet({ radius: 3, tags: [seg01] }, %)`
await runModifyAstWithFilletAndTagTest(
@ -528,24 +528,24 @@ const extrude001 = extrude(-15, sketch001)
)
})
it('should add a fillet to the 2 segments of a single extrusion', async () => {
const code = `const sketch001 = startSketchOn('XY')
const code = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-10, 10], %)
|> line([20, 0], %)
|> line([0, -20], %)
|> line([-20, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)`
let extrude001 = extrude(-15, sketch001)`
const segmentSnippets = ['line([20, 0], %)', 'line([-20, 0], %)']
const radiusValue = 3
const expectedCode = `const sketch001 = startSketchOn('XY')
const expectedCode = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-10, 10], %)
|> line([20, 0], %, $seg01)
|> line([0, -20], %)
|> line([-20, 0], %, $seg02)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)
let extrude001 = extrude(-15, sketch001)
|> fillet({ radius: 3, tags: [seg01] }, %)
|> fillet({ radius: 3, tags: [seg02] }, %)`
@ -557,25 +557,25 @@ const extrude001 = extrude(-15, sketch001)
)
})
it('should add a fillet when the extrude variable previously had an fillet', async () => {
const code = `const sketch001 = startSketchOn('XY')
const code = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-10, 10], %)
|> line([20, 0], %)
|> line([0, -20], %)
|> line([-20, 0], %, $seg01)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)
let extrude001 = extrude(-15, sketch001)
|> fillet({ radius: 3, tags: [seg01] }, %)` // <--- one fillet already there on input code
const segmentSnippets = ['line([20, 0], %)']
const radiusValue = 3
const expectedCode = `const sketch001 = startSketchOn('XY')
const expectedCode = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-10, 10], %)
|> line([20, 0], %, $seg02)
|> line([0, -20], %)
|> line([-20, 0], %, $seg01)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)
let extrude001 = extrude(-15, sketch001)
|> fillet({ radius: 3, tags: [seg01] }, %)
|> fillet({ radius: 3, tags: [seg02] }, %)` // <-- able to add a new one
@ -587,41 +587,41 @@ const extrude001 = extrude(-15, sketch001)
)
})
it('should add the fillets to 2 bodies', async () => {
const code = `const sketch001 = startSketchOn('XY')
const code = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-10, 10], %)
|> line([20, 0], %)
|> line([0, -20], %)
|> line([-20, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)
const sketch002 = startSketchOn('XY')
let extrude001 = extrude(-15, sketch001)
let sketch002 = startSketchOn('XY')
|> startProfileAt([30, 10], %)
|> line([15, 0], %)
|> line([0, -15], %)
|> line([-15, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude002 = extrude(-25, sketch002)` // <--- body 2
let extrude002 = extrude(-25, sketch002)` // <--- body 2
const segmentSnippets = ['line([0, -20], %)', 'line([0, -15], %)']
const radiusValue = 3
const expectedCode = `const sketch001 = startSketchOn('XY')
const expectedCode = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-10, 10], %)
|> line([20, 0], %)
|> line([0, -20], %, $seg01)
|> line([-20, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-15, sketch001)
let extrude001 = extrude(-15, sketch001)
|> fillet({ radius: 3, tags: [seg01] }, %)
const sketch002 = startSketchOn('XY')
let sketch002 = startSketchOn('XY')
|> startProfileAt([30, 10], %)
|> line([15, 0], %)
|> line([0, -15], %, $seg02)
|> line([-15, 0], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude002 = extrude(-25, sketch002)
let extrude002 = extrude(-25, sketch002)
|> fillet({ radius: 3, tags: [seg02] }, %)` // <-- able to add a new one
await runModifyAstWithFilletAndTagTest(
@ -634,13 +634,13 @@ const extrude002 = extrude(-25, sketch002)
})
describe('Testing isTagUsedInFillet', () => {
const code = `const sketch001 = startSketchOn('XZ')
const code = `let 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(%)
const extrude001 = extrude(-5, sketch001)
let extrude001 = extrude(-5, sketch001)
|> fillet({
radius: 1.11,
tags: [
@ -750,17 +750,17 @@ describe('Testing button states', () => {
expect(buttonState).toEqual(expectedState)
}
const codeWithBody: string = `
const sketch001 = startSketchOn('XY')
let sketch001 = startSketchOn('XY')
|> startProfileAt([-20, -5], %)
|> line([0, 10], %)
|> line([10, 0], %)
|> line([0, -10], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-10, sketch001)
let extrude001 = extrude(-10, sketch001)
`
const codeWithoutBodies: string = `
const sketch001 = startSketchOn('XY')
let sketch001 = startSketchOn('XY')
|> startProfileAt([-20, -5], %)
|> line([0, 10], %)
|> line([10, 0], %)

View File

@ -26,21 +26,21 @@ beforeAll(async () => {
describe('findAllPreviousVariables', () => {
it('should find all previous variables', async () => {
const code = `const baseThick = 1
const armAngle = 60
const code = `let baseThick = 1
let armAngle = 60
const baseThickHalf = baseThick / 2
const halfArmAngle = armAngle / 2
let baseThickHalf = baseThick / 2
let halfArmAngle = armAngle / 2
const arrExpShouldNotBeIncluded = [1, 2, 3]
const objExpShouldNotBeIncluded = { a: 1, b: 2, c: 3 }
let arrExpShouldNotBeIncluded = [1, 2, 3]
let objExpShouldNotBeIncluded = { a: 1, b: 2, c: 3 }
const part001 = startSketchOn('XY')
let part001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> yLineTo(1, %)
|> xLine(3.84, %) // selection-range-7ish-before-this
const variableBelowShouldNotBeIncluded = 3
let variableBelowShouldNotBeIncluded = 3
`
const rangeStart = code.indexOf('// selection-range-7ish-before-this') - 7
const ast = parse(code)
@ -67,7 +67,7 @@ const variableBelowShouldNotBeIncluded = 3
})
describe('testing argIsNotIdentifier', () => {
const code = `const part001 = startSketchOn('XY')
const code = `let part001 = startSketchOn('XY')
|> startProfileAt([-1.2, 4.83], %)
|> line([2.8, 0], %)
|> angledLine([100 + 100, 3.09], %)
@ -75,8 +75,8 @@ describe('testing argIsNotIdentifier', () => {
|> angledLine([def('yo'), 3.09], %)
|> angledLine([ghi(%), 3.09], %)
|> angledLine([jkl('yo') + 2, 3.09], %)
const yo = 5 + 6
const yo2 = hmm([identifierGuy + 5])`
let yo = 5 + 6
let yo2 = hmm([identifierGuy + 5])`
it('find a safe binaryExpression', () => {
const ast = parse(code)
if (err(ast)) throw ast
@ -150,7 +150,7 @@ const yo2 = hmm([identifierGuy + 5])`
const replaced = result.replacer(structuredClone(ast), 'replaceName')
if (err(replaced)) throw replaced
const outCode = recast(replaced.modifiedAst)
expect(outCode).toContain(`const yo = replaceName`)
expect(outCode).toContain(`let yo = replaceName`)
})
it('find a safe BinaryExpression that has a CallExpression within', () => {
const ast = parse(code)
@ -186,7 +186,7 @@ const yo2 = hmm([identifierGuy + 5])`
if (err(replaced)) throw replaced
const { modifiedAst } = replaced
const outCode = recast(modifiedAst)
expect(outCode).toContain(`const yo2 = hmm([replaceName])`)
expect(outCode).toContain(`let yo2 = hmm([replaceName])`)
})
describe('testing isTypeInValue', () => {
@ -214,7 +214,7 @@ const yo2 = hmm([identifierGuy + 5])`
})
describe('testing getNodePathFromSourceRange', () => {
const code = `const part001 = startSketchOn('XY')
const code = `let part001 = startSketchOn('XY')
|> startProfileAt([0.39, -0.05], %)
|> line([0.94, 2.61], %)
|> line([-0.21, -1.4], %)`
@ -271,7 +271,7 @@ describe('testing getNodePathFromSourceRange', () => {
describe('testing doesPipeHave', () => {
it('finds close', () => {
const exampleCode = `const length001 = 2
const part001 = startSketchAt([-1.41, 3.46])
let part001 = startSketchAt([-1.41, 3.46])
|> line([19.49, 1.16], %, $seg01)
|> angledLine([-35, length001], %)
|> line([-3.22, -7.36], %)
@ -290,7 +290,7 @@ const part001 = startSketchAt([-1.41, 3.46])
})
it('finds extrude', () => {
const exampleCode = `const length001 = 2
const part001 = startSketchAt([-1.41, 3.46])
let part001 = startSketchAt([-1.41, 3.46])
|> line([19.49, 1.16], %, $seg01)
|> angledLine([-35, length001], %)
|> line([-3.22, -7.36], %)
@ -310,7 +310,7 @@ const part001 = startSketchAt([-1.41, 3.46])
})
it('does NOT find close', () => {
const exampleCode = `const length001 = 2
const part001 = startSketchAt([-1.41, 3.46])
let part001 = startSketchAt([-1.41, 3.46])
|> line([19.49, 1.16], %, $seg01)
|> angledLine([-35, length001], %)
|> line([-3.22, -7.36], %)
@ -343,7 +343,7 @@ const part001 = startSketchAt([-1.41, 3.46])
describe('testing hasExtrudeSketchGroup', () => {
it('find sketch group', async () => {
const exampleCode = `const length001 = 2
const part001 = startSketchAt([-1.41, 3.46])
let part001 = startSketchAt([-1.41, 3.46])
|> line([19.49, 1.16], %, $seg01)
|> angledLine([-35, length001], %)
|> line([-3.22, -7.36], %)
@ -361,7 +361,7 @@ const part001 = startSketchAt([-1.41, 3.46])
})
it('find extrude group', async () => {
const exampleCode = `const length001 = 2
const part001 = startSketchAt([-1.41, 3.46])
let part001 = startSketchAt([-1.41, 3.46])
|> line([19.49, 1.16], %, $seg01)
|> angledLine([-35, length001], %)
|> line([-3.22, -7.36], %)
@ -394,7 +394,7 @@ const part001 = startSketchAt([-1.41, 3.46])
})
describe('Testing findUsesOfTagInPipe', () => {
const exampleCode = `const part001 = startSketchOn('-XZ')
const exampleCode = `let part001 = startSketchOn('-XZ')
|> startProfileAt([68.12, 156.65], %)
|> line([306.21, 198.82], %)
|> line([306.21, 198.85], %, $seg01)

View File

@ -15,27 +15,27 @@ describe('recast', () => {
expect(recasted.trim()).toBe(code)
})
it('variable declaration', () => {
const code = 'const myVar = 5'
const code = 'let myVar = 5'
const { ast } = code2ast(code)
const recasted = recast(ast)
if (err(recasted)) throw recasted
expect(recasted.trim()).toBe(code)
})
it("variable declaration that's binary with string", () => {
const code = "const myVar = 5 + 'yo'"
const code = "let myVar = 5 + 'yo'"
const { ast } = code2ast(code)
const recasted = recast(ast)
if (err(recasted)) throw recasted
expect(recasted.trim()).toBe(code)
const codeWithOtherQuotes = 'const myVar = 5 + "yo"'
const codeWithOtherQuotes = 'let myVar = 5 + "yo"'
const { ast: ast2 } = code2ast(codeWithOtherQuotes)
const recastRetVal = recast(ast2)
if (err(recastRetVal)) throw recastRetVal
expect(recastRetVal.trim()).toBe(codeWithOtherQuotes)
})
it('test assigning two variables, the second summing with the first', () => {
const code = `const myVar = 5
const newVar = myVar + 1
const code = `let myVar = 5
let newVar = myVar + 1
`
const { ast } = code2ast(code)
const recasted = recast(ast)
@ -53,7 +53,7 @@ const newVar = myVar + 1
expect(recasted.trim()).toBe(code.trim())
})
it('test with function call', () => {
const code = `const myVar = "hello"
const code = `let myVar = "hello"
log(5, myVar)
`
const { ast } = code2ast(code)
@ -66,8 +66,8 @@ log(5, myVar)
'fn funcN = (a, b) => {',
' return a + b',
'}',
'const theVar = 60',
'const magicNum = funcN(9, theVar)',
'let theVar = 60',
'let magicNum = funcN(9, theVar)',
].join('\n')
const { ast } = code2ast(code)
const recasted = recast(ast)
@ -75,7 +75,7 @@ log(5, myVar)
expect(recasted.trim()).toBe(code)
})
it('recast sketch declaration', () => {
let code = `const mySketch = startSketchAt([0, 0])
let code = `let mySketch = startSketchAt([0, 0])
|> lineTo([0, 1], %, $myPath)
|> lineTo([1, 1], %)
|> lineTo([1, 0], %, $rightPath)
@ -88,7 +88,7 @@ log(5, myVar)
})
it('sketch piped into callExpression', () => {
const code = [
'const mySk1 = startSketchAt([0, 0])',
'let mySk1 = startSketchAt([0, 0])',
' |> lineTo([1, 1], %)',
' |> lineTo([0, 1], %, $myTag)',
' |> lineTo([1, 1], %)',
@ -104,7 +104,7 @@ log(5, myVar)
'fn myFn = (a) => {',
' return a + 1',
'}',
'const myVar = 5 + 1',
'let myVar = 5 + 1',
' |> myFn(%)',
].join('\n')
const { ast } = code2ast(code)
@ -113,21 +113,21 @@ log(5, myVar)
expect(recasted.trim()).toBe(code)
})
it('recast nested binary expression', () => {
const code = ['const myVar = 1 + 2 * 5'].join('\n')
const code = ['let myVar = 1 + 2 * 5'].join('\n')
const { ast } = code2ast(code)
const recasted = recast(ast)
if (err(recasted)) throw recasted
expect(recasted.trim()).toBe(code.trim())
})
it('recast nested binary expression with parans', () => {
const code = ['const myVar = 1 + (1 + 2) * 5'].join('\n')
const code = ['let myVar = 1 + (1 + 2) * 5'].join('\n')
const { ast } = code2ast(code)
const recasted = recast(ast)
if (err(recasted)) throw recasted
expect(recasted.trim()).toBe(code.trim())
})
it('unnecessary paran wrap will be remove', () => {
const code = ['const myVar = 1 + (2 * 5)'].join('\n')
const code = ['let myVar = 1 + (2 * 5)'].join('\n')
const { ast } = code2ast(code)
const recasted = recast(ast)
if (err(recasted)) throw recasted
@ -148,9 +148,7 @@ log(5, myVar)
expect(recasted.trim()).toBe(code.trim())
})
it('recast array declaration', () => {
const code = ['const three = 3', "const yo = [1, '2', three, 4 + 5]"].join(
'\n'
)
const code = ['let three = 3', "let yo = [1, '2', three, 4 + 5]"].join('\n')
const { ast } = code2ast(code)
const recasted = recast(ast)
if (err(recasted)) throw recasted
@ -158,8 +156,8 @@ log(5, myVar)
})
it('recast long array declaration', () => {
const code = [
'const three = 3',
'const yo = [',
'let three = 3',
'let yo = [',
' 1,',
" '2',",
' three,',
@ -173,8 +171,8 @@ log(5, myVar)
expect(recasted.trim()).toBe(code.trim())
})
it('recast long object execution', () => {
const code = `const three = 3
const yo = {
const code = `let three = 3
let yo = {
aStr: 'str',
anum: 2,
identifier: three,
@ -187,7 +185,7 @@ const yo = {
expect(recasted).toBe(code)
})
it('recast short object execution', () => {
const code = `const yo = { key: 'val' }
const code = `let yo = { key: 'val' }
`
const { ast } = code2ast(code)
const recasted = recast(ast)
@ -195,11 +193,11 @@ const yo = {
expect(recasted).toBe(code)
})
it('recast object execution with member expression', () => {
const code = `const yo = { a: { b: { c: '123' } } }
const key = 'c'
const myVar = yo.a['b'][key]
const key2 = 'b'
const myVar2 = yo['a'][key2].c
const code = `let yo = { a: { b: { c: '123' } } }
let key = 'c'
let myVar = yo.a['b'][key]
let key2 = 'b'
let myVar2 = yo['a'][key2].c
`
const { ast } = code2ast(code)
const recasted = recast(ast)
@ -210,9 +208,9 @@ const myVar2 = yo['a'][key2].c
describe('testing recasting with comments and whitespace', () => {
it('code with comments', () => {
const code = `const yo = { a: { b: { c: '123' } } }
const code = `let yo = { a: { b: { c: '123' } } }
// this is a comment
const key = 'c'
let key = 'c'
`
const { ast } = code2ast(code)
@ -222,12 +220,12 @@ const key = 'c'
expect(recasted).toBe(code)
})
it('code with comment and extra lines', () => {
const code = `const yo = 'c'
const code = `let yo = 'c'
/* this is
a
comment */
const yo = 'bing'
let yo = 'bing'
`
const { ast } = code2ast(code)
const recasted = recast(ast)
@ -236,8 +234,8 @@ const yo = 'bing'
})
it('comments at the start and end', () => {
const code = `// this is a comment
const yo = { a: { b: { c: '123' } } }
const key = 'c'
let yo = { a: { b: { c: '123' } } }
let key = 'c'
// this is also a comment
`
@ -249,11 +247,11 @@ const key = 'c'
it('comments in a fn block', () => {
const code = `fn myFn = () => {
// this is a comment
const yo = { a: { b: { c: '123' } } }
let yo = { a: { b: { c: '123' } } }
/* block
comment */
const key = 'c'
let key = 'c'
// this is also a comment
}
`
@ -264,7 +262,7 @@ const key = 'c'
})
it('comments in a pipe expression', () => {
const code = [
'const mySk1 = startSketchAt([0, 0])',
'let mySk1 = startSketchAt([0, 0])',
' |> lineTo([1, 1], %)',
' |> lineTo([0, 1], %, $myTag)',
' |> lineTo([1, 1], %)',
@ -280,7 +278,7 @@ const key = 'c'
const code = `
/* comment at start */
const mySk1 = startSketchAt([0, 0])
let mySk1 = startSketchAt([0, 0])
|> lineTo([1, 1], %)
// comment here
|> lineTo([0, 1], %, $myTag)
@ -303,7 +301,7 @@ one more for good measure
if (err(recasted)) throw recasted
expect(recasted).toBe(`/* comment at start */
const mySk1 = startSketchAt([0, 0])
let mySk1 = startSketchAt([0, 0])
|> lineTo([1, 1], %)
// comment here
|> lineTo([0, 1], %, $myTag)
@ -321,21 +319,21 @@ const mySk1 = startSketchAt([0, 0])
describe('testing call Expressions in BinaryExpressions and UnaryExpressions', () => {
it('nested callExpression in binaryExpression', () => {
const code = 'const myVar = 2 + min(100, legLen(5, 3))'
const code = 'let myVar = 2 + min(100, legLen(5, 3))'
const { ast } = code2ast(code)
const recasted = recast(ast)
if (err(recasted)) throw recasted
expect(recasted.trim()).toBe(code)
})
it('nested callExpression in unaryExpression', () => {
const code = 'const myVar = -min(100, legLen(5, 3))'
const code = 'let myVar = -min(100, legLen(5, 3))'
const { ast } = code2ast(code)
const recasted = recast(ast)
if (err(recasted)) throw recasted
expect(recasted.trim()).toBe(code)
})
it('with unaryExpression in callExpression', () => {
const code = 'const myVar = min(5, -legLen(5, 4))'
const code = 'let myVar = min(5, -legLen(5, 4))'
const { ast } = code2ast(code)
const recasted = recast(ast)
if (err(recasted)) throw recasted
@ -343,7 +341,7 @@ describe('testing call Expressions in BinaryExpressions and UnaryExpressions', (
})
it('with unaryExpression in sketch situation', () => {
const code = [
'const part001 = startSketchAt([0, 0])',
'let part001 = startSketchAt([0, 0])',
' |> line([-2.21, -legLen(5, min(3, 999))], %)',
].join('\n')
const { ast } = code2ast(code)
@ -355,7 +353,7 @@ 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 = `const part001 = startSketchAt([-0.01, -0.08])
const code = `let part001 = startSketchAt([-0.01, -0.08])
|> line([0.62, 4.15], %, $seg01)
|> line([2.77, -1.24], %)
|> angledLineThatIntersects({
@ -386,7 +384,7 @@ describe('it recasts wrapped object expressions in pipe bodies with correct inde
describe('it recasts binary expression using brackets where needed', () => {
it('when there are two minus in a row', () => {
const code = `const part001 = 1 - (def - abc)
const code = `let part001 = 1 - (def - abc)
`
const recasted = recast(code2ast(code).ast)
expect(recasted).toBe(code)

View File

@ -31,52 +31,52 @@ It's needed for testing the artifactGraph, as it is tied to the websocket comman
const pathStart = 'src/lang/std/artifactMapCache'
const fullPath = `${pathStart}/artifactMapCache.json`
const exampleCode1 = `const sketch001 = startSketchOn('XY')
const exampleCode1 = `let sketch001 = startSketchOn('XY')
|> startProfileAt([-5, -5], %)
|> line([0, 10], %)
|> line([10.55, 0], %, $seg01)
|> line([0, -10], %, $seg02)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(-10, sketch001)
let extrude001 = extrude(-10, sketch001)
|> fillet({ radius: 5, tags: [seg01] }, %)
const sketch002 = startSketchOn(extrude001, seg02)
let sketch002 = startSketchOn(extrude001, seg02)
|> startProfileAt([-2, -6], %)
|> line([2, 3], %)
|> line([2, -3], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude002 = extrude(5, sketch002)
let extrude002 = extrude(5, sketch002)
`
const sketchOnFaceOnFaceEtc = `const sketch001 = startSketchOn('XZ')
const sketchOnFaceOnFaceEtc = `let sketch001 = startSketchOn('XZ')
|> startProfileAt([0, 0], %)
|> line([4, 8], %)
|> line([5, -8], %, $seg01)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude001 = extrude(6, sketch001)
const sketch002 = startSketchOn(extrude001, seg01)
let extrude001 = extrude(6, sketch001)
let sketch002 = startSketchOn(extrude001, seg01)
|> startProfileAt([-0.5, 0.5], %)
|> line([2, 5], %)
|> line([2, -5], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude002 = extrude(5, sketch002)
const sketch003 = startSketchOn(extrude002, 'END')
let extrude002 = extrude(5, sketch002)
let sketch003 = startSketchOn(extrude002, 'END')
|> startProfileAt([1, 1.5], %)
|> line([0.5, 2], %, $seg02)
|> line([1, -2], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude003 = extrude(4, sketch003)
const sketch004 = startSketchOn(extrude003, seg02)
let extrude003 = extrude(4, sketch003)
let sketch004 = startSketchOn(extrude003, seg02)
|> startProfileAt([-3, 14], %)
|> line([0.5, 1], %)
|> line([0.5, -2], %)
|> lineTo([profileStartX(%), profileStartY(%)], %)
|> close(%)
const extrude004 = extrude(3, sketch004)
let extrude004 = extrude(3, sketch004)
`
// add more code snippets here and use `getCommands` to get the orderedCommands and responseMap for more tests

Binary file not shown.

Before

Width:  |  Height:  |  Size: 378 KiB

After

Width:  |  Height:  |  Size: 244 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 613 KiB

After

Width:  |  Height:  |  Size: 446 KiB

View File

@ -106,7 +106,7 @@ describe('testing changeSketchArguments', () => {
const lineAfterChange = 'lineTo([2, 3], %)'
test('changeSketchArguments', async () => {
// Enable rotations #152
const genCode = (line: string) => `const mySketch001 = startSketchOn('XY')
const genCode = (line: string) => `let mySketch001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> ${line}
|> lineTo([0.46, -5.82], %)
@ -142,7 +142,7 @@ describe('testing addNewSketchLn', () => {
test('addNewSketchLn', async () => {
// Enable rotations #152
const code = `
const mySketch001 = startSketchOn('XY')
let mySketch001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
// |> rx(45, %)
|> lineTo([-1.59, -1.54], %)
@ -152,7 +152,7 @@ const mySketch001 = startSketchOn('XY')
const programMemory = await enginelessExecutor(ast)
const sourceStart = code.indexOf(lineToChange)
expect(sourceStart).toBe(95)
expect(sourceStart).toBe(93)
const newSketchLnRetVal = addNewSketchLn({
node: ast,
programMemory,
@ -173,7 +173,7 @@ const mySketch001 = startSketchOn('XY')
if (err(newSketchLnRetVal)) return newSketchLnRetVal
// Enable rotations #152
let expectedCode = `const mySketch001 = startSketchOn('XY')
let expectedCode = `let mySketch001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
// |> rx(45, %)
|> lineTo([-1.59, -1.54], %)
@ -197,7 +197,7 @@ const mySketch001 = startSketchOn('XY')
})
if (err(modifiedAst2)) return modifiedAst2
expectedCode = `const mySketch001 = startSketchOn('XY')
expectedCode = `let mySketch001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
// |> rx(45, %)
|> lineTo([-1.59, -1.54], %)
@ -212,7 +212,7 @@ describe('testing addTagForSketchOnFace', () => {
it('needs to be in it', async () => {
const originalLine = 'lineTo([-1.59, -1.54], %)'
// Enable rotations #152
const genCode = (line: string) => `const mySketch001 = startSketchOn('XY')
const genCode = (line: string) => `let mySketch001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
// |> rx(45, %)
|> ${line}

View File

@ -69,7 +69,7 @@ async function testingSwapSketchFnCall({
describe('testing swapping out sketch calls with xLine/xLineTo', () => {
const bigExampleArr = [
`const part001 = startSketchOn('XY')`,
`let part001 = startSketchOn('XY')`,
` |> startProfileAt([0, 0], %)`,
` |> lineTo([1, 1], %, $abc1)`,
` |> line([-2.04, -0.7], %, $abc2)`,
@ -258,14 +258,14 @@ describe('testing swapping out sketch calls with xLine/xLineTo', () => {
describe('testing swapping out sketch calls with xLine/xLineTo while keeping variable/identifiers intact', () => {
// Enable rotations #152
const variablesExampleArr = [
`const lineX = -1`,
`const lineToX = -1.3`,
`const angledLineAngle = 207`,
`const angledLineOfXLengthX = 0.8`,
`const angledLineOfYLengthY = 0.89`,
`const angledLineToXx = -1.86`,
`const angledLineToYy = -0.76`,
`const part001 = startSketchOn('XY')`,
`let lineX = -1`,
`let lineToX = -1.3`,
`let angledLineAngle = 207`,
`let angledLineOfXLengthX = 0.8`,
`let angledLineOfYLengthY = 0.89`,
`let angledLineToXx = -1.86`,
`let angledLineToYy = -0.76`,
`let part001 = startSketchOn('XY')`,
` |> startProfileAt([0, 0], %)`,
// ` |> rx(90, %)`,
` |> lineTo([1, 1], %)`,
@ -359,7 +359,7 @@ describe('testing swapping out sketch calls with xLine/xLineTo while keeping var
describe('testing getSketchSegmentIndexFromSourceRange', () => {
const code = `
const part001 = startSketchOn('XY')
let part001 = startSketchOn('XY')
|> startProfileAt([0, 0.04], %) // segment-in-start
|> line([0, 0.4], %)
|> xLine(3.48, %)

View File

@ -96,12 +96,12 @@ function makeSelections(
}
describe('testing transformAstForSketchLines for equal length constraint', () => {
const inputScript = `const myVar = 3
const myVar2 = 5
const myVar3 = 6
const myAng = 40
const myAng2 = 134
const part001 = startSketchOn('XY')
const inputScript = `let myVar = 3
let myVar2 = 5
let myVar3 = 6
let myAng = 40
let myAng2 = 134
let part001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([1, 3.82], %) // ln-should-get-tag
|> lineTo([myVar, 1], %) // ln-lineTo-xAbsolute should use angleToMatchLengthX helper
@ -132,12 +132,12 @@ const part001 = startSketchOn('XY')
|> xLineTo(30, %) // ln-xLineTo-free should convert to xLine
|> yLineTo(20, %) // ln-yLineTo-free should convert to yLine
`
const expectModifiedScript = `const myVar = 3
const myVar2 = 5
const myVar3 = 6
const myAng = 40
const myAng2 = 134
const part001 = startSketchOn('XY')
const expectModifiedScript = `let myVar = 3
let myVar2 = 5
let myVar3 = 6
let myAng = 40
let myAng2 = 134
let part001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([1, 3.82], %, $seg01) // ln-should-get-tag
|> angledLineToX([
@ -241,10 +241,10 @@ const part001 = startSketchOn('XY')
})
describe('testing transformAstForSketchLines for vertical and horizontal constraint', () => {
const inputScript = `const myVar = 2
const myVar2 = 12
const myVar3 = -10
const part001 = startSketchOn('XY')
const inputScript = `let myVar = 2
let myVar2 = 12
let myVar3 = -10
let part001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> lineTo([1, 1], %)
|> line([-6.28, 1.4], %) // select for horizontal constraint 1
@ -269,10 +269,10 @@ const part001 = startSketchOn('XY')
|> angledLineToY([301, myVar], %) // select for vertical constraint 10
`
it('should transform horizontal lines the ast', async () => {
const expectModifiedScript = `const myVar = 2
const myVar2 = 12
const myVar3 = -10
const part001 = startSketchOn('XY')
const expectModifiedScript = `let myVar = 2
let myVar2 = 12
let myVar3 = -10
let part001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> lineTo([1, 1], %)
|> xLine(-6.28, %) // select for horizontal constraint 1
@ -331,10 +331,10 @@ const part001 = startSketchOn('XY')
expect(newCode).toBe(expectModifiedScript)
})
it('should transform vertical lines the ast', async () => {
const expectModifiedScript = `const myVar = 2
const myVar2 = 12
const myVar3 = -10
const part001 = startSketchOn('XY')
const expectModifiedScript = `let myVar = 2
let myVar2 = 12
let myVar3 = -10
let part001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> lineTo([1, 1], %)
|> line([-6.28, 1.4], %) // select for horizontal constraint 1
@ -396,8 +396,8 @@ const part001 = startSketchOn('XY')
describe('testing transformAstForSketchLines for vertical and horizontal distance constraints', () => {
describe('testing setHorzDistance for line', () => {
const inputScript = `const myVar = 1
const part001 = startSketchOn('XY')
const inputScript = `let myVar = 1
let part001 = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([0.31, 1.67], %) // base selection
|> line([0.45, 1.46], %)
@ -505,7 +505,7 @@ const baseThickHalf = baseThick / 2
const halfHeight = totalHeight / 2
const halfArmAngle = armAngle / 2
const part001 = startSketchOn('XY')
let part001 = startSketchOn('XY')
|> startProfileAt([-0.01, -0.05], %)
|> line([0.01, 0.94 + 0], %) // partial
|> xLine(3.03, %) // partial

View File

@ -1 +1 @@
const myVar = "a str" + " another str"
let myVar = "a str" + " another str"

View File

@ -2207,7 +2207,7 @@ fn hmm = (x) => {
return x
}
const yo = 5 + 6
let yo = 5 + 6
const abc = 3
const identifierGuy = 5

View File

@ -1759,7 +1759,7 @@ mod tests {
#[test]
fn test_comments_in_function2() {
let test_program = r#"() => {
const yo = { a: { b: { c: '123' } } } /* block
let yo = { a: { b: { c: '123' } } } /* block
comment */
}"#;
let tokens = crate::token::lexer(test_program).unwrap();
@ -1899,7 +1899,7 @@ const mySk1 = startSketchAt([0, 0])"#;
#[test]
fn many_comments() {
let test_program = r#"// this is a comment
const yo = { a: { b: { c: '123' } } } /* block
let yo = { a: { b: { c: '123' } } } /* block
comment */
const key = 'c'
@ -1957,7 +1957,7 @@ const mySk1 = startSketchAt([0, 0])"#;
#[test]
fn inline_block_comments() {
let test_program = r#"const yo = 3 /* block
let test_program = r#"let yo = 3 /* block
comment */
return 1"#;

View File

@ -1114,7 +1114,7 @@ show(part001)"#;
fn test_program3() {
let program = r#"
// this is a comment
const yo = { a: { b: { c: '123' } } }
let yo = { a: { b: { c: '123' } } }
const key = 'c'
const things = "things"

View File

@ -4,7 +4,7 @@ use crate::{
ast::types::{
ArrayExpression, BinaryExpression, BinaryOperator, BinaryPart, BodyItem, CallExpression, Expr, FormatOptions,
FunctionExpression, Literal, LiteralIdentifier, LiteralValue, MemberExpression, MemberObject, NonCodeValue,
ObjectExpression, PipeExpression, Program, TagDeclarator, UnaryExpression, VariableDeclaration,
ObjectExpression, PipeExpression, Program, TagDeclarator, UnaryExpression, VariableDeclaration, VariableKind,
},
parser::PIPE_OPERATOR,
};
@ -164,12 +164,17 @@ impl CallExpression {
impl VariableDeclaration {
pub fn recast(&self, options: &FormatOptions, indentation_level: usize) -> String {
let indentation = options.get_indentation(indentation_level);
let kind = match self.kind {
VariableKind::Fn => "fn",
VariableKind::Let | VariableKind::Const => "let",
VariableKind::Var => "var",
};
self.declarations.iter().fold(String::new(), |mut output, declaration| {
let _ = write!(
output,
"{}{} {} = {}",
indentation,
self.kind,
kind,
declaration.id.name,
declaration.init.recast(options, indentation_level, false).trim()
);
@ -1297,7 +1302,7 @@ const tabs_l = startSketchOn({
fn test_recast_comment_in_a_fn_block() {
let some_program_string = r#"fn myFn = () => {
// this is a comment
const yo = { a: { b: { c: '123' } } } /* block
let yo = { a: { b: { c: '123' } } } /* block
comment */
const key = 'c'
@ -1313,7 +1318,7 @@ const tabs_l = startSketchOn({
recasted,
r#"fn myFn = () => {
// this is a comment
const yo = { a: { b: { c: '123' } } } /* block
let yo = { a: { b: { c: '123' } } } /* block
comment */
const key = 'c'
@ -1514,13 +1519,13 @@ const mySk1 = startSketchOn('XY')
fn test_recast_first_level_object() {
let some_program_string = r#"const three = 3
const yo = {
let yo = {
aStr: 'str',
anum: 2,
identifier: three,
binExp: 4 + 5
}
const yo = [
let yo = [
1,
" 2,",
"three",
@ -1540,7 +1545,7 @@ const yo = [
fn test_recast_new_line_before_comment() {
let some_program_string = r#"
// this is a comment
const yo = { a: { b: { c: '123' } } }
let yo = { a: { b: { c: '123' } } }
const key = 'c'
const things = "things"

View File

@ -353,7 +353,7 @@ fn roundedRectangle = (pos, w, l, cornerRadius) => {
const holeRadius = 1
const holeIndex = 6
const part = roundedRectangle([0, 0], 20, 20, 4)
let part = roundedRectangle([0, 0], 20, 20, 4)
|> hole(circle({ center: [-holeIndex, holeIndex], radius: holeRadius }, %), %)
|> hole(circle({ center: [holeIndex, holeIndex], radius: holeRadius }, %), %)
|> hole(circle({ center: [-holeIndex, -holeIndex], radius: holeRadius }, %), %)
@ -377,7 +377,7 @@ async fn kcl_test_top_level_expression() {
async fn kcl_test_patterns_linear_basic_with_math() {
let code = r#"const num = 12
const distance = 5
const part = startSketchOn('XY')
let part = startSketchOn('XY')
|> circle({ center: [0,0], radius: 2 }, %)
|> patternLinear2d({axis: [0,1], repetitions: num -1, distance: distance - 1}, %)
|> extrude(1, %)
@ -389,7 +389,7 @@ const part = startSketchOn('XY')
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_patterns_linear_basic() {
let code = r#"const part = startSketchOn('XY')
let code = r#"let part = startSketchOn('XY')
|> circle({ center: [0,0], radius: 2 }, %)
|> patternLinear2d({axis: [0,1], repetitions: 12, distance: 4}, %)
|> extrude(1, %)
@ -401,7 +401,7 @@ async fn kcl_test_patterns_linear_basic() {
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_patterns_linear_basic_3d() {
let code = r#"const part = startSketchOn('XY')
let code = r#"let part = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([0,1], %)
|> line([1, 0], %)
@ -417,7 +417,7 @@ async fn kcl_test_patterns_linear_basic_3d() {
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_patterns_linear_basic_negative_distance() {
let code = r#"const part = startSketchOn('XY')
let code = r#"let part = startSketchOn('XY')
|> circle({ center: [0,0], radius: 2 }, %)
|> patternLinear2d({axis: [0,1], repetitions: 12, distance: -2}, %)
|> extrude(1, %)
@ -429,7 +429,7 @@ async fn kcl_test_patterns_linear_basic_negative_distance() {
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_patterns_linear_basic_negative_axis() {
let code = r#"const part = startSketchOn('XY')
let code = r#"let part = startSketchOn('XY')
|> circle({ center: [0,0], radius: 2 }, %)
|> patternLinear2d({axis: [0,-1], repetitions: 12, distance: 2}, %)
|> extrude(1, %)
@ -462,7 +462,7 @@ const rectangle = startSketchOn('XY')
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_patterns_circular_basic_2d() {
let code = r#"const part = startSketchOn('XY')
let code = r#"let part = startSketchOn('XY')
|> circle({ center: [0,0], radius: 2 }, %)
|> patternCircular2d({center: [20, 20], repetitions: 12, arcDegrees: 210, rotateDuplicates: true}, %)
|> extrude(1, %)
@ -474,7 +474,7 @@ async fn kcl_test_patterns_circular_basic_2d() {
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_patterns_circular_basic_3d() {
let code = r#"const part = startSketchOn('XY')
let code = r#"let part = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([0,1], %)
|> line([1, 0], %)
@ -490,7 +490,7 @@ async fn kcl_test_patterns_circular_basic_3d() {
#[tokio::test(flavor = "multi_thread")]
async fn kcl_test_patterns_circular_3d_tilted_axis() {
let code = r#"const part = startSketchOn('XY')
let code = r#"let part = startSketchOn('XY')
|> startProfileAt([0, 0], %)
|> line([0,1], %)
|> line([1, 0], %)
@ -845,7 +845,7 @@ const holeRadius = 1
const holeIndex = 6
// Create the mounting plate extrusion, holes, and fillets
const part = rectShape([0, 0], 20, 20)
let part = rectShape([0, 0], 20, 20)
|> hole(circle('XY', [-holeIndex, holeIndex], holeRadius), %)
|> hole(circle('XY', [holeIndex, holeIndex], holeRadius), %)
|> hole(circle('XY', [-holeIndex, -holeIndex], holeRadius), %)