Skip to content

Commit

Permalink
Fix most tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Sep 20, 2022
1 parent 54bfdca commit 6adcd56
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/Program.spec.ts
Expand Up @@ -197,7 +197,7 @@ describe('Program', () => {
const beforeFileParse = sinon.spy();
const afterFileParse = sinon.spy();
const afterFileValidate = sinon.spy();
program.plugins = new PluginInterface([{
program.plugins.add({
name: 'emits events for scope and file creation',
beforeProgramValidate: beforeProgramValidate,
afterProgramValidate: afterProgramValidate,
Expand All @@ -207,7 +207,7 @@ describe('Program', () => {
beforeFileParse: beforeFileParse,
afterFileParse: afterFileParse,
afterFileValidate: afterFileValidate
}], new Logger());
});

let mainPath = s`${rootDir}/source/main.brs`;
//add a new source file
Expand Down
9 changes: 4 additions & 5 deletions src/Program.ts
Expand Up @@ -440,8 +440,7 @@ export class Program {
//add a dependency graph key if missing
file.dependencyGraphKey ??= file.pkgPath.toLowerCase();

//register this file (and its dependencies) with the dependency graph
this.dependencyGraph.addOrReplace(file.dependencyGraphKey, file.dependencies ?? []);
this.assignFile(file);

//register a callback anytime this file's dependencies change
if (typeof file.onDependenciesChanged === 'function') {
Expand All @@ -451,6 +450,9 @@ export class Program {
);
}

//register this file (and its dependencies) with the dependency graph
this.dependencyGraph.addOrReplace(file.dependencyGraphKey, file.dependencies ?? []);

//if this is a `source` file, add it to the source scope's dependency list
if (file.pkgPath.startsWith(startOfSourcePkgPath)) {
this.createSourceScope();
Expand All @@ -466,11 +468,8 @@ export class Program {
//register this compoent now that we have parsed it and know its component name
this.registerComponent(file, scope);
}

this.assignFile(file);
}


return primaryFile;
});
return file as T;
Expand Down
7 changes: 0 additions & 7 deletions src/Scope.spec.ts
Expand Up @@ -295,13 +295,6 @@ describe('Scope', () => {
A_B_C_ga()
end sub
`);
program.setFile('source/main.xml', `
<?xml version="1.0" encoding="UTF-8"?>
<component name="MyComponent" extends="Group">
<script type="text/brightscript" uri="main.brs"/>
<script type="text/brightscript" uri="ns.bs"/>
</component>
`);
program.validate();
expectZeroDiagnostics(program);
});
Expand Down
3 changes: 2 additions & 1 deletion src/XmlScope.ts
Expand Up @@ -2,12 +2,13 @@ import type { Location, Position } from 'vscode-languageserver';
import { Scope } from './Scope';
import { DiagnosticMessages } from './DiagnosticMessages';
import type { XmlFile } from './files/XmlFile';
import type { BscFile, CallableContainerMap, FileReference } from './interfaces';
import type { CallableContainerMap, FileReference } from './interfaces';
import type { Program } from './Program';
import util from './util';
import { isXmlFile } from './astUtils/reflection';
import { SGFieldTypes } from './parser/SGTypes';
import type { SGTag } from './parser/SGTypes';
import type { BscFile } from './files/BscFile';

export class XmlScope extends Scope {
constructor(
Expand Down
1 change: 0 additions & 1 deletion src/bscPlugin/fileProviders/FileProvider.ts
Expand Up @@ -4,7 +4,6 @@ import { BrsFile } from '../../files/BrsFile';
import chalk from 'chalk';
import { LogLevel } from '../../Logger';
import { XmlFile } from '../../files/XmlFile';
import { XmlScope } from '../../XmlScope';
import { util } from '../../util';

export class FileProvider {
Expand Down
19 changes: 6 additions & 13 deletions src/files/BrsFile.spec.ts
Expand Up @@ -2868,7 +2868,6 @@ describe('BrsFile', () => {
});
});


describe('type definitions', () => {
it('only exposes defined functions even if source has more', () => {
//parse the .brs file first so it doesn't know about the typedef
Expand Down Expand Up @@ -3312,23 +3311,17 @@ describe('BrsFile', () => {
});

it('can load an absolute plugin which receives callbacks', () => {
program.plugins = new PluginInterface(
util.loadPlugins(tempDir, [
s`${tempDir}/plugins/${pluginFileName}`
]),
new Logger()
);
for (const plugin of util.loadPlugins(tempDir, [s`${tempDir}/plugins/${pluginFileName}`])) {
program.plugins.add(plugin);
}
const file = program.setFile<any>('source/MAIN.brs', '');
expect(file._customProp).to.exist;
});

it('can load a relative plugin which receives callbacks', () => {
program.plugins = new PluginInterface(
util.loadPlugins(tempDir, [
`./plugins/${pluginFileName}`
]),
new Logger()
);
for (const plugin of util.loadPlugins(tempDir, [`./plugins/${pluginFileName}`])) {
program.plugins.add(plugin);
}
const file = program.setFile<any>('source/MAIN.brs', '');
expect(file._customProp).to.exist;
});
Expand Down
2 changes: 1 addition & 1 deletion src/files/BrsFile.ts
Expand Up @@ -23,7 +23,7 @@ import { BrsTranspileState } from '../parser/BrsTranspileState';
import { Preprocessor } from '../preprocessor/Preprocessor';
import { LogLevel } from '../Logger';
import { serializeError } from 'serialize-error';
import { isCallExpression, isMethodStatement, isClassStatement, isDottedGetExpression, isFunctionExpression, isFunctionStatement, isFunctionType, isLiteralExpression, isNamespaceStatement, isStringType, isVariableExpression, isXmlFile, isImportStatement, isFieldStatement, isEnumStatement, isConstStatement, isBrsFile } from '../astUtils/reflection';
import { isCallExpression, isMethodStatement, isClassStatement, isDottedGetExpression, isFunctionExpression, isFunctionStatement, isFunctionType, isLiteralExpression, isNamespaceStatement, isStringType, isVariableExpression, isImportStatement, isFieldStatement, isEnumStatement, isConstStatement, isBrsFile } from '../astUtils/reflection';
import type { BscType } from '../types/BscType';
import { createVisitor, WalkMode } from '../astUtils/visitors';
import type { DependencyGraph } from '../DependencyGraph';
Expand Down
6 changes: 5 additions & 1 deletion src/files/BscFile.ts
@@ -1,4 +1,4 @@
import type { BsDiagnostic } from '../interfaces';
import type { BsDiagnostic, CommentFlag } from '../interfaces';

export interface BscFile {
/**
Expand Down Expand Up @@ -44,6 +44,10 @@ export interface BscFile {
* TODO do we need this property?
*/
needsTranspiled?: boolean;
/**
* An array of comment-based flags that can be used to suppress diagnostics
*/
commentFlags?: CommentFlag[];
/**
* An array of functions that will be called when this file gets destroyed (i.e. event handler disconnection functions)
*/
Expand Down
6 changes: 3 additions & 3 deletions src/files/XmlFile.spec.ts
Expand Up @@ -1176,7 +1176,7 @@ describe('XmlFile', () => {
expectZeroDiagnostics(program);
});

it('ignores warning from previous line just for the specified code', () => {
it('ignores a specific diagnostic on next line', () => {
//component without a name attribute
program.setFile<XmlFile>('components/file.xml', trim`
<?xml version="1.0" encoding="utf-8" ?>
Expand All @@ -1190,7 +1190,7 @@ describe('XmlFile', () => {
]);
});

it('ignores warning from previous line comment', () => {
it('ignores all warnings from previous line comment', () => {
//component without a name attribute
program.setFile<XmlFile>('components/file.xml', trim`
<?xml version="1.0" encoding="utf-8" ?>
Expand All @@ -1205,7 +1205,7 @@ describe('XmlFile', () => {
//component without a name attribute
program.setFile<XmlFile>('components/file.xml', trim`
<?xml version="1.0" encoding="utf-8" ?>
<component> <!--bs:disable-line 1006-->
<component name="ButtonCustom"> <!--bs:disable-line 1006-->
</component>
`);
program.validate();
Expand Down
14 changes: 6 additions & 8 deletions src/util.ts
Expand Up @@ -729,14 +729,12 @@ export class Util {
*/
public diagnosticIsSuppressed(diagnostic: BsDiagnostic) {
const diagnosticCode = typeof diagnostic.code === 'string' ? diagnostic.code.toLowerCase() : diagnostic.code;
if (isBrsFile(diagnostic.file)) {
for (let flag of diagnostic.file.commentFlags ?? []) {
//this diagnostic is affected by this flag
if (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;
}
for (let flag of diagnostic.file?.commentFlags ?? []) {
//this diagnostic is affected by this flag
if (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 6adcd56

Please sign in to comment.