Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into release-0.66.0
  • Loading branch information
TwitchBronBron committed Jul 5, 2023
2 parents 4a6e43c + a2d898b commit 8d02c4d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import * as fsExtra from 'fs-extra';
import { createSandbox } from 'sinon';
import { DiagnosticMessages } from './DiagnosticMessages';
import { tempDir, rootDir } from './testHelpers.spec';
import { Program } from './Program';
import { TypeChainEntry } from './interfaces';
import { ClassType } from './types/ClassType';
import { NamespaceType } from './types/NamespaceType';
import { ClassType } from './types/ClassType';
import { ReferenceType } from './types/ReferenceType';
import { SymbolTypeFlag } from './SymbolTable';

Expand Down Expand Up @@ -43,6 +44,31 @@ describe('util', () => {
});
});

describe('diagnosticIsSuppressed', () => {
it('does not crash when diagnostic is missing location information', () => {
const program = new Program({});
const file = program.setFile('source/main.brs', '');
const diagnostic = {
file: file,
message: 'crash',
//important part of the test. range must be missing
range: undefined
};

file.commentFlags.push({
affectedRange: util.createRange(1, 2, 3, 4),
codes: [1, 2, 3],
file: file,
range: util.createRange(1, 2, 3, 4)
});
file.diagnostics.push(diagnostic);

util.diagnosticIsSuppressed(diagnostic);

//test passes if there's no crash
});
});

describe('getRokuPkgPath', () => {
it('replaces more than one windows slash in a path', () => {
expect(util.getRokuPkgPath('source\\folder1\\folder2\\file.brs')).to.eql('pkg:/source/folder1/folder2/file.brs');
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ export class Util {
const diagnosticCode = typeof diagnostic.code === 'string' ? diagnostic.code.toLowerCase() : diagnostic.code;
for (let flag of diagnostic.file?.commentFlags ?? []) {
//this diagnostic is affected by this flag
if (this.rangeContains(flag.affectedRange, diagnostic.range.start)) {
if (diagnostic.range && this.rangeContains(flag.affectedRange, diagnostic.range.start)) {
//if the flag acts upon this diagnostic's code
if (flag.codes === null || flag.codes.includes(diagnosticCode)) {
return true;
Expand Down

0 comments on commit 8d02c4d

Please sign in to comment.