From ef44cff189bc713e2b7ba37a9d1ebe6af5a2fba3 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sat, 17 Aug 2019 15:12:09 -0700 Subject: [PATCH] Test that our runtime implementaiton matches the object definitions we got from the decompiler Eventually it would be nice to test against std.mi --- modern/src/maki-interpreter/objects.js | 8 ++--- modern/src/maki-interpreter/objects.test.js | 34 +++++++++++++++++++++ modern/src/runtime/AnimatedLayer.js | 4 +-- modern/src/runtime/Container.js | 4 +-- modern/src/runtime/Layout.js | 4 +-- 5 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 modern/src/maki-interpreter/objects.test.js diff --git a/modern/src/maki-interpreter/objects.js b/modern/src/maki-interpreter/objects.js index c07da629..0a21a83a 100644 --- a/modern/src/maki-interpreter/objects.js +++ b/modern/src/maki-interpreter/objects.js @@ -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 }; diff --git a/modern/src/maki-interpreter/objects.test.js b/modern/src/maki-interpreter/objects.test.js new file mode 100644 index 00000000..c76c77d7 --- /dev/null +++ b/modern/src/maki-interpreter/objects.test.js @@ -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); + }); + }); +} diff --git a/modern/src/runtime/AnimatedLayer.js b/modern/src/runtime/AnimatedLayer.js index 99d4d86d..924e2ade 100644 --- a/modern/src/runtime/AnimatedLayer.js +++ b/modern/src/runtime/AnimatedLayer.js @@ -1,6 +1,6 @@ -import Layout from "./Layout"; +import Layer from "./Layer"; -class AnimatedLayer extends Layout { +class AnimatedLayer extends Layer { /** * getclassname() * diff --git a/modern/src/runtime/Container.js b/modern/src/runtime/Container.js index dc8918d9..855e6a91 100644 --- a/modern/src/runtime/Container.js +++ b/modern/src/runtime/Container.js @@ -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() * diff --git a/modern/src/runtime/Layout.js b/modern/src/runtime/Layout.js index e4b6c707..9b504301 100644 --- a/modern/src/runtime/Layout.js +++ b/modern/src/runtime/Layout.js @@ -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() *