* Code changes Signed-off-by: Nick Cameron <nrc@ncameron.org> * test changes Signed-off-by: Nick Cameron <nrc@ncameron.org> * Frontend changes Signed-off-by: Nick Cameron <nrc@ncameron.org> * Refactor asNum Co-authored-by: Jonathan Tran <jonnytran@gmail.com> --------- Signed-off-by: Nick Cameron <nrc@ncameron.org> Co-authored-by: Jonathan Tran <jonnytran@gmail.com>
60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import { assertParse, initPromise, parse } from './wasm'
|
|
import { err } from 'lib/trap'
|
|
|
|
beforeAll(async () => {
|
|
await initPromise
|
|
})
|
|
|
|
describe('testing AST', () => {
|
|
test('5 + 6', () => {
|
|
const ast = assertParse('5 +6')
|
|
delete (ast as any).nonCodeMeta
|
|
expect(ast.body).toEqual([
|
|
{
|
|
type: 'ExpressionStatement',
|
|
start: 0,
|
|
end: 4,
|
|
|
|
expression: {
|
|
type: 'BinaryExpression',
|
|
start: 0,
|
|
end: 4,
|
|
|
|
left: {
|
|
type: 'Literal',
|
|
start: 0,
|
|
end: 1,
|
|
value: {
|
|
suffix: 'None',
|
|
value: 5,
|
|
},
|
|
raw: '5',
|
|
},
|
|
operator: '+',
|
|
right: {
|
|
type: 'Literal',
|
|
start: 3,
|
|
end: 4,
|
|
value: {
|
|
suffix: 'None',
|
|
value: 6,
|
|
},
|
|
raw: '6',
|
|
},
|
|
},
|
|
},
|
|
])
|
|
})
|
|
})
|
|
|
|
describe('parsing errors', () => {
|
|
it('should return an error when there is a unexpected closed curly brace', async () => {
|
|
const code = `const myVar = startSketchAt([}], %)`
|
|
const result = parse(code)
|
|
if (err(result)) throw result
|
|
const error = result.errors[0]
|
|
expect(error.message).toBe('Array is missing a closing bracket(`]`)')
|
|
expect(error.sourceRange).toEqual([28, 29, 0])
|
|
})
|
|
})
|