mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 05:28:41 +00:00
test: evaluate
This commit is contained in:
parent
81b6dede03
commit
9120affd7f
@ -1,9 +1,12 @@
|
|||||||
import shapeshifter from './shapeshifter.mjs';
|
import shapeshifter from './shapeshifter.mjs';
|
||||||
|
import * as strudel from '@strudel/core';
|
||||||
|
|
||||||
|
const { isPattern } = strudel;
|
||||||
|
|
||||||
export const extend = (...args) => {
|
export const extend = (...args) => {
|
||||||
// TODO: find a way to make args available to eval without adding it to global scope...
|
// TODO: find a way to make args available to eval without adding it to global scope...
|
||||||
// sadly, "with" does not work in strict mode
|
// sadly, "with" does not work in strict mode
|
||||||
Object.assign(window, ...args);
|
Object.assign(globalThis, ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const evaluate = async (code) => {
|
export const evaluate = async (code) => {
|
||||||
|
|||||||
@ -1,9 +1,27 @@
|
|||||||
/* import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import evaluate from '../evaluate.mjs';
|
import { evaluate, extend } from '../evaluate.mjs';
|
||||||
|
import { mini } from '@strudel/mini';
|
||||||
|
import * as strudel from '@strudel/core';
|
||||||
|
|
||||||
|
const { cat } = strudel;
|
||||||
|
|
||||||
|
extend({ mini }, strudel);
|
||||||
|
|
||||||
describe('evaluate', () => {
|
describe('evaluate', () => {
|
||||||
it('Should evaluate simple double quote string', () => {
|
const ev = async (code) => (await evaluate(code)).pattern._firstCycleValues;
|
||||||
assert.deepStrictEqual(evaluate('"c3"'), pure('c3'));
|
it('Should evaluate strudel functions', async () => {
|
||||||
|
assert.deepStrictEqual(await ev("pure('c3')"), ['c3']);
|
||||||
|
assert.deepStrictEqual(await ev('cat(c3)'), ['c3']);
|
||||||
|
assert.deepStrictEqual(await ev('cat(c3, d3)'), ['c3', 'd3']);
|
||||||
|
assert.deepStrictEqual(await ev('slowcat(c3, d3)'), ['c3']);
|
||||||
|
});
|
||||||
|
it('Should be extendable', async () => {
|
||||||
|
extend({ myFunction: (...x) => cat(...x) });
|
||||||
|
assert.deepStrictEqual(await ev('myFunction(c3, d3)'), ['c3', 'd3']);
|
||||||
|
});
|
||||||
|
it('Should evaluate simple double quoted mini notation', async () => {
|
||||||
|
assert.deepStrictEqual(await ev('"c3"'), ['c3']);
|
||||||
|
assert.deepStrictEqual(await ev('"c3 d3"'), ['c3', 'd3']);
|
||||||
|
assert.deepStrictEqual(await ev('"<c3 d3>"'), ['c3']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
Loading…
x
Reference in New Issue
Block a user