import { describe, expect, it } from "vitest"; import { parseData } from "../../src/core/data"; import { runQuery } from "../../src/core/query"; describe("query engine", () => { const root = parseData( '[{"team":"a","n":2},{"team":"a","n":4},{"team":"b","n":9}]', "json", ).root; it("filters groups aggregates sorts and limits", () => { expect( runQuery( root, "SELECT team, COUNT(*) AS count, AVG(n) AS mean WHERE n >= 2 GROUP BY team ORDER BY mean DESC LIMIT 2", "sql", ).rows, ).toEqual([ { team: "b", count: 1, mean: 9 }, { team: "a", count: 2, mean: 3 }, ]); }); it("supports bounded path navigation and filtering", () => { expect(runQuery(root, "$[?(@.n >= 4)].team", "path").value).toEqual([ "a", "b", ]); }); it("rejects unsupported syntax rather than evaluating it", () => { expect(() => runQuery(root, "SELECT eval(n)", "sql")).toThrow( /Invalid SELECT/iu, ); expect(() => runQuery(root, "$..team", "path")).toThrow( /Unsupported path/iu, ); }); });