Files
plainleaf/plug-api/lib/query_expression.test.ts
T
MaksandGitHub 8a3782e946 improve dependency management (#770)
* use import_map.json instead of per-file import

* remove test_deps.ts in favor of import_map

* remove common/deps.ts in favor of import_map

* use import_map instead of server/deps.ts

* make all plug-api files usable without an import_map

* make all lib files usable without an import_map

* remove web/deps.ts in favor of import_map

* fix plug build

* remove plug-api/deps.ts in favor of lib/deps.ts

* fix server deps bundled in client deps
2024-03-16 15:29:24 +01:00

46 lines
1.0 KiB
TypeScript

import { evalQueryExpression } from "$sb/lib/query_expression.ts";
import { assert, assertEquals } from "$std/testing/asserts.ts";
Deno.test("Test query expression evaluation", async () => {
assertEquals(
evalQueryExpression(
["+", ["number", 1], ["number", 2]],
{},
{},
{},
),
3,
);
assertEquals(
evalQueryExpression(
["?", [">", ["number", 8], ["number", 3]], ["string", "yes"], [
"string",
"no",
]],
{},
{},
{},
),
"yes",
);
// Only when an expression calls an async function should the result be a
const prom = evalQueryExpression(
["+", ["call", "asyncCall", []], ["number", 2]],
{},
{},
{ asyncCall: () => Promise.resolve(1) },
);
assert(prom instanceof Promise);
assertEquals(await prom, 3);
const nonProm = evalQueryExpression(
["+", ["call", "asyncCall", []], ["number", 2]],
{},
{},
{ asyncCall: () => 1 },
);
assert(!(nonProm instanceof Promise));
assertEquals(nonProm, 3);
});