add the ability to edit sketch later
This commit is contained in:
@ -3,7 +3,7 @@ import fs from 'node:fs'
|
||||
import { abstractSyntaxTree } from './abstractSyntaxTree'
|
||||
import { lexer } from './tokeniser'
|
||||
import { executor, ProgramMemory } from './executor'
|
||||
import { Transform } from './sketch'
|
||||
import { Transform, SketchGeo } from './sketch'
|
||||
|
||||
describe('test', () => {
|
||||
it('test assigning two variables, the second summing with the first', () => {
|
||||
@ -64,7 +64,7 @@ show(mySketch)
|
||||
`
|
||||
const { root, return: _return } = exe(code)
|
||||
expect(
|
||||
root.mySketch.map(
|
||||
root.mySketch.sketch.map(
|
||||
({ previousPath, firstPath, geo, ...rest }: any) => rest
|
||||
)
|
||||
).toEqual([
|
||||
@ -77,7 +77,7 @@ show(mySketch)
|
||||
sourceRange: [93, 100],
|
||||
},
|
||||
])
|
||||
expect(root.mySketch[0]).toEqual(root.mySketch[4].firstPath)
|
||||
expect(root.mySketch.sketch[0]).toEqual(root.mySketch.sketch[4].firstPath)
|
||||
// hmm not sure what handle the "show" function
|
||||
expect(_return).toEqual([
|
||||
{
|
||||
@ -109,7 +109,7 @@ show(mySketch)
|
||||
// 'show(mySk1)',
|
||||
].join('\n')
|
||||
const { root } = exe(code)
|
||||
expect(root.mySk1).toHaveLength(4)
|
||||
expect(root.mySk1.sketch).toHaveLength(4)
|
||||
expect(root?.rotated?.type).toBe('transform')
|
||||
})
|
||||
|
||||
@ -124,9 +124,7 @@ show(mySketch)
|
||||
const { root } = exe(code)
|
||||
const striptVersion = removeGeoFromSketch(root.mySk1)
|
||||
expect(striptVersion).toEqual({
|
||||
type: 'transform',
|
||||
rotation: [1.5707963267948966, 0, 0],
|
||||
transform: [0, 0, 0],
|
||||
type: 'sketchGeo',
|
||||
sketch: [
|
||||
{
|
||||
type: 'base',
|
||||
@ -150,8 +148,38 @@ show(mySketch)
|
||||
sourceRange: [60, 71],
|
||||
},
|
||||
],
|
||||
sourceRange: [77, 86],
|
||||
sourceRange: [13, 73],
|
||||
})
|
||||
// old expect
|
||||
// expect(striptVersion).toEqual({
|
||||
// type: 'transform',
|
||||
// rotation: [1.5707963267948966, 0, 0],
|
||||
// transform: [0, 0, 0],
|
||||
// sketch: [
|
||||
// {
|
||||
// type: 'base',
|
||||
// from: [0, 0],
|
||||
// sourceRange: [0, 0],
|
||||
// },
|
||||
// {
|
||||
// type: 'toPoint',
|
||||
// to: [1, 1],
|
||||
// sourceRange: [17, 28],
|
||||
// },
|
||||
// {
|
||||
// type: 'toPoint',
|
||||
// to: [0, 1],
|
||||
// sourceRange: [36, 57],
|
||||
// name: 'myPath',
|
||||
// },
|
||||
// {
|
||||
// type: 'toPoint',
|
||||
// to: [1, 1],
|
||||
// sourceRange: [60, 71],
|
||||
// },
|
||||
// ],
|
||||
// sourceRange: [77, 86],
|
||||
// })
|
||||
})
|
||||
})
|
||||
|
||||
@ -166,8 +194,8 @@ function exe(
|
||||
return executor(ast, programMemory)
|
||||
}
|
||||
|
||||
function removeGeoFromSketch(sketch: Transform): any {
|
||||
if (!Array.isArray(sketch.sketch)) {
|
||||
function removeGeoFromSketch(sketch: Transform | SketchGeo): any {
|
||||
if (sketch.type !== 'sketchGeo') {
|
||||
return removeGeoFromSketch(sketch.sketch)
|
||||
}
|
||||
return {
|
||||
|
Reference in New Issue
Block a user