2023-02-03 10:04:16 +11:00
|
|
|
import { processMemory } from './MemoryPanel'
|
2023-08-18 19:37:52 +10:00
|
|
|
import { parser_wasm } from '../lang/abstractSyntaxTree'
|
2023-07-10 15:15:07 +10:00
|
|
|
import { enginelessExecutor } from '../lib/testHelpers'
|
2023-02-21 09:42:41 +11:00
|
|
|
import { initPromise } from '../lang/rust'
|
2023-02-03 10:04:16 +11:00
|
|
|
|
2023-02-21 09:42:41 +11:00
|
|
|
beforeAll(() => initPromise)
|
2023-02-03 10:04:16 +11:00
|
|
|
|
2023-02-21 09:42:41 +11:00
|
|
|
describe('processMemory', () => {
|
2023-06-22 16:43:33 +10:00
|
|
|
it('should grab the values and remove and geo data', async () => {
|
2023-07-10 15:15:07 +10:00
|
|
|
// Enable rotations #152
|
2023-02-21 09:42:41 +11:00
|
|
|
const code = `
|
|
|
|
const myVar = 5
|
|
|
|
const myFn = (a) => {
|
|
|
|
return a - 2
|
|
|
|
}
|
|
|
|
const otherVar = myFn(5)
|
|
|
|
|
|
|
|
const theExtrude = startSketchAt([0, 0])
|
|
|
|
|> lineTo([-2.4, myVar], %)
|
|
|
|
|> lineTo([-0.76, otherVar], %)
|
|
|
|
|> extrude(4, %)
|
|
|
|
|
|
|
|
const theSketch = startSketchAt([0, 0])
|
|
|
|
|> lineTo([-3.35, 0.17], %)
|
|
|
|
|> lineTo([0.98, 5.16], %)
|
|
|
|
|> lineTo([2.15, 4.32], %)
|
2023-07-10 15:15:07 +10:00
|
|
|
// |> rx(90, %)
|
2023-02-21 09:42:41 +11:00
|
|
|
show(theExtrude, theSketch)`
|
2023-08-18 19:37:52 +10:00
|
|
|
const ast = parser_wasm(code)
|
2023-07-10 15:15:07 +10:00
|
|
|
const programMemory = await enginelessExecutor(ast, {
|
2023-02-21 09:42:41 +11:00
|
|
|
root: {
|
|
|
|
log: {
|
|
|
|
type: 'userVal',
|
|
|
|
value: (a: any) => {
|
|
|
|
console.log('raw log', a)
|
|
|
|
},
|
|
|
|
__meta: [],
|
2023-02-03 10:04:16 +11:00
|
|
|
},
|
|
|
|
},
|
2023-06-22 16:43:33 +10:00
|
|
|
pendingMemory: {},
|
2023-02-21 09:42:41 +11:00
|
|
|
})
|
2023-02-03 10:04:16 +11:00
|
|
|
const output = processMemory(programMemory)
|
|
|
|
expect(output.myVar).toEqual(5)
|
|
|
|
expect(output.myFn).toEqual('__function__')
|
|
|
|
expect(output.otherVar).toEqual(3)
|
|
|
|
expect(output).toEqual({
|
|
|
|
myVar: 5,
|
|
|
|
myFn: '__function__',
|
|
|
|
otherVar: 3,
|
2023-07-10 15:15:07 +10:00
|
|
|
theExtrude: [],
|
2023-02-03 10:04:16 +11:00
|
|
|
theSketch: [
|
|
|
|
{ type: 'toPoint', to: [-3.35, 0.17], from: [0, 0] },
|
|
|
|
{ type: 'toPoint', to: [0.98, 5.16], from: [-3.35, 0.17] },
|
|
|
|
{ type: 'toPoint', to: [2.15, 4.32], from: [0.98, 5.16] },
|
|
|
|
],
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|