Add JS Linting

This commit is contained in:
Nick Gerleman
2022-12-24 01:46:20 -08:00
parent 014986e9da
commit 4d17e309d2
47 changed files with 1447 additions and 561 deletions

View File

@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
it("dirtied", function() {
test("dirtied", function () {
const root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100);
@@ -14,28 +14,26 @@ it("dirtied", function() {
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
let dirtied = 0;
root.setDirtiedFunc(function() { dirtied++; });
root.setDirtiedFunc(function () {
dirtied++;
});
// only nodes with a measure function can be marked dirty
root.setMeasureFunc(function() {});
root.setMeasureFunc(function () {});
console.assert(0 === dirtied, "0 === dirtied");
expect(dirtied).toBe(0);
// dirtied func MUST be called in case of explicit dirtying.
root.markDirty();
console.assert(1 === dirtied, "1 === dirtied");
expect(dirtied).toBe(1);
// dirtied func MUST be called ONCE.
root.markDirty();
console.assert(1 === dirtied, "1 === dirtied");
expect(dirtied).toBe(1);
if (typeof root !== "undefined")
root.freeRecursive();
typeof gc !== "undefined" && gc();
// TODO Add event support in js and check instace allocation and de allocation using that
root.freeRecursive();
});
it("dirtied_propagation", function() {
test("dirtied_propagation", function () {
const root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100);
@@ -45,7 +43,7 @@ it("dirtied_propagation", function() {
root_child0.setAlignItems(Yoga.ALIGN_FLEX_START);
root_child0.setWidth(50);
root_child0.setHeight(20);
root_child0.setMeasureFunc(function() {});
root_child0.setMeasureFunc(function () {});
root.insertChild(root_child0, 0);
const root_child1 = Yoga.Node.create();
@@ -57,91 +55,85 @@ it("dirtied_propagation", function() {
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
let dirtied = 0;
root.setDirtiedFunc(function() { dirtied++; });
console.assert(0 === dirtied, "0 === dirtied");
// dirtied func MUST be called for the first time.
root_child0.markDirty();
console.assert(1 === dirtied, "1 === dirtied");
// dirtied func must NOT be called for the second time.
root_child0.markDirty();
console.assert(1 === dirtied, "1 === dirtied");
if (typeof root !== "undefined")
root.freeRecursive();
typeof gc !== "undefined" && gc();
// TODO Add event support in js and check instace allocation and de allocation using that
});
it("dirtied_hierarchy", function() {
const root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100);
root.setHeight(100);
const root_child0 = Yoga.Node.create();
root_child0.setAlignItems(Yoga.ALIGN_FLEX_START);
root_child0.setWidth(50);
root_child0.setHeight(20);
root_child0.setMeasureFunc(function() {});
root.insertChild(root_child0, 0);
const root_child1 = Yoga.Node.create();
root_child1.setAlignItems(Yoga.ALIGN_FLEX_START);
root_child1.setWidth(50);
root_child1.setHeight(20);
root_child1.setMeasureFunc(function() {});
root.insertChild(root_child1, 0);
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
let dirtied = 0;
root_child0.setDirtiedFunc(function() {
root.setDirtiedFunc(function () {
dirtied++;
});
console.assert(0 === dirtied, "0 === dirtied");
expect(dirtied).toBe(0);
// dirtied func MUST be called for the first time.
root_child0.markDirty();
expect(dirtied).toBe(1);
// dirtied func must NOT be called for the second time.
root_child0.markDirty();
expect(dirtied).toBe(1);
root.freeRecursive();
});
test("dirtied_hierarchy", function () {
const root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100);
root.setHeight(100);
const root_child0 = Yoga.Node.create();
root_child0.setAlignItems(Yoga.ALIGN_FLEX_START);
root_child0.setWidth(50);
root_child0.setHeight(20);
root_child0.setMeasureFunc(function () {});
root.insertChild(root_child0, 0);
const root_child1 = Yoga.Node.create();
root_child1.setAlignItems(Yoga.ALIGN_FLEX_START);
root_child1.setWidth(50);
root_child1.setHeight(20);
root_child1.setMeasureFunc(function () {});
root.insertChild(root_child1, 0);
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
let dirtied = 0;
root_child0.setDirtiedFunc(function () {
dirtied++;
});
expect(dirtied).toBe(0);
// dirtied func must NOT be called for descendants.
// NOTE: nodes without a measure function cannot be marked dirty manually,
// but nodes with a measure function can not have children.
// Update the width to dirty the node instead.
root.setWidth(110);
console.assert(0 === dirtied, "0 === dirtied");
expect(dirtied).toBe(0);
// dirtied func MUST be called in case of explicit dirtying.
root_child0.markDirty();
console.assert(1 === dirtied, "1 === dirtied");
expect(dirtied).toBe(1);
if (typeof root !== "undefined")
root.freeRecursive();
typeof gc !== "undefined" && gc();
// TODO Add event support in js and check instace allocation and de allocation using that
root.freeRecursive();
});
it("dirtied_reset", function() {
test("dirtied_reset", function () {
const root = Yoga.Node.create();
root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100);
root.setHeight(100);
root.setMeasureFunc(function() {});
root.setMeasureFunc(function () {});
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
let dirtied = 0;
root.setDirtiedFunc(function() {
root.setDirtiedFunc(function () {
dirtied++;
});
console.assert(0 === dirtied, "0 === dirtied");
expect(dirtied).toBe(0);
// dirtied func MUST be called in case of explicit dirtying.
root.markDirty();
console.assert(1 === dirtied, "1 === dirtied");
expect(dirtied).toBe(1);
// recalculate so the root is no longer dirty
root.calculateLayout(undefined, undefined, Yoga.DIRECTION_LTR);
@@ -150,17 +142,13 @@ it("dirtied_reset", function() {
root.setAlignItems(Yoga.ALIGN_FLEX_START);
root.setWidth(100);
root.setHeight(100);
root.setMeasureFunc(function() {});
root.setMeasureFunc(function () {});
root.markDirty();
// dirtied func must NOT be called after reset.
root.markDirty();
console.assert(1 === dirtied, "1 === dirtied");
expect(dirtied).toBe(1);
if (typeof root !== "undefined")
root.freeRecursive();
typeof gc !== "undefined" && gc();
// TODO Add event support in js and check instace allocation and de allocation using that
root.freeRecursive();
});