🚨🦀 Setup Rust -> WASM 🦀🚨 (#28)
* initial tokeniser to wasm port * fix tests * add wasm to build script * add rust tools to test action * tweaks * maybe tests will be happy * tweak simple server * trying to get tests to pass * it pget vercel to build * tidy up * clean up rust files * change lexer to use recursion so that it's consistent with the rest of the interpreter * clean up nokeniser further * rename variables * readme typos * run rust tests in CI * follow clippy's advice * more clippy clean up * setup up proper serialzation to js-land * tidy init promise in tests
This commit is contained in:
@ -12,6 +12,9 @@ import {
|
||||
} from '../abstractSyntaxTree'
|
||||
import { recast } from '../recast'
|
||||
import { executor } from '../executor'
|
||||
import { initPromise } from '../rust'
|
||||
|
||||
beforeAll(() => initPromise)
|
||||
|
||||
const eachQuad: [number, [number, number]][] = [
|
||||
[-315, [1, 1]],
|
||||
@ -159,32 +162,34 @@ show(mySketch001)`
|
||||
})
|
||||
|
||||
describe('testing addTagForSketchOnFace', () => {
|
||||
const originalLine = 'lineTo([-1.59, -1.54], %)'
|
||||
const genCode = (line: string) => `
|
||||
const mySketch001 = startSketchAt([0, 0])
|
||||
|> rx(45, %)
|
||||
|> ${line}
|
||||
|> lineTo([0.46, -5.82], %)
|
||||
show(mySketch001)`
|
||||
const code = genCode(originalLine)
|
||||
const ast = abstractSyntaxTree(lexer(code))
|
||||
const programMemory = executor(ast)
|
||||
const sourceStart = code.indexOf(originalLine)
|
||||
const sourceRange: [number, number] = [
|
||||
sourceStart,
|
||||
sourceStart + originalLine.length,
|
||||
]
|
||||
const pathToNode = getNodePathFromSourceRange(ast, sourceRange)
|
||||
const { modifiedAst } = addTagForSketchOnFace(
|
||||
{
|
||||
previousProgramMemory: programMemory,
|
||||
pathToNode,
|
||||
node: ast,
|
||||
},
|
||||
'lineTo'
|
||||
)
|
||||
const expectedCode = genCode(
|
||||
"lineTo({ to: [-1.59, -1.54], tag: 'seg01' }, %)"
|
||||
)
|
||||
expect(recast(modifiedAst)).toBe(expectedCode)
|
||||
it('needs to be in it', () => {
|
||||
const originalLine = 'lineTo([-1.59, -1.54], %)'
|
||||
const genCode = (line: string) => `
|
||||
const mySketch001 = startSketchAt([0, 0])
|
||||
|> rx(45, %)
|
||||
|> ${line}
|
||||
|> lineTo([0.46, -5.82], %)
|
||||
show(mySketch001)`
|
||||
const code = genCode(originalLine)
|
||||
const ast = abstractSyntaxTree(lexer(code))
|
||||
const programMemory = executor(ast)
|
||||
const sourceStart = code.indexOf(originalLine)
|
||||
const sourceRange: [number, number] = [
|
||||
sourceStart,
|
||||
sourceStart + originalLine.length,
|
||||
]
|
||||
const pathToNode = getNodePathFromSourceRange(ast, sourceRange)
|
||||
const { modifiedAst } = addTagForSketchOnFace(
|
||||
{
|
||||
previousProgramMemory: programMemory,
|
||||
pathToNode,
|
||||
node: ast,
|
||||
},
|
||||
'lineTo'
|
||||
)
|
||||
const expectedCode = genCode(
|
||||
"lineTo({ to: [-1.59, -1.54], tag: 'seg01' }, %)"
|
||||
)
|
||||
expect(recast(modifiedAst)).toBe(expectedCode)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user