mono/packages/xblox/tests/unit/if-else-engine.test.ts
2026-04-07 19:41:32 +02:00

24 lines
1001 B
TypeScript

import { describe, it, expect } from 'vitest';
import { executeBlock } from '../../src/engine/execute-block.js';
import { blocksFileSchema } from '../../src/schema/blocks-file.js';
import { readFile } from 'node:fs/promises';
import { fixture } from '../test-commons.js';
describe('if / else-if / alternate engine', () => {
it('evaluates else-if branch (negative n)', async () => {
const raw = JSON.parse(await readFile(fixture('if-else.json'), 'utf8'));
const file = blocksFileSchema.parse(raw);
const ctx = Object.assign(Object.create(null), file.context) as object;
expect(await executeBlock(file.roots[0], ctx)).toBe('neg');
});
it('evaluates alternate when no branch matches', async () => {
const raw = JSON.parse(await readFile(fixture('if-else-zero.json'), 'utf8'));
const file = blocksFileSchema.parse(raw);
const ctx = Object.assign(Object.create(null), file.context) as object;
expect(await executeBlock(file.roots[0], ctx)).toBe('zero');
});
});