From 4836f2ccc44a04259b3a964b40ff7eff38eb7dd9 Mon Sep 17 00:00:00 2001 From: Bronley Date: Fri, 12 Feb 2021 22:21:55 -0500 Subject: [PATCH] Add `Roku_Ads()` to global callables for now --- src/globalCallables.spec.ts | 13 +++++++++++++ src/globalCallables.ts | 7 +++++++ src/testHelpers.spec.ts | 4 ++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/globalCallables.spec.ts b/src/globalCallables.spec.ts index 094cacb55..5ae53a38e 100644 --- a/src/globalCallables.spec.ts +++ b/src/globalCallables.spec.ts @@ -1,6 +1,7 @@ import { standardizePath as s } from './util'; import { Program } from './Program'; import { expect } from 'chai'; +import { expectZeroDiagnostics } from './testHelpers.spec'; let tmpPath = s`${process.cwd()}/.tmp`; let rootDir = s`${tmpPath}/rootDir`; @@ -18,6 +19,18 @@ describe('globalCallables', () => { program.dispose(); }); + describe('Roku_ads', () => { + it('exists', () => { + program.addOrReplaceFile('source/main.brs', ` + sub main() + adIface = Roku_Ads() + end sub + `); + program.validate(); + expectZeroDiagnostics(program); + }); + }); + describe('val', () => { it('allows single parameter', () => { program.addOrReplaceFile('source/main.brs', ` diff --git a/src/globalCallables.ts b/src/globalCallables.ts index 7706392a4..2a7f8c2f5 100644 --- a/src/globalCallables.ts +++ b/src/globalCallables.ts @@ -722,6 +722,13 @@ let programStatementFunctions = [ name: 'x', type: new IntegerType() }] + //TODO this is a temporary fix for library imported files. Eventually this should be moved into `Roku_Ads.brs` and handled by the `Library` statement + }, { + name: 'Roku_Ads', + shortDescription: 'The main entry point for instantiating the ad interface. This object manages ad server requests, parses ad structure, schedules and renders ads, and triggers tracking beacons.\n\nThe Roku ad parser/renderer object returned has global scope because it is meant to represent interaction with external resources (the ad server and any tracking services) that have persistence and state independent of the ad rendering within a client application.', + type: new FunctionType(new ObjectType()), + file: globalFile, + params: [] } ] as Callable[]; diff --git a/src/testHelpers.spec.ts b/src/testHelpers.spec.ts index 1e92409a9..f333be092 100644 --- a/src/testHelpers.spec.ts +++ b/src/testHelpers.spec.ts @@ -57,10 +57,10 @@ export function expectZeroDiagnostics(arg: { getDiagnostics(): Array let diagnostics: BsDiagnostic[]; if (Array.isArray(arg)) { diagnostics = arg as BsDiagnostic[]; - } else if ((arg as any).diagnostics) { - diagnostics = (arg as any).diagnostics; } else if ((arg as any).getDiagnostics) { diagnostics = (arg as any).getDiagnostics(); + } else if ((arg as any).diagnostics) { + diagnostics = (arg as any).diagnostics; } else { throw new Error('Cannot derive a list of diagnostics from ' + JSON.stringify(arg)); }