24 lines
1001 B
TypeScript
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');
|
|
});
|
|
});
|