Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
iObject committed Aug 19, 2024
1 parent 04f7d52 commit 0fc3516
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/findNodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import undent from 'undent';

describe('findnode', () => {
let program: Program;
const rootDir = path.join(__dirname, '../.tmp');

beforeEach(() => {
program = new Program({});
program = new Program({rootDir: rootDir});
program.plugins.add(new Plugin());
});

Expand Down Expand Up @@ -167,13 +168,27 @@ describe('findnode', () => {

program.validate();
expect(
program.getDiagnostics().map(x => ({ message: x.message, range: x.range }))
program.getDiagnostics().map(x => ({ message: x.message, range: x.range, relatedInformation: x.relatedInformation }))
).to.eql([{
message: `Unnecessary call to 'm.top.findNode("helloZombieText")'`,
range: util.createRange(2, 36, 2, 69)
range: util.createRange(2, 36, 2, 69),
relatedInformation: [{
message: `In scope 'components/ZombieKeyboard.xml'`,
location: util.createLocation(
util.pathToUri(`${rootDir}/components/ZombieKeyboard.xml`),
util.createRange(4, 31, 4, 46)
)
}]
}, {
message: `Unnecessary call to 'm.top.findNode("helloZombieText")'`,
range: util.createRange(3, 37, 3, 70)
range: util.createRange(3, 37, 3, 70),
relatedInformation: [{
message: `In scope 'components/ZombieKeyboard.xml'`,
location: util.createLocation(
util.pathToUri(`${rootDir}/components/ZombieKeyboard.xml`),
util.createRange(4, 31, 4, 46)
)
}]
}]);
});

Expand Down
2 changes: 1 addition & 1 deletion src/findNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function findChildrenWithIDs(children: Array<SGNode>): Map<string, Range> {
if (children) {
children.forEach(child => {
if (child.id) {
foundIDs.set(child.id, child.attributes.find(x => x.key.text === 'id')?.key.range ?? util.createRange(0, 0, 0, 100));
foundIDs.set(child.id, child.attributes.find(x => x.key.text === 'id')?.value?.range ?? util.createRange(0, 0, 0, 100));
}
const subChildren = findChildrenWithIDs(child.children);
foundIDs = new Map([...foundIDs, ...subChildren]);
Expand Down

0 comments on commit 0fc3516

Please sign in to comment.