-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AST child searching functionality. (#695)
- Loading branch information
1 parent
63b53bf
commit 749ea40
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { standardizePath as s, util } from '../util'; | ||
import * as fsExtra from 'fs-extra'; | ||
import { Program } from '../Program'; | ||
import type { BrsFile } from '../files/BrsFile'; | ||
import { expect } from 'chai'; | ||
import type { DottedGetExpression } from './Expression'; | ||
import { expectZeroDiagnostics } from '../testHelpers.spec'; | ||
|
||
let tempDir = s`${process.cwd()}/.tmp`; | ||
let rootDir = s`${tempDir}/rootDir`; | ||
let stagingDir = s`${tempDir}/staging`; | ||
|
||
describe('Program', () => { | ||
let program: Program; | ||
|
||
beforeEach(() => { | ||
fsExtra.emptyDirSync(tempDir); | ||
program = new Program({ | ||
rootDir: rootDir, | ||
stagingFolderPath: stagingDir | ||
}); | ||
program.createSourceScope(); //ensure source scope is created | ||
}); | ||
afterEach(() => { | ||
fsExtra.emptyDirSync(tempDir); | ||
program.dispose(); | ||
}); | ||
|
||
describe('AstNode', () => { | ||
describe('findNodeAtPosition', () => { | ||
it('finds deepest AstNode that matches the position', () => { | ||
const file = program.setFile<BrsFile>('source/main.brs', ` | ||
sub main() | ||
alpha = invalid | ||
print alpha.beta.charlie.delta(alpha.echo.foxtrot()) | ||
end sub | ||
`); | ||
program.validate(); | ||
expectZeroDiagnostics(program); | ||
const delta = file.ast.findChildAtPosition<DottedGetExpression>(util.createPosition(3, 52)); | ||
expect(delta.name.text).to.eql('delta'); | ||
|
||
const foxtrot = file.ast.findChildAtPosition<DottedGetExpression>(util.createPosition(3, 71)); | ||
expect(foxtrot.name.text).to.eql('foxtrot'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters