Skip to content

Commit

Permalink
fix(shader-ast): fix typo in isTerm(), add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 8, 2020
1 parent bbe5f73 commit 615c8d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/shader-ast/src/ast/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const RE_MAT = /^mat[234]$/;
* @param t
*/
export const isTerm = (t: any): t is Term<any> =>
isPlainObject(t) && !!t.tag && !t.type;
isPlainObject(t) && !!t.tag && !!t.type;

/**
* Returns true, if given term evaluates to a boolean value.
Expand Down
18 changes: 17 additions & 1 deletion packages/shader-ast/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from "assert";
import { mul, vec2 } from "../src";
import { defn, float, isTerm, mul, ret, TRUE, vec2 } from "../src";

describe("shader-ast", () => {
it("op2 type infer mulvv", () => {
Expand Down Expand Up @@ -54,4 +54,20 @@ describe("shader-ast", () => {
r: { tag: "lit", type: "float", info: undefined, val: 1 },
});
});

it("isTerm", () => {
assert.ok(isTerm({ tag: "lit", type: "float", val: 1 }));
assert.ok(isTerm(float(1)));
assert.ok(!isTerm(null));
assert.ok(!isTerm(undefined));
assert.ok(!isTerm({}));
assert.ok(!isTerm(1));
});

it("defn deps", () => {
const foo = defn("bool", "foo", [], () => [ret(TRUE)]);
const bar = defn("float", "bar", [], () => [ret(float(foo()))]);
assert.equal(bar.deps.length, 1);
assert.equal(bar.deps[0].id, "foo");
});
});

0 comments on commit 615c8d2

Please sign in to comment.