Skip to content

Commit

Permalink
Fix Substance AST queries test
Browse files Browse the repository at this point in the history
  • Loading branch information
samestep committed May 11, 2022
1 parent 9eb147d commit a82da0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/analysis/SubstanceAnalysis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
} from "compiler/Substance";
import { dummyIdentifier } from "engine/EngineUtils";
import { intersectionWith } from "lodash";
import { similarMappings, similarNodes } from "synthesis/Search";
import { A, ASTNode } from "types/ast";
import { similarMappings, similarNodes, SubNode } from "synthesis/Search";
import { A } from "types/ast";
import { Env } from "types/domain";
import { SubProg, SubStmt } from "types/substance";
import {
Expand All @@ -33,8 +33,8 @@ const compile = (src: string): SubProg<A> =>

describe("Substance AST queries", () => {
test("Similar AST nodes", () => {
let node1: ASTNode<A>;
let node2: ASTNode<A>;
let node1: SubNode<A>;
let node2: SubNode<A>;
node1 = compile("Set A");
node2 = compile("Set B");
expect(similarNodes(node1, node2)).toBe(true);
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/synthesis/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ export const diffSubStmts = (
return exactDiffs.map((d) => toStmtDiff(d, leftSorted));
};

type SubNode<T> = LabelOption<T> | SubExpr<T> | SubStmt<T> | Type<T>;
export type SubNode<T> =
| LabelOption<T>
| SubExpr<T>
| SubProg<T>
| SubStmt<T>
| Type<T>;

const children = <T>(node: SubNode<T>): SubNode<T>[] => {
switch (node.tag) {
Expand Down Expand Up @@ -158,6 +163,9 @@ const children = <T>(node: SubNode<T>): SubNode<T>[] => {
case "NoLabel": {
return [...node.args];
}
case "SubProg": {
return [...node.statements];
}
case "TypeVar": {
return [node.name];
}
Expand Down

0 comments on commit a82da0f

Please sign in to comment.