Skip to content

Commit

Permalink
test changes to match new api
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Jan 18, 2021
1 parent 5ef936f commit 9277689
Show file tree
Hide file tree
Showing 17 changed files with 1,174 additions and 1,223 deletions.
4 changes: 2 additions & 2 deletions src/FunctionScope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('FunctionScope', () => {
expect(variables).to.be.lengthOf(0);
});

it('returns variables defined above the specified line number', async () => {
let file = await program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
it('returns variables defined above the specified line number', () => {
let file = program.addOrReplaceFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
sub main()
var1 = 1
var2 = 2
Expand Down
53 changes: 27 additions & 26 deletions src/LanguageServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,20 @@ describe('LanguageServer', () => {
server.dispose();
});

async function addXmlFile(name: string, additionalXmlContents = '') {
function addXmlFile(name: string, additionalXmlContents = '') {
const filePath = `components/${name}.xml`;

const contents = `<?xml version="1.0" encoding="utf-8"?>
<component name="${name}" extends="Group">
${additionalXmlContents}
<script type="text/brightscript" uri="${name}.brs" />
</component>`;
await program.addOrReplaceFile(filePath, contents);
program.addOrReplaceFile(filePath, contents);
}

async function addScriptFile(name: string, contents: string, extension = 'brs') {
function addScriptFile(name: string, contents: string, extension = 'brs') {
const filePath = s`components/${name}.${extension}`;
await program.addOrReplaceFile(filePath, contents);
program.addOrReplaceFile(filePath, contents);
for (const key in program.files) {
if (key.includes(filePath)) {
const document = TextDocument.create(util.pathToUri(key), 'brightscript', 1, contents);
Expand Down Expand Up @@ -279,6 +279,7 @@ describe('LanguageServer', () => {
'source/**/*'
]
},
getFileContents: sinon.stub().callsFake(() => Promise.resolve('')) as any,
rootDir: rootDir,
program: {
addOrReplaceFile: <any>addOrReplaceFileStub
Expand All @@ -294,7 +295,7 @@ describe('LanguageServer', () => {
pathAbsolute: mainPath
}]);

expect(addOrReplaceFileStub.getCalls()[0].args[0]).to.eql({
expect(addOrReplaceFileStub.getCalls()[0]?.args[0]).to.eql({
src: mainPath,
dest: s`source/main.brs`
});
Expand Down Expand Up @@ -362,7 +363,7 @@ describe('LanguageServer', () => {
program = svr.workspaces[0].builder.program;

const name = `CallComponent`;
callDocument = await addScriptFile(name, `
callDocument = addScriptFile(name, `
sub init()
shouldBuildAwesome = true
if shouldBuildAwesome then
Expand All @@ -372,14 +373,14 @@ describe('LanguageServer', () => {
end if
end sub
`);
await addXmlFile(name, `<script type="text/brightscript" uri="${functionFileBaseName}.bs" />`);
addXmlFile(name, `<script type="text/brightscript" uri="${functionFileBaseName}.bs" />`);
});

it('should return the expected signature info when documentation is included', async () => {
const funcDescriptionComment = '@description Builds awesome for you';
const funcReturnComment = '@return {Integer} The key to everything';

await addScriptFile(functionFileBaseName, `
addScriptFile(functionFileBaseName, `
' /**
' * ${funcDescriptionComment}
' * ${funcReturnComment}
Expand All @@ -403,7 +404,7 @@ describe('LanguageServer', () => {
});

it('should work if used on a property value', async () => {
await addScriptFile(functionFileBaseName, `
addScriptFile(functionFileBaseName, `
${funcDefinitionLine}
return 42
end function
Expand All @@ -422,7 +423,7 @@ describe('LanguageServer', () => {

it('should give the correct signature for a class method', async () => {
const classMethodDefinitionLine = 'function buildAwesome(classVersion = true as Boolean)';
await addScriptFile(functionFileBaseName, `
addScriptFile(functionFileBaseName, `
class ${functionFileBaseName}
${classMethodDefinitionLine}
return 42
Expand Down Expand Up @@ -453,15 +454,15 @@ describe('LanguageServer', () => {
program = svr.workspaces[0].builder.program;

const functionFileBaseName = 'buildAwesome';
functionDocument = await addScriptFile(functionFileBaseName, `
functionDocument = addScriptFile(functionFileBaseName, `
function buildAwesome()
return 42
end function
`);

for (let i = 0; i < 5; i++) {
let name = `CallComponent${i}`;
const document = await addScriptFile(name, `
const document = addScriptFile(name, `
sub init()
shouldBuildAwesome = true
if shouldBuildAwesome then
Expand All @@ -470,7 +471,7 @@ describe('LanguageServer', () => {
end sub
`);

await addXmlFile(name, `<script type="text/brightscript" uri="${functionFileBaseName}.brs" />`);
addXmlFile(name, `<script type="text/brightscript" uri="${functionFileBaseName}.brs" />`);
referenceFileUris.push(document.uri);
}
});
Expand Down Expand Up @@ -521,7 +522,7 @@ describe('LanguageServer', () => {
program = svr.workspaces[0].builder.program;

const functionFileBaseName = 'buildAwesome';
functionDocument = await addScriptFile(functionFileBaseName, `
functionDocument = addScriptFile(functionFileBaseName, `
function pi()
return 3.141592653589793
end function
Expand All @@ -532,7 +533,7 @@ describe('LanguageServer', () => {
`);

const name = `CallComponent`;
referenceDocument = await addScriptFile(name, `
referenceDocument = addScriptFile(name, `
sub init()
shouldBuildAwesome = true
if shouldBuildAwesome then
Expand All @@ -543,7 +544,7 @@ describe('LanguageServer', () => {
end sub
`);

await addXmlFile(name, `<script type="text/brightscript" uri="${functionFileBaseName}.brs" />`);
addXmlFile(name, `<script type="text/brightscript" uri="${functionFileBaseName}.brs" />`);
});

it('should return the expected location if we entered on an identifier token', async () => {
Expand Down Expand Up @@ -605,7 +606,7 @@ describe('LanguageServer', () => {

it('should work for bs class functions as well', async () => {
const functionFileBaseName = 'Build';
functionDocument = await addScriptFile(functionFileBaseName, `
functionDocument = addScriptFile(functionFileBaseName, `
class ${functionFileBaseName}
function awesome()
return 42
Expand All @@ -614,14 +615,14 @@ describe('LanguageServer', () => {
`, 'bs');

const name = `CallComponent`;
referenceDocument = await addScriptFile(name, `
referenceDocument = addScriptFile(name, `
sub init()
build = new Build()
build.awesome()
end sub
`);

await addXmlFile(name, `<script type="text/brightscript" uri="${functionFileBaseName}.bs" />`);
addXmlFile(name, `<script type="text/brightscript" uri="${functionFileBaseName}.bs" />`);

const locations = await svr.onDefinition({
textDocument: {
Expand All @@ -647,7 +648,7 @@ describe('LanguageServer', () => {
});

it('should return the expected symbols even if pulled from cache', async () => {
const document = await addScriptFile('buildAwesome', `
const document = addScriptFile('buildAwesome', `
function pi()
return 3.141592653589793
end function
Expand All @@ -669,7 +670,7 @@ describe('LanguageServer', () => {
});

it('should work for brightscript classes as well', async () => {
const document = await addScriptFile('MyFirstClass', `
const document = addScriptFile('MyFirstClass', `
class MyFirstClass
function pi()
return 3.141592653589793
Expand Down Expand Up @@ -698,7 +699,7 @@ describe('LanguageServer', () => {
});

it('should work for brightscript namespaces as well', async () => {
const document = await addScriptFile('MyFirstNamespace', `
const document = addScriptFile('MyFirstNamespace', `
namespace MyFirstNamespace
function pi()
return 3.141592653589793
Expand Down Expand Up @@ -738,7 +739,7 @@ describe('LanguageServer', () => {
const className = 'MyFirstClass';
const namespaceName = 'MyFirstNamespace';

await addScriptFile('buildAwesome', `
addScriptFile('buildAwesome', `
function pi()
return 3.141592653589793
end function
Expand All @@ -748,7 +749,7 @@ describe('LanguageServer', () => {
end function
`);

await addScriptFile(className, `
addScriptFile(className, `
class ${className}
function ${className}pi()
return 3.141592653589793
Expand All @@ -761,7 +762,7 @@ describe('LanguageServer', () => {
`, 'bs');


await addScriptFile(namespaceName, `
addScriptFile(namespaceName, `
namespace ${namespaceName}
function pi()
return 3.141592653589793
Expand Down Expand Up @@ -810,7 +811,7 @@ describe('LanguageServer', () => {
const nestedNamespace = 'containerNamespace';
const nestedClassName = 'nestedClass';

await addScriptFile('nested', `
addScriptFile('nested', `
namespace ${nestedNamespace}
class ${nestedClassName}
function pi()
Expand Down
Loading

0 comments on commit 9277689

Please sign in to comment.