Skip to content

Commit

Permalink
Fixed most test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lvcabral committed Jan 22, 2025
1 parent 397d5d7 commit 4003997
Show file tree
Hide file tree
Showing 26 changed files with 388 additions and 385 deletions.
4 changes: 3 additions & 1 deletion src/LexerParser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as fs from "fs";
import * as path from "path";
import { promisify } from "util";
import pSettle from "p-settle";
const readFile = promisify(fs.readFile);

import { Lexer } from "./lexer";
import { Parser, Stmt } from "./parser/";
Expand Down Expand Up @@ -31,7 +33,7 @@ export function getLexerParserFn(
if (script.uri !== undefined) {
filename = script.uri.replace(/[\/\\]+/g, path.posix.sep);
try {
contents = fs.readFileSync(filename, "utf-8");
contents = await readFile(filename, "utf-8");
} catch (err) {
let errno = (err as NodeJS.ErrnoException)?.errno || -4858;
return Promise.reject({
Expand Down
3 changes: 2 additions & 1 deletion src/brsTypes/components/RoDeviceInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ export class RoDeviceInfo extends BrsComponent implements BrsValue {
returns: ValueKind.Void,
},
impl: (_, port: RoMessagePort) => {
return this.port = port;
this.port = port;
return BrsInvalid.Instance;
},
});

Expand Down
6 changes: 3 additions & 3 deletions src/brsTypes/components/RoSGNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ export class RoSGNode extends BrsComponent implements BrsValue, BrsIterable {
return [
`<Component: ${componentName}> =`,
"{",
...Array.from(this.fields.entries()).reverse().map(
([key, value]) => ` ${key}: ${value.toString(this)}`
),
...Array.from(this.fields.entries())
.reverse()
.map(([key, value]) => ` ${key}: ${value.toString(this)}`),
"}",
].join("\n");
}
Expand Down
3 changes: 2 additions & 1 deletion src/brsTypes/components/RoSGScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export class roSGScreen extends BrsComponent implements BrsValue {
returns: ValueKind.Void,
},
impl: (_, port: RoMessagePort) => {
return this.port = port;
this.port = port;
return BrsInvalid.Instance;
},
});
/** Returns the message port (if any) currently associated with the object */
Expand Down
6 changes: 1 addition & 5 deletions src/brsTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,7 @@ export function isBrsEvent(value: BrsType): value is BrsEvent {
}

// The set of BrightScript Event components
export type BrsEvent =
| RoDeviceInfoEvent
| RoSGNodeEvent
| RoSGScreenEvent;

export type BrsEvent = RoDeviceInfoEvent | RoSGNodeEvent | RoSGScreenEvent;

/**
* The set of all comparable BrightScript types. Only primitive (i.e. intrinsic * and unboxed)
Expand Down
7 changes: 0 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,6 @@ async function loadFiles(options: Partial<ExecutionOptions>) {
}

componentDefinitions.forEach((component: ComponentDefinition) => {
console.log(
`Component: ${component.name?.padEnd(16)} fields: ${
Object.keys(component.fields).length
} scripts: ${component.scripts.length} functions: ${
Object.keys(component.functions).length
} children: ${component.children.length}`
);
if (component.scripts.length < 1) return;
try {
component.scripts = component.scripts.map((script: ComponentScript) => {
Expand Down
1 change: 0 additions & 1 deletion src/interpreter/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class Environment {
/** The node in which field-change observers are registered. */
public hostNode: RoSGNode | undefined;

public nodeName: string = "";
/**
* Stores a `value` for the `name`d variable in the provided `scope`.
* @param scope The logical region from a particular variable or function that defines where it may be accessed from
Expand Down
16 changes: 8 additions & 8 deletions test/brsTypes/components/RoInvalid.test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
const brs = require("../../../lib");
const { RoAssociativeArray, BrsBoolean, BrsInvalid, roInvalid } = brs.types;
const { RoAssociativeArray, BrsBoolean, BrsInvalid, RoInvalid } = brs.types;

describe("RoInvalid", () => {
describe("comparisons", () => {
it("is equal to itself", () => {
let a = new roInvalid();
let a = new RoInvalid();
expect(a.equalTo(a)).toBe(BrsBoolean.True);
});

it("is equal to invalid", () => {
let a = new roInvalid();
let a = new RoInvalid();
expect(a.equalTo(BrsInvalid.Instance)).toBe(BrsBoolean.True);
});

it("is equal to roInvalid", () => {
let a = new roInvalid();
expect(a.equalTo(new roInvalid())).toBe(BrsBoolean.True);
it("is equal to RoInvalid", () => {
let a = new RoInvalid();
expect(a.equalTo(new RoInvalid())).toBe(BrsBoolean.True);
});

it("is not equal to a RoAssocArray", () => {
let a = new roInvalid();
let a = new RoInvalid();
let b = new RoAssociativeArray([]);
expect(a.equalTo(b)).toBe(BrsBoolean.False);
});
});

describe("stringification", () => {
it("stringifies itself", () => {
let a = new roInvalid();
let a = new RoInvalid();
expect(a.toString()).toBe("<Component: roInvalid>");
});
});
Expand Down
34 changes: 22 additions & 12 deletions test/brsTypes/components/RoSGNode.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const brs = require("../../../lib");
const { RoInvalid } = require("../../../lib/brsTypes/components/RoInvalid");
const {
RoAssociativeArray,
RoSGNode,
Expand Down Expand Up @@ -35,16 +36,16 @@ describe("RoSGNode", () => {
expect(node.toString()).toEqual(
`<Component: roSGNode:Node> =
{
number: -1
string: "a string"
boolean: true
node: <Component: roSGNode:Node>
associative-array: <Component: roAssociativeArray>
array: <Component: roArray>
change: <Component: roAssociativeArray>
focusable: false
focusedchild: invalid
focusedchild: <Component: roInvalid>
id: ""
array: <Component: roArray>
associative-array: <Component: roAssociativeArray>
node: <Component: roSGNode:Node>
boolean: true
string: "a string"
number: -1
}`
);
});
Expand Down Expand Up @@ -364,6 +365,9 @@ describe("RoSGNode", () => {
expect(keyValPairs.length).toEqual(expectedValues.length);
expectedValues.forEach((expectedValue, index) => {
let actualValue = keyValPairs[index].get(new BrsString("value"));
if ("unbox" in actualValue) {
actualValue = actualValue.unbox();
}
expect(actualValue).toEqual(expectedValue);
});
});
Expand All @@ -386,6 +390,9 @@ describe("RoSGNode", () => {
expect(keyValPairs.length).toEqual(expectedValues.length);
expectedValues.forEach((expectedValue, index) => {
let actualValue = keyValPairs[index].get(new BrsString("value"));
if ("unbox" in actualValue) {
actualValue = actualValue.unbox();
}
expect(actualValue).toEqual(expectedValue);
});
});
Expand Down Expand Up @@ -536,6 +543,9 @@ describe("RoSGNode", () => {
expect(value.elements).toBeInstanceOf(Map);
expect(value.elements).toEqual(expected.elements.get(name).elements);
} else {
if ("unbox" in value) {
value = value.unbox();
}
expect(value).toEqual(expected.elements.get(name));
}
});
Expand Down Expand Up @@ -2189,8 +2199,8 @@ describe("RoSGNode", () => {
expect(result).toEqual(BrsBoolean.False);

// by default their focusedChild fields should be invalid
expect(child1.get(focusedChildString)).toEqual(BrsInvalid.Instance);
expect(child2.get(focusedChildString)).toEqual(BrsInvalid.Instance);
expect(child1.get(focusedChildString).unbox()).toEqual(BrsInvalid.Instance);
expect(child2.get(focusedChildString).unbox()).toEqual(BrsInvalid.Instance);

//focus on child 1
child1SetFocus.call(interpreter, BrsBoolean.True);
Expand All @@ -2199,7 +2209,7 @@ describe("RoSGNode", () => {
result = child2HasFocus.call(interpreter);
expect(result).toEqual(BrsBoolean.False);
expect(child1.get(focusedChildString)).toEqual(child1);
expect(child2.get(focusedChildString)).toEqual(BrsInvalid.Instance);
expect(child2.get(focusedChildString).unbox()).toEqual(BrsInvalid.Instance);

//focus on child 2 should remove focus from child 1
child2SetFocus.call(interpreter, BrsBoolean.True);
Expand All @@ -2224,7 +2234,7 @@ describe("RoSGNode", () => {
result = child2HasFocus.call(interpreter);
expect(result).toEqual(BrsBoolean.False);
expect(child1.get(focusedChildString)).toEqual(child1);
expect(child2.get(focusedChildString)).toEqual(BrsInvalid.Instance);
expect(child2.get(focusedChildString).unbox()).toEqual(BrsInvalid.Instance);

//set focus to false on child 1
child1SetFocus.call(interpreter, BrsBoolean.False);
Expand All @@ -2233,7 +2243,7 @@ describe("RoSGNode", () => {
result = child2HasFocus.call(interpreter);
expect(result).toEqual(BrsBoolean.False);
expect(child1.get(focusedChildString)).toEqual(BrsInvalid.Instance);
expect(child2.get(focusedChildString)).toEqual(BrsInvalid.Instance);
expect(child2.get(focusedChildString).unbox()).toEqual(BrsInvalid.Instance);
});
});

Expand Down
116 changes: 58 additions & 58 deletions test/brsTypes/nodes/ArrayGrid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,67 @@ describe("ArrayGrid", () => {
expect(group.toString()).toEqual(
`<Component: roSGNode:ArrayGrid> =
{
currfocussection: 0
currfocuscolumn: 0
currfocusrow: 0
animatetoitem: 0
jumptoitem: 0
itemunfocused: 0
itemfocused: 0
itemselected: 0
itemclippingrect: <Component: roArray>
sectiondividerleftoffset: 0
sectiondividerminwidth: 0
sectiondividerheight: 0
sectiondividerwidth: 0
sectiondividerspacing: 0
sectiondividertextcolor: ""
sectiondividerfont: <Component: roInvalid>
sectiondividerbitmapuri: ""
columnspacings: <Component: roArray>
rowspacings: <Component: roArray>
columnwidths: <Component: roArray>
rowheights: <Component: roArray>
numrenderpasses: 1
fixedlayout: false
wrapdividerheight: 36
wrapdividerwidth: 0
wrapdividerbitmapuri: ""
focusfootprintblendcolor: "0xFFFFFFFF"
focusbitmapblendcolor: "0xFFFFFFFF"
focusfootprintbitmapuri: ""
focusbitmapuri: ""
currfocusfeedbackopacity: NaN
fadefocusfeedbackwhenautoscrolling: false
drawfocusfeedback: true
drawfocusfeedbackontop: false
vertfocusanimationstyle: "floatingFocus"
horizfocusanimationstyle: "floatingFocus"
focuscolumn: 0
focusrow: 0
numcolumns: 0
numrows: 0
itemspacing: <Component: roArray>
itemsize: <Component: roArray>
content: <Component: roInvalid>
rendertracking: "disabled"
enablerendertracking: false
muteaudioguide: false
renderpass: 0
clippingrect: <Component: roArray>
inheritparentopacity: true
inheritparenttransform: true
childrenderorder: "renderLast"
scalerotatecenter: <Component: roArray>
scale: <Component: roArray>
rotation: 0
translation: <Component: roArray>
opacity: 1
visible: true
change: <Component: roAssociativeArray>
focusable: false
focusedchild: invalid
focusedchild: <Component: roInvalid>
id: ""
visible: true
opacity: 1
translation: <Component: roArray>
rotation: 0
scale: <Component: roArray>
scalerotatecenter: <Component: roArray>
childrenderorder: "renderLast"
inheritparenttransform: true
inheritparentopacity: true
clippingrect: <Component: roArray>
renderpass: 0
muteaudioguide: false
enablerendertracking: false
rendertracking: "disabled"
content: invalid
itemsize: <Component: roArray>
itemspacing: <Component: roArray>
numrows: 0
numcolumns: 0
focusrow: 0
focuscolumn: 0
horizfocusanimationstyle: "floatingFocus"
vertfocusanimationstyle: "floatingFocus"
drawfocusfeedbackontop: false
drawfocusfeedback: true
fadefocusfeedbackwhenautoscrolling: false
currfocusfeedbackopacity: NaN
focusbitmapuri: ""
focusfootprintbitmapuri: ""
focusbitmapblendcolor: "0xFFFFFFFF"
focusfootprintblendcolor: "0xFFFFFFFF"
wrapdividerbitmapuri: ""
wrapdividerwidth: 0
wrapdividerheight: 36
fixedlayout: false
numrenderpasses: 1
rowheights: <Component: roArray>
columnwidths: <Component: roArray>
rowspacings: <Component: roArray>
columnspacings: <Component: roArray>
sectiondividerbitmapuri: ""
sectiondividerfont: invalid
sectiondividertextcolor: ""
sectiondividerspacing: 0
sectiondividerwidth: 0
sectiondividerheight: 0
sectiondividerminwidth: 0
sectiondividerleftoffset: 0
itemclippingrect: <Component: roArray>
itemselected: 0
itemfocused: 0
itemunfocused: 0
jumptoitem: 0
animatetoitem: 0
currfocusrow: 0
currfocuscolumn: 0
currfocussection: 0
}`
);
});
Expand Down
Loading

0 comments on commit 4003997

Please sign in to comment.