Test that our runtime implementaiton matches the object definitions we got from the decompiler

Eventually it would be nice to test against std.mi
This commit is contained in:
Jordan Eldredge 2019-08-17 15:12:09 -07:00
parent e4fc867656
commit ef44cff189
5 changed files with 43 additions and 11 deletions

View file

@ -3950,7 +3950,7 @@ Object.values(normalizedObjects).forEach(object => {
object.parentClass = parentClass;
});
function getFormattedId(id) {
export function getFormattedId(id) {
// https://en.wikipedia.org/wiki/Universally_unique_identifier#Encoding
const formattedId = id.replace(
/(........)(....)(....)(..)(..)(..)(..)(..)(..)(..)(..)/,
@ -3959,11 +3959,11 @@ function getFormattedId(id) {
return formattedId.toLowerCase();
}
function getClass(id) {
export function getClass(id) {
return normalizedObjects[getFormattedId(id)];
}
function getObjectFunction(klass, functionName) {
export function getObjectFunction(klass, functionName) {
const method = klass.functions.find(func => {
// TODO: This could probably be normalized at load time, or evern sooner.
return func.name.toLowerCase() === functionName.toLowerCase();
@ -3976,5 +3976,3 @@ function getObjectFunction(klass, functionName) {
}
return getObjectFunction(klass.parentClass, functionName);
}
module.exports = { getClass, getObjectFunction, getFormattedId };

View file

@ -0,0 +1,34 @@
import { getClass } from "./objects";
import runtime from "../runtime";
const getMethods = obj =>
Object.getOwnPropertyNames(obj).filter(name => {
return (
typeof obj[name] === "function" &&
!name.startsWith("js_") &&
name !== "constructor"
);
});
for (let [key, Klass] of Object.entries(runtime)) {
const obj = getClass(key);
describe(`${obj.name}`, () => {
test("implements getclassname()", () => {
expect(Klass.prototype.getclassname()).toBe(obj.name);
});
/*
test("implements all methods", () => {
const methods = getMethods(Klass.prototype);
console.log(methods);
});
*/
test("has the correct parent", () => {
const Parent = Object.getPrototypeOf(Klass);
if (Klass.prototype.getclassname() === "Object") {
expect(Parent.prototype).toBe(undefined);
return;
}
expect(Parent.prototype.getclassname()).toBe(obj.parent);
});
});
}

View file

@ -1,6 +1,6 @@
import Layout from "./Layout";
import Layer from "./Layer";
class AnimatedLayer extends Layout {
class AnimatedLayer extends Layer {
/**
* getclassname()
*

View file

@ -1,7 +1,7 @@
import GuiObject from "./GuiObject";
import MakiObject from "./MakiObject";
import { findDescendantByTypeAndId } from "../utils";
class Container extends GuiObject {
class Container extends MakiObject {
/**
* getclassname()
*

View file

@ -1,7 +1,7 @@
import GuiObject from "./GuiObject";
import Group from "./Group";
import { findParentNodeOfType } from "../utils";
class Layout extends GuiObject {
class Layout extends Group {
/**
* getclassname()
*