This commit is contained in:
Kurt Hutten IrevDev
2022-12-23 07:47:22 +11:00
parent 544f20852c
commit 1c1ceae4d3
4 changed files with 51 additions and 40 deletions

View File

@ -3,8 +3,8 @@ import { lexer } from './tokeniser'
import { abstractSyntaxTree, getNodeFromPath } from './abstractSyntaxTree'
describe('testing getNodePathFromSourceRange', () => {
it('test it gets the right path for a `lineTo` CallExpression within a SketchExpression', () => {
const code = `
it('test it gets the right path for a `lineTo` CallExpression within a SketchExpression', () => {
const code = `
const myVar = 5
sketch sk3 {
lineTo(1, 2)
@ -12,16 +12,18 @@ describe('testing getNodePathFromSourceRange', () => {
close()
}
`
const subStr = 'lineTo(3, 4)'
const lineToSubstringIndex = code.indexOf(subStr)
const sourceRange: [number, number] = [lineToSubstringIndex, lineToSubstringIndex + subStr.length]
const subStr = 'lineTo(3, 4)'
const lineToSubstringIndex = code.indexOf(subStr)
const sourceRange: [number, number] = [
lineToSubstringIndex,
lineToSubstringIndex + subStr.length,
]
const ast = abstractSyntaxTree(lexer(code))
const nodePath = getNodePathFromSourceRange(ast, sourceRange)
const node = getNodeFromPath(ast, nodePath)
const ast = abstractSyntaxTree(lexer(code))
const nodePath = getNodePathFromSourceRange(ast, sourceRange)
const node = getNodeFromPath(ast, nodePath)
expect([node.start, node.end]).toEqual(sourceRange)
expect(node.type).toBe('CallExpression')
})
expect([node.start, node.end]).toEqual(sourceRange)
expect(node.type).toBe('CallExpression')
})
})