More tests

This commit is contained in:
Adam Chalmers
2024-09-25 11:53:01 -05:00
parent 5274ae80db
commit 94b6ad2e68

View File

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