mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 14:35:45 +00:00
test(javascript): consolidate semantic graph coverage
This commit is contained in:
1 parent
e2e3881c0e
commit
c77d4261a1
17 files changed
+684
-1098
No files matched your search
@@ -186,48 +186,36 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps assignments in computed methods' parameter defaults in the method", () => {
|
||||
it("keeps assignments with the callable that evaluates them inside computed methods", () => {
|
||||
const graph = graphForJavaScript(`
|
||||
const accel = 0.001; let speed = 6;
|
||||
const obj = { ["tick"](value = (speed = accel)) { return speed; } };
|
||||
const accel = 0.001; let parameterSpeed = 6; let callbackSpeed = 6; let callback;
|
||||
const withDefault = { ["tick"](value = (parameterSpeed = accel)) { return parameterSpeed; } };
|
||||
const withKeyCallback = { [(() => { callbackSpeed = accel; return "tick"; })()]() {} };
|
||||
const withDeferredCallback = { [(callback = () => accel)]() {} };
|
||||
`);
|
||||
const nodes = new Map(graph.nodes.map((node) => [node.node_id, node]));
|
||||
const assignment = graph.relations.find(
|
||||
(edge) => edge.properties.assignment_operator === "=",
|
||||
);
|
||||
expect(assignment).toBeDefined();
|
||||
const source = nodes.get(assignment!.source_node_id);
|
||||
const target = nodes.get(assignment!.target_node_id);
|
||||
expect(source?.function_node_id).toBeTypeOf("string");
|
||||
expect(source?.function_node_id).toBe(target?.function_node_id);
|
||||
});
|
||||
|
||||
it("does not treat a callback body nested in a computed key as a key-time assignment input", () => {
|
||||
const graph = graphForJavaScript(`
|
||||
const accel = 0.001; let callback;
|
||||
const obj = { [(callback = () => accel)]() {} };
|
||||
`);
|
||||
expect(
|
||||
graph.relations.filter(
|
||||
(edge) => edge.properties.assignment_operator !== undefined,
|
||||
),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("retains an assignment owned by a callback inside a computed key", () => {
|
||||
const graph = graphForJavaScript(`
|
||||
const accel = 0.001; let speed = 6;
|
||||
const obj = { [(() => { speed = accel; return "tick"; })()]() {} };
|
||||
`);
|
||||
const nodes = new Map(graph.nodes.map((node) => [node.node_id, node]));
|
||||
const assignment = graph.relations.find(
|
||||
(edge) => edge.properties.assignment_operator === "=",
|
||||
);
|
||||
expect(assignment).toBeDefined();
|
||||
const source = nodes.get(assignment!.source_node_id);
|
||||
const target = nodes.get(assignment!.target_node_id);
|
||||
expect(source?.label).toBe("accel");
|
||||
expect(target?.label).toBe("speed");
|
||||
expect(source?.function_node_id).toBeTypeOf("string");
|
||||
expect(source?.function_node_id).toBe(target?.function_node_id);
|
||||
const assignments = graph.relations
|
||||
.filter(({ properties }) => properties.assignment_operator === "=")
|
||||
.map(({ source_node_id, target_node_id }) => ({
|
||||
source: nodes.get(source_node_id),
|
||||
target: nodes.get(target_node_id),
|
||||
}));
|
||||
expect(assignments.map(({ target }) => target?.label).sort()).toEqual([
|
||||
"callbackSpeed",
|
||||
"parameterSpeed",
|
||||
]);
|
||||
for (const { source, target } of assignments) {
|
||||
expect(source?.label).toBe("accel");
|
||||
const owner = source?.function_node_id;
|
||||
if (owner == null) throw new Error("Expected an assignment owner");
|
||||
expect(target?.function_node_id).toBe(owner);
|
||||
expect(nodes.get(owner)).toMatchObject({
|
||||
kind: "function",
|
||||
identity: {
|
||||
source_range: {
|
||||
start: { line: target?.label === "parameterSpeed" ? 3 : 4 },
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user