@elaraai/east-node-std 0.0.1-beta.0 → 0.0.1-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/test.js CHANGED
@@ -3,189 +3,152 @@
3
3
  * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
4
4
  */
5
5
  import assert from "node:assert/strict";
6
+ import util from "node:util";
6
7
  import { test as testNode, describe as describeNode } from "node:test";
7
- import { East, Expr, get_location, NullType, StringType, BlockBuilder, FunctionType } from "@elaraai/east";
8
+ import { writeFileSync, mkdirSync } from "node:fs";
9
+ import { join } from "node:path";
10
+ import { AsyncFunctionType, East, Expr, get_location, IRType, NullType, StringType, toJSONFor } from "@elaraai/east";
8
11
  const { str } = East;
12
+ // Force node test to show full stack traces for easier debugging
13
+ Error.stackTraceLimit = Infinity;
14
+ // Force node to print full objects in console.log output
15
+ util.inspect.defaultOptions.depth = null;
9
16
  /**
10
- * Signals that a test assertion passed.
17
+ * Platform function that indicates a test assertion passed.
11
18
  *
12
- * This platform function is used internally by East test assertions to indicate
13
- * successful validation. When executed in Node.js, it performs no action (the test
14
- * continues normally). Other platform implementations may log or track passes.
15
- *
16
- * This function is primarily used within the {@link Test} assertion helpers rather
17
- * than being called directly in test code.
18
- *
19
- * @returns `null` - Has no meaningful return value
20
- *
21
- * @example
22
- * ```ts
23
- * import { East, NullType } from "@elaraai/east";
24
- * import { Test } from "@elaraai/east-node-std";
25
- *
26
- * // Used internally by Test assertions
27
- * const myTest = East.function([], NullType, $ => {
28
- * // Test.equal internally calls testPass when the assertion succeeds
29
- * $(Test.equal(East.value(42n), 42n));
30
- * });
31
- *
32
- * const compiled = East.compile(myTest.toIR(), Test.Implementation);
33
- * compiled(); // Test passes silently
34
- * ```
35
- *
36
- * @remarks
37
- * - Does not throw or produce output in Node.js implementation
38
- * - Used by all {@link Test} assertion methods to signal success
39
- * - Can be called directly for custom assertion logic
19
+ * This is used by East test code to signal successful assertions.
20
+ * When running in Node.js, this does nothing. Other platforms may log or track passes.
40
21
  */
41
- export const testPass = East.platform("testPass", [], NullType);
22
+ const testPass = East.platform("testPass", [], NullType);
42
23
  /**
43
- * Signals that a test assertion failed with a message.
44
- *
45
- * This platform function is used internally by East test assertions to indicate
46
- * validation failures. When executed in Node.js, it throws an assertion error with
47
- * the provided message, causing the test to fail.
24
+ * Platform function that indicates a test assertion failed.
48
25
  *
49
- * This function is primarily used within the {@link Test} assertion helpers rather
50
- * than being called directly, though it can be used for custom failure conditions.
26
+ * This is used by East test code to signal failed assertions.
27
+ * When running in Node.js, this throws an assertion error.
51
28
  *
52
- * @param message - The error message describing why the assertion failed
53
- * @returns `null` - Never actually returns (throws in implementation)
54
- *
55
- * @throws {AssertionError} Always throws with the provided message (Node.js implementation)
29
+ * @param message - The error message describing the assertion failure
30
+ */
31
+ const testFail = East.platform("testFail", [StringType], NullType);
32
+ /**
33
+ * Platform function that defines a single test case.
56
34
  *
57
- * @example
58
- * ```ts
59
- * import { East, StringType, NullType } from "@elaraai/east";
60
- * import { Test } from "@elaraai/east-node-std";
35
+ * This is used by East test code to define individual tests.
36
+ * When running in Node.js, this runs the test using Node's test runner.
61
37
  *
62
- * // Used internally by Test assertions
63
- * const myTest = East.function([], NullType, $ => {
64
- * // Test.equal internally calls testFail when the assertion fails
65
- * $(Test.equal(East.value(42n), 99n));
66
- * // Throws: "Expected 42 to equal 99 (...)"
67
- * });
68
- * ```
38
+ * @param name - The name of the test
39
+ * @param body - The test body function
40
+ */
41
+ const test = East.asyncPlatform("test", [StringType, AsyncFunctionType([], NullType)], NullType);
42
+ /**
43
+ * Platform function that defines a test suite.
69
44
  *
70
- * @example
71
- * ```ts
72
- * // Direct usage for custom validation
73
- * const validatePositive = East.function([IntegerType], NullType, ($, n) => {
74
- * return n.greater(0n).ifElse(
75
- * _ => Test.pass(),
76
- * _ => Test.fail("Number must be positive")
77
- * );
78
- * });
45
+ * This is used by East test code to group related tests.
46
+ * When running in Node.js, this runs the suite using Node's describe.
79
47
  *
80
- * const compiled = East.compile(validatePositive.toIR(), Test.Implementation);
81
- * compiled(-5n); // Throws: "Number must be positive"
82
- * ```
48
+ * @param name - The name of the test suite
49
+ * @param body - A function that calls test() to define tests
50
+ */
51
+ const describe = East.asyncPlatform("describe", [StringType, AsyncFunctionType([], NullType)], NullType);
52
+ /**
53
+ * Creates a test platform that uses Node.js assertions.
83
54
  *
84
- * @remarks
85
- * - Always throws in Node.js implementation (test fails immediately)
86
- * - Used by all {@link Test} assertion methods to signal failure
87
- * - Accepts location information in message for debugging
55
+ * @returns A platform object with `testPass`, `testFail`, `test`, and `describe` functions
88
56
  */
89
- const testFail = East.platform("testFail", [StringType], NullType);
90
- const test = East.platform("test", [StringType, FunctionType([], NullType, null),], NullType);
91
- const describe = East.platform("describe", [StringType, FunctionType([], NullType, null),], NullType);
92
- export const NodeTestTypes = [
93
- testPass,
94
- testFail,
95
- test,
96
- describe,
97
- ];
98
- export const NodeTest = [
57
+ export const TestImpl = [
99
58
  testPass.implement(() => { }), // Assertion passed - do nothing (test continues)
100
59
  testFail.implement((message) => {
101
60
  // Assertion failed - throw to fail the test
102
61
  assert.fail(message);
103
62
  }),
104
- test.implement((name, body) => {
105
- testNode(name, () => {
106
- body();
107
- });
108
- }),
109
- describe.implement((name, body) => {
110
- describeNode(name, () => {
111
- body();
112
- });
113
- }),
63
+ test.implement((name, body) => testNode(name, async () => { await body(); })),
64
+ describe.implement((name, body) => describeNode(name, async () => { await body(); })),
114
65
  ];
66
+ const IRToJSON = toJSONFor(IRType);
115
67
  /**
116
- * Wrapper around Node.js `describe` that also exports test IR for cross-platform testing.
68
+ * Defines and runs an East test suite using platform functions.
117
69
  *
118
- * This function behaves exactly like Node.js `describe` - it runs all the tests normally.
119
- * Additionally, it creates a single East function that runs all tests in sequence,
120
- * making it easy to export the entire test suite for running in other East implementations.
70
+ * This creates a single East function that calls `describe` and `test` platform functions.
71
+ * The entire suite can be exported as IR and run on any East implementation that provides
72
+ * the test platform (testPass, testFail, test, describe).
121
73
  *
122
- * Supports lifecycle hooks (beforeAll, afterAll, beforeEach, afterEach) as East functions
123
- * to properly set up and tear down resources like database connections.
74
+ * When the `EXPORT_TEST_IR` environment variable is set to a directory path, the IR for
75
+ * each test suite is exported to `<path>/<suite_name>.json`.
124
76
  *
125
77
  * @param suiteName - The name of the test suite
126
78
  * @param builder - A function that receives a `test` function for defining tests
127
- * @param options - Configuration options including platform functions and lifecycle hooks
128
79
  *
129
80
  * @example
130
81
  * ```ts
131
- * // Basic usage with platform functions
132
82
  * describeEast("Array tests", (test) => {
133
83
  * test("addition", $ => {
134
- * $(Test.equal(East.value(1n).add(1n), 2n));
84
+ * $(assertEast.equal(East.value(1n).add(1n), 2n));
135
85
  * });
136
- * }, { platformFns: [] });
86
+ * test("subtraction", $ => {
87
+ * $(assertEast.equal(East.value(2n).subtract(1n), 1n));
88
+ * });
89
+ * });
137
90
  * ```
138
91
  *
139
92
  * @example
140
- * ```ts
141
- * // With database cleanup hooks
142
- * import { SQL } from "@elaraai/east-node-io";
143
- *
144
- * describeEast("Database tests", (test) => {
145
- * test("query users", $ => {
146
- * const conn = $.let(SQL.Postgres.connect(config));
147
- * const result = $.let(SQL.Postgres.query(conn, "SELECT * FROM users", []));
148
- * $(Test.equal(result.rows.length(), 2n));
149
- * });
150
- * }, {
151
- * platformFns: SQL.Postgres.Implementation,
152
- * afterEach: $ => {
153
- * // Close connections even if test fails
154
- * const conn = $.let(SQL.Postgres.connect(config));
155
- * $(SQL.Postgres.close(conn));
156
- * }
157
- * });
93
+ * ```bash
94
+ * # Export test IR to a directory
95
+ * EXPORT_TEST_IR=./test-ir npm test
158
96
  * ```
159
97
  */
160
- export function describeEast(suiteName, builder, options = {}) {
161
- const platformFns = options.platformFns ?? [];
98
+ export function describeEast(suiteName, builder, options) {
162
99
  const tests = [];
163
100
  // Collect all test names and bodies
164
- builder((name, body) => tests.push({ name, body }));
101
+ builder((name, body) => {
102
+ tests.push({ name, body });
103
+ });
165
104
  // Create a single East function that uses describe/test platform functions
166
- const suiteFunction = East.function([], NullType, $ => {
167
- $(describe.call($, suiteName, East.function([], NullType, $ => {
168
- if (options.beforeAll)
169
- $(test.call($, "beforeAll", East.function([], NullType, options.beforeAll)));
105
+ const suiteFunction = East.asyncFunction([], NullType, $ => {
106
+ $(describe.call($, suiteName, East.asyncFunction([], NullType, $ => {
107
+ // beforeAll hook
108
+ if (options?.beforeAll) {
109
+ options.beforeAll($);
110
+ }
170
111
  for (const { name, body } of tests) {
171
- if (options.beforeEach)
172
- $(test.call($, "beforeEach", East.function([], NullType, options.beforeEach)));
173
- $(test.call($, name, East.function([], NullType, body)));
174
- if (options.afterEach)
175
- $(test.call($, "afterEach", East.function([], NullType, options.afterEach)));
112
+ $(test.call($, name, East.asyncFunction([], NullType, $test => {
113
+ // beforeEach hook (inside test body)
114
+ if (options?.beforeEach) {
115
+ options.beforeEach($test);
116
+ }
117
+ // Wrap test body in try-finally so afterEach runs even on failure
118
+ if (options?.afterEach) {
119
+ $test.try(body).finally(options.afterEach);
120
+ }
121
+ else {
122
+ body($test);
123
+ }
124
+ })));
125
+ }
126
+ // afterAll hook
127
+ if (options?.afterAll) {
128
+ options.afterAll($);
176
129
  }
177
- if (options.afterAll)
178
- $(test.call($, "afterAll", East.function([], NullType, options.afterAll)));
179
130
  })));
180
131
  });
181
- const funcs = [...NodeTest, ...platformFns];
182
- if (funcs.some(f => f.type === 'async')) {
183
- suiteFunction.toIR().compileAsync([...NodeTest, ...platformFns]);
132
+ // Auto-export test IR if EXPORT_TEST_IR environment variable is set to a path
133
+ if (process.env.EXPORT_TEST_IR) {
134
+ const outputDir = process.env.EXPORT_TEST_IR;
135
+ try {
136
+ mkdirSync(outputDir, { recursive: true });
137
+ const ir = suiteFunction.toIR();
138
+ const irJSON = IRToJSON(ir.ir);
139
+ const filename = join(outputDir, `${suiteName.replace(/[^a-zA-Z0-9]/g, '_')}.json`);
140
+ writeFileSync(filename, JSON.stringify(irJSON, null, 2));
141
+ console.log(`✓ Exported test IR: ${filename}`);
142
+ }
143
+ catch (err) {
144
+ console.error(`✗ Failed to export test IR for "${suiteName}":`, err);
145
+ }
184
146
  }
185
- else {
186
- suiteFunction.toIR().compile([...NodeTest, ...platformFns]);
147
+ if (options?.exportOnly !== true) {
148
+ // Run the test suite using the Node.js platform implementation
149
+ const compiled = suiteFunction.toIR().compile([...(options?.platformFns ?? [])]);
150
+ return compiled();
187
151
  }
188
- // Run the test suite using the Node.js platform implementation
189
152
  }
190
153
  /**
191
154
  * East assertion functions that match Node.js assert API naming.
@@ -193,58 +156,7 @@ export function describeEast(suiteName, builder, options = {}) {
193
156
  * These functions generate East expressions that perform runtime assertions
194
157
  * using platform functions, enabling testing of East code.
195
158
  */
196
- /**
197
- * East assertion functions that match Node.js assert API naming.
198
- *
199
- * These functions generate East expressions that perform runtime assertions
200
- * using platform functions, enabling testing of East code.
201
- */
202
- export const Test = {
203
- /**
204
- * Platform function that signals a test assertion passed.
205
- *
206
- * Used internally by assertion methods to indicate successful validation.
207
- * Does nothing in Node.js implementation - test continues normally.
208
- *
209
- * @returns An East expression that returns `null`
210
- *
211
- * @example
212
- * ```ts
213
- * import { East, NullType } from "@elaraai/east";
214
- * import { Test } from "@elaraai/east-node-std";
215
- *
216
- * const customAssertion = East.function([], NullType, $ => {
217
- * return East.value(true).ifElse(
218
- * _ => Test.pass(),
219
- * _ => Test.fail("Condition was false")
220
- * );
221
- * });
222
- * ```
223
- */
224
- pass: testPass,
225
- /**
226
- * Platform function that signals a test assertion failed.
227
- *
228
- * Used internally by assertion methods to indicate validation failures.
229
- * Throws an assertion error in Node.js implementation - test fails immediately.
230
- *
231
- * @param message - Error message describing the failure
232
- * @returns An East expression that returns `null` (never actually returns - throws)
233
- *
234
- * @example
235
- * ```ts
236
- * import { East, StringType, NullType } from "@elaraai/east";
237
- * import { Test } from "@elaraai/east-node-std";
238
- *
239
- * const validateRange = East.function([IntegerType], NullType, ($, value) => {
240
- * return value.between(0n, 100n).ifElse(
241
- * _ => Test.pass(),
242
- * _ => Test.fail("Value must be between 0 and 100")
243
- * );
244
- * });
245
- * ```
246
- */
247
- fail: testFail,
159
+ export const Assert = {
248
160
  /**
249
161
  * Asserts that two values are the same reference (meaning if one is mutated, the other reflects the change - and they are always equal).
250
162
  *
@@ -259,7 +171,7 @@ export const Test = {
259
171
  return Expr.tryCatch(Expr.block($ => {
260
172
  const act = $.let(actual);
261
173
  const exp = $.let(expected_expr);
262
- return East.is(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to equal ${exp} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`));
174
+ return East.is(act, exp).ifElse(_$ => testPass(), _$ => testFail(str `Expected ${act} to be ${exp} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`));
263
175
  }), (_$, message, stack) => testFail(East.String.printError(message, stack)));
264
176
  },
265
177
  /**
@@ -403,5 +315,514 @@ export const Test = {
403
315
  }
404
316
  });
405
317
  },
318
+ /**
319
+ * Fails a test with the given message.
320
+ *
321
+ * @param message
322
+ * @returns An East expression that unconditionally fails the test
323
+ */
324
+ fail(message) {
325
+ const location = get_location(2);
326
+ const message_expr = Expr.from(message, StringType);
327
+ return testFail(str `${message_expr} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`);
328
+ }
406
329
  };
330
+ // /**
331
+ // * Copyright (c) 2025 Elara AI Pty Ltd
332
+ // * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
333
+ // */
334
+ // import assert from "node:assert/strict";
335
+ // import { test as testNode, describe as describeNode } from "node:test";
336
+ // import { East, Expr, get_location, NullType, StringType, BlockBuilder, type SubtypeExprOrValue, type ExprType, type EastType, AsyncFunctionType } from "@elaraai/east";
337
+ // import type { PlatformFunction } from "@elaraai/east/internal";
338
+ // const { str } = East;
339
+ // /**
340
+ // * Signals that a test assertion passed.
341
+ // *
342
+ // * This platform function is used internally by East test assertions to indicate
343
+ // * successful validation. When executed in Node.js, it performs no action (the test
344
+ // * continues normally). Other platform implementations may log or track passes.
345
+ // *
346
+ // * This function is primarily used within the {@link Test} assertion helpers rather
347
+ // * than being called directly in test code.
348
+ // *
349
+ // * @returns `null` - Has no meaningful return value
350
+ // *
351
+ // * @example
352
+ // * ```ts
353
+ // * import { East, NullType } from "@elaraai/east";
354
+ // * import { Test } from "@elaraai/east-node-std";
355
+ // *
356
+ // * // Used internally by Test assertions
357
+ // * const myTest = East.function([], NullType, $ => {
358
+ // * // Test.equal internally calls testPass when the assertion succeeds
359
+ // * $(Test.equal(East.value(42n), 42n));
360
+ // * });
361
+ // *
362
+ // * const compiled = East.compile(myTest.toIR(), Test.Implementation);
363
+ // * compiled(); // Test passes silently
364
+ // * ```
365
+ // *
366
+ // * @remarks
367
+ // * - Does not throw or produce output in Node.js implementation
368
+ // * - Used by all {@link Test} assertion methods to signal success
369
+ // * - Can be called directly for custom assertion logic
370
+ // */
371
+ // export const testPass = East.platform("testPass", [], NullType);
372
+ // /**
373
+ // * Signals that a test assertion failed with a message.
374
+ // *
375
+ // * This platform function is used internally by East test assertions to indicate
376
+ // * validation failures. When executed in Node.js, it throws an assertion error with
377
+ // * the provided message, causing the test to fail.
378
+ // *
379
+ // * This function is primarily used within the {@link Test} assertion helpers rather
380
+ // * than being called directly, though it can be used for custom failure conditions.
381
+ // *
382
+ // * @param message - The error message describing why the assertion failed
383
+ // * @returns `null` - Never actually returns (throws in implementation)
384
+ // *
385
+ // * @throws {AssertionError} Always throws with the provided message (Node.js implementation)
386
+ // *
387
+ // * @example
388
+ // * ```ts
389
+ // * import { East, StringType, NullType } from "@elaraai/east";
390
+ // * import { Test } from "@elaraai/east-node-std";
391
+ // *
392
+ // * // Used internally by Test assertions
393
+ // * const myTest = East.function([], NullType, $ => {
394
+ // * // Test.equal internally calls testFail when the assertion fails
395
+ // * $(Test.equal(East.value(42n), 99n));
396
+ // * // Throws: "Expected 42 to equal 99 (...)"
397
+ // * });
398
+ // * ```
399
+ // *
400
+ // * @example
401
+ // * ```ts
402
+ // * // Direct usage for custom validation
403
+ // * const validatePositive = East.function([IntegerType], NullType, ($, n) => {
404
+ // * return n.greater(0n).ifElse(
405
+ // * _ => Test.pass(),
406
+ // * _ => Test.fail("Number must be positive")
407
+ // * );
408
+ // * });
409
+ // *
410
+ // * const compiled = East.compile(validatePositive.toIR(), Test.Implementation);
411
+ // * compiled(-5n); // Throws: "Number must be positive"
412
+ // * ```
413
+ // *
414
+ // * @remarks
415
+ // * - Always throws in Node.js implementation (test fails immediately)
416
+ // * - Used by all {@link Test} assertion methods to signal failure
417
+ // * - Accepts location information in message for debugging
418
+ // */
419
+ // const testFail = East.platform("testFail", [StringType], NullType);
420
+ // const test = East.asyncPlatform("test", [StringType, AsyncFunctionType([], NullType)], NullType);
421
+ // const describe = East.asyncPlatform("describe", [StringType, AsyncFunctionType([], NullType)], NullType);
422
+ // export const NodeTestTypes: any[] = [
423
+ // testPass,
424
+ // testFail,
425
+ // test,
426
+ // describe,
427
+ // ];
428
+ // export const NodeTest: PlatformFunction[] = [
429
+ // testPass.implement(() => { }), // Assertion passed - do nothing (test continues)
430
+ // testFail.implement((message: string) => {
431
+ // // Assertion failed - throw to fail the test
432
+ // assert.fail(message);
433
+ // }),
434
+ // test.implement(async (name: string, body: () => Promise<null>) => {
435
+ // testNode(name, async () => {
436
+ // await body();
437
+ // });
438
+ // }),
439
+ // describe.implement(async (
440
+ // name: string,
441
+ // body: () => Promise<null>,
442
+ // ) => {
443
+ // describeNode(name, async () => {
444
+ // await body();
445
+ // });
446
+ // }),
447
+ // ];
448
+ // /**
449
+ // * Configuration options for East test suites.
450
+ // */
451
+ // export interface DescribeEastOptions {
452
+ // /**
453
+ // * Platform functions to include in all tests and hooks.
454
+ // */
455
+ // platformFns?: PlatformFunction[];
456
+ // /**
457
+ // * Setup function run once before all tests.
458
+ // * Use for opening database connections, initializing resources, etc.
459
+ // */
460
+ // beforeAll?: ($: BlockBuilder<NullType>) => void;
461
+ // /**
462
+ // * Cleanup function run once after all tests.
463
+ // * Use for closing database connections, cleaning up resources, etc.
464
+ // * Runs even if tests fail.
465
+ // */
466
+ // afterAll?: ($: BlockBuilder<NullType>) => void;
467
+ // /**
468
+ // * Setup function run before each test.
469
+ // */
470
+ // beforeEach?: ($: BlockBuilder<NullType>) => void;
471
+ // /**
472
+ // * Cleanup function run after each test.
473
+ // * Runs even if the test fails.
474
+ // */
475
+ // afterEach?: ($: BlockBuilder<NullType>) => void;
476
+ // }
477
+ // /**
478
+ // * Wrapper around Node.js `describe` that also exports test IR for cross-platform testing.
479
+ // *
480
+ // * This function behaves exactly like Node.js `describe` - it runs all the tests normally.
481
+ // * Additionally, it creates a single East function that runs all tests in sequence,
482
+ // * making it easy to export the entire test suite for running in other East implementations.
483
+ // *
484
+ // * Supports lifecycle hooks (beforeAll, afterAll, beforeEach, afterEach) as East functions
485
+ // * to properly set up and tear down resources like database connections.
486
+ // *
487
+ // * @param suiteName - The name of the test suite
488
+ // * @param builder - A function that receives a `test` function for defining tests
489
+ // * @param options - Configuration options including platform functions and lifecycle hooks
490
+ // *
491
+ // * @example
492
+ // * ```ts
493
+ // * // Basic usage with platform functions
494
+ // * describeEast("Array tests", (test) => {
495
+ // * test("addition", $ => {
496
+ // * $(Test.equal(East.value(1n).add(1n), 2n));
497
+ // * });
498
+ // * }, { platformFns: [] });
499
+ // * ```
500
+ // *
501
+ // * @example
502
+ // * ```ts
503
+ // * // With database cleanup hooks
504
+ // * import { SQL } from "@elaraai/east-node-io";
505
+ // *
506
+ // * describeEast("Database tests", (test) => {
507
+ // * test("query users", $ => {
508
+ // * const conn = $.let(SQL.Postgres.connect(config));
509
+ // * const result = $.let(SQL.Postgres.query(conn, "SELECT * FROM users", []));
510
+ // * $(Test.equal(result.rows.length(), 2n));
511
+ // * });
512
+ // * }, {
513
+ // * platformFns: SQL.Postgres.Implementation,
514
+ // * afterEach: $ => {
515
+ // * // Close connections even if test fails
516
+ // * const conn = $.let(SQL.Postgres.connect(config));
517
+ // * $(SQL.Postgres.close(conn));
518
+ // * }
519
+ // * });
520
+ // * ```
521
+ // */
522
+ // export function describeEast(
523
+ // suiteName: string,
524
+ // builder: (test: (name: string, body: ($: BlockBuilder<NullType>) => void) => void) => void,
525
+ // options: DescribeEastOptions = {}
526
+ // ) {
527
+ // const platformFns = options.platformFns ?? [];
528
+ // const tests: Array<{ name: string, body: ($: BlockBuilder<NullType>) => void }> = [];
529
+ // // Collect all test names and bodies
530
+ // builder((name: string, body: ($: BlockBuilder<NullType>) => void) => tests.push({ name, body }));
531
+ // // Create a single East function that uses describe/test platform functions
532
+ // const suiteFunction = East.asyncFunction([], NullType, $ => {
533
+ // $(describe.call(
534
+ // $,
535
+ // suiteName,
536
+ // East.asyncFunction([], NullType, $ => {
537
+ // if (options.beforeAll) $(test.call($, "beforeAll", East.asyncFunction([], NullType, options.beforeAll)));
538
+ // for (const { name, body } of tests) {
539
+ // if (options.beforeEach) $(test.call($, "beforeEach", East.asyncFunction([], NullType, options.beforeEach)));
540
+ // $(test.call($, name, East.asyncFunction([], NullType, body)));
541
+ // if (options.afterEach) $(test.call($, "afterEach", East.asyncFunction([], NullType, options.afterEach)));
542
+ // }
543
+ // if (options.afterAll) $(test.call($, "afterAll", East.asyncFunction([], NullType, options.afterAll)));
544
+ // }),
545
+ // ));
546
+ // });
547
+ // const funcs = [...NodeTest, ...platformFns]
548
+ // if(funcs.some(f => f.type === 'async')) {
549
+ // suiteFunction.toIR().compile([...NodeTest, ...platformFns]);
550
+ // } else {
551
+ // suiteFunction.toIR().compile([...NodeTest, ...platformFns]);
552
+ // }
553
+ // // Run the test suite using the Node.js platform implementation
554
+ // }
555
+ // /**
556
+ // * East assertion functions that match Node.js assert API naming.
557
+ // *
558
+ // * These functions generate East expressions that perform runtime assertions
559
+ // * using platform functions, enabling testing of East code.
560
+ // */
561
+ // /**
562
+ // * East assertion functions that match Node.js assert API naming.
563
+ // *
564
+ // * These functions generate East expressions that perform runtime assertions
565
+ // * using platform functions, enabling testing of East code.
566
+ // */
567
+ // export const Test = {
568
+ // /**
569
+ // * Platform function that signals a test assertion passed.
570
+ // *
571
+ // * Used internally by assertion methods to indicate successful validation.
572
+ // * Does nothing in Node.js implementation - test continues normally.
573
+ // *
574
+ // * @returns An East expression that returns `null`
575
+ // *
576
+ // * @example
577
+ // * ```ts
578
+ // * import { East, NullType } from "@elaraai/east";
579
+ // * import { Test } from "@elaraai/east-node-std";
580
+ // *
581
+ // * const customAssertion = East.function([], NullType, $ => {
582
+ // * return East.value(true).ifElse(
583
+ // * _ => Test.pass(),
584
+ // * _ => Test.fail("Condition was false")
585
+ // * );
586
+ // * });
587
+ // * ```
588
+ // */
589
+ // pass: testPass,
590
+ // /**
591
+ // * Platform function that signals a test assertion failed.
592
+ // *
593
+ // * Used internally by assertion methods to indicate validation failures.
594
+ // * Throws an assertion error in Node.js implementation - test fails immediately.
595
+ // *
596
+ // * @param message - Error message describing the failure
597
+ // * @returns An East expression that returns `null` (never actually returns - throws)
598
+ // *
599
+ // * @example
600
+ // * ```ts
601
+ // * import { East, StringType, NullType } from "@elaraai/east";
602
+ // * import { Test } from "@elaraai/east-node-std";
603
+ // *
604
+ // * const validateRange = East.function([IntegerType], NullType, ($, value) => {
605
+ // * return value.between(0n, 100n).ifElse(
606
+ // * _ => Test.pass(),
607
+ // * _ => Test.fail("Value must be between 0 and 100")
608
+ // * );
609
+ // * });
610
+ // * ```
611
+ // */
612
+ // fail: testFail,
613
+ // /**
614
+ // * Asserts that two values are the same reference (meaning if one is mutated, the other reflects the change - and they are always equal).
615
+ // *
616
+ // * @typeParam E - The type of the actual expression
617
+ // * @param actual - The actual value to test
618
+ // * @param expected - The expected value to compare against
619
+ // * @returns An East expression that performs the equality check
620
+ // */
621
+ // is<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
622
+ // const location = get_location(2);
623
+ // const expected_expr = Expr.from(expected, Expr.type(actual));
624
+ // return Expr.tryCatch(
625
+ // Expr.block($ => {
626
+ // const act = $.let(actual);
627
+ // const exp = $.let(expected_expr);
628
+ // return East.is(act as any, exp as any).ifElse(
629
+ // _$ => testPass(),
630
+ // _$ => testFail(str`Expected ${act} to equal ${exp} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`)
631
+ // );
632
+ // }),
633
+ // (_$, message, stack) => testFail(East.String.printError(message, stack))
634
+ // );
635
+ // },
636
+ // /**
637
+ // * Asserts that two values are equal.
638
+ // *
639
+ // * @typeParam E - The type of the actual expression
640
+ // * @param actual - The actual value to test
641
+ // * @param expected - The expected value to compare against
642
+ // * @returns An East expression that performs the equality check
643
+ // */
644
+ // equal<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
645
+ // const location = get_location(2);
646
+ // const expected_expr = Expr.from(expected, Expr.type(actual));
647
+ // return Expr.tryCatch(
648
+ // Expr.block($ => {
649
+ // const act = $.let(actual);
650
+ // const exp = $.let(expected_expr);
651
+ // return East.equal(act as any, exp as any).ifElse(
652
+ // _$ => testPass(),
653
+ // _$ => testFail(str`Expected ${act} to equal ${exp} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`)
654
+ // );
655
+ // }),
656
+ // (_$, message, stack) => testFail(East.String.printError(message, stack))
657
+ // );
658
+ // },
659
+ // /**
660
+ // * Asserts that two values are not equal.
661
+ // *
662
+ // * @typeParam E - The type of the actual expression
663
+ // * @param actual - The actual value to test
664
+ // * @param expected - The value that should not be equal
665
+ // * @returns An East expression that performs the inequality check
666
+ // */
667
+ // notEqual<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
668
+ // const location = get_location(2);
669
+ // const expected_expr = Expr.from(expected, Expr.type(actual));
670
+ // return Expr.tryCatch(
671
+ // Expr.block($ => {
672
+ // const act = $.let(actual);
673
+ // const exp = $.let(expected_expr);
674
+ // return East.notEqual(act as any, exp as any).ifElse(
675
+ // _$ => testPass(),
676
+ // _$ => testFail(str`Expected ${act} to not equal ${exp} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`)
677
+ // );
678
+ // }),
679
+ // (_$, message, stack) => testFail(East.String.printError(message, stack))
680
+ // );
681
+ // },
682
+ // /**
683
+ // * Asserts that actual is less than expected.
684
+ // *
685
+ // * @typeParam E - The type of the actual expression
686
+ // * @param actual - The actual value to test
687
+ // * @param expected - The value that actual should be less than
688
+ // * @returns An East expression that performs the less-than check
689
+ // */
690
+ // less<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
691
+ // const location = get_location(2);
692
+ // const expected_expr = Expr.from(expected, Expr.type(actual));
693
+ // return Expr.tryCatch(
694
+ // Expr.block($ => {
695
+ // const act = $.let(actual);
696
+ // const exp = $.let(expected_expr);
697
+ // return East.less(act as any, exp as any).ifElse(
698
+ // _$ => testPass(),
699
+ // _$ => testFail(str`Expected ${act} to be less than ${exp} (${`${location.filename} ${location.line}:${location.column}`})`)
700
+ // );
701
+ // }),
702
+ // (_$, message, stack) => testFail(East.String.printError(message, stack))
703
+ // );
704
+ // },
705
+ // /**
706
+ // * Asserts that actual is less than or equal to expected.
707
+ // *
708
+ // * @typeParam E - The type of the actual expression
709
+ // * @param actual - The actual value to test
710
+ // * @param expected - The value that actual should be less than or equal to
711
+ // * @returns An East expression that performs the less-than-or-equal check
712
+ // */
713
+ // lessEqual<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
714
+ // const location = get_location(2);
715
+ // const expected_expr = Expr.from(expected, Expr.type(actual));
716
+ // return Expr.tryCatch(
717
+ // Expr.block($ => {
718
+ // const act = $.let(actual);
719
+ // const exp = $.let(expected_expr);
720
+ // return East.lessEqual(act as any, exp as any).ifElse(
721
+ // _$ => testPass(),
722
+ // _$ => testFail(str`Expected ${act} to be less than or equal to ${exp} (${`${location.filename} ${location.line}:${location.column}`})`)
723
+ // );
724
+ // }),
725
+ // (_$, message, stack) => testFail(East.String.printError(message, stack))
726
+ // );
727
+ // },
728
+ // /**
729
+ // * Asserts that actual is greater than expected.
730
+ // *
731
+ // * @typeParam E - The type of the actual expression
732
+ // * @param actual - The actual value to test
733
+ // * @param expected - The value that actual should be greater than
734
+ // * @returns An East expression that performs the greater-than check
735
+ // */
736
+ // greater<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
737
+ // const location = get_location(2);
738
+ // const expected_expr = Expr.from(expected, Expr.type(actual));
739
+ // return Expr.tryCatch(
740
+ // Expr.block($ => {
741
+ // const act = $.let(actual);
742
+ // const exp = $.let(expected_expr);
743
+ // return East.greater(act as any, exp as any).ifElse(
744
+ // _$ => testPass(),
745
+ // _$ => testFail(str`Expected ${act} to be greater than ${exp} (${`${location.filename} ${location.line}:${location.column}`})`)
746
+ // );
747
+ // }),
748
+ // (_$, message, stack) => testFail(East.String.printError(message, stack))
749
+ // );
750
+ // },
751
+ // /**
752
+ // * Asserts that actual is greater than or equal to expected.
753
+ // *
754
+ // * @typeParam E - The type of the actual expression
755
+ // * @param actual - The actual value to test
756
+ // * @param expected - The value that actual should be greater than or equal to
757
+ // * @returns An East expression that performs the greater-than-or-equal check
758
+ // */
759
+ // greaterEqual<E extends EastType>(actual: Expr<E>, expected: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
760
+ // const location = get_location(2);
761
+ // const expected_expr = Expr.from(expected, Expr.type(actual));
762
+ // return Expr.tryCatch(
763
+ // Expr.block($ => {
764
+ // const act = $.let(actual);
765
+ // const exp = $.let(expected_expr);
766
+ // return East.greaterEqual(act as any, exp as any).ifElse(
767
+ // _$ => testPass(),
768
+ // _$ => testFail(str`Expected ${act} to be greater than or equal to ${exp} (${`${location.filename} ${location.line}:${location.column}`})`)
769
+ // );
770
+ // }),
771
+ // (_$, message, stack) => testFail(East.String.printError(message, stack))
772
+ // );
773
+ // },
774
+ // /**
775
+ // * Asserts that actual is between min and max (inclusive).
776
+ // *
777
+ // * @typeParam E - The type of the actual expression
778
+ // * @param actual - The actual value to test
779
+ // * @param min - The minimum value (inclusive)
780
+ // * @param max - The maximum value (inclusive)
781
+ // * @returns An East expression that performs the range check
782
+ // */
783
+ // between<E extends EastType>(actual: Expr<E>, min: SubtypeExprOrValue<NoInfer<E>>, max: SubtypeExprOrValue<NoInfer<E>>): ExprType<NullType> {
784
+ // const location = get_location(2);
785
+ // const min_expr = Expr.from(min, Expr.type(actual));
786
+ // const max_expr = Expr.from(max, Expr.type(actual));
787
+ // return Expr.tryCatch(
788
+ // East.greaterEqual(actual, min_expr as any).ifElse(
789
+ // _$ => East.lessEqual(actual, max_expr as any).ifElse(
790
+ // _$ => testPass(),
791
+ // _$ => testFail(str`Expected ${actual} to be less than or equal to ${max_expr} (${`${location.filename} ${location.line}:${location.column}`})`)
792
+ // ),
793
+ // _$ => testFail(str`Expected ${actual} to be greater than or equal to ${min_expr}`)
794
+ // ),
795
+ // (_$, message, stack) => testFail(East.String.printError(message, stack))
796
+ // );
797
+ // },
798
+ // /**
799
+ // * Asserts that an expression throws an error.
800
+ // *
801
+ // * @param fn - The expression that should throw an error when evaluated
802
+ // * @param pattern - Optional regex pattern to match against the error message
803
+ // * @returns An East expression that verifies an error is thrown
804
+ // */
805
+ // throws(fn: Expr<any>, pattern?: RegExp): ExprType<NullType> {
806
+ // const location = get_location(2);
807
+ // return Expr.tryCatch(
808
+ // Expr.block($ => {
809
+ // const result = $.let(fn);
810
+ // $(testFail(str`Expected error, got ${result} (${East.value(`${location.filename} ${location.line}:${location.column}`)})`));
811
+ // return null;
812
+ // }),
813
+ // ($, message, stack) => {
814
+ // if (pattern) {
815
+ // // Validate error message matches the pattern
816
+ // return message.contains(pattern).ifElse(
817
+ // _$ => testPass(),
818
+ // _$ => testFail(str`Expected error message to match ${East.value(pattern.source)}, but got: ${East.String.printError(message, stack)}`)
819
+ // );
820
+ // } else {
821
+ // // Just verify it threw
822
+ // return testPass();
823
+ // }
824
+ // }
825
+ // );
826
+ // },
827
+ // };
407
828
  //# sourceMappingURL=test.js.map