silphius/app/astride/evaluators/object.test.js
2024-06-22 08:02:23 -05:00

61 lines
1.2 KiB
JavaScript

import {expect, test} from 'vitest';
import evaluate from '@/astride/evaluate.js';
import expression from '@/astride/test/expression.js';
test('evaluates object expression', async () => {
let evaluated;
evaluated = evaluate(await expression(`({
["foo"]: 16,
bar: 32,
'baz': 64,
})`));
expect(evaluated.value)
.to.deep.equal({
foo: 16,
bar: 32,
baz: 64,
});
});
test('evaluates async object expression', async () => {
let evaluated;
evaluated = evaluate(await expression(`({
foo: await 32,
})`));
expect(evaluated.async)
.to.equal(true);
expect(await evaluated.value)
.to.deep.equal({
foo: 32,
});
});
test('evaluates object spread expression', async () => {
let evaluated;
evaluated = evaluate(await expression(`({
foo: 16,
...({bar: 32}),
})`));
expect(evaluated.value)
.to.deep.equal({
foo: 16,
bar: 32,
});
});
test('evaluates async spread expression', async () => {
let evaluated;
evaluated = evaluate(await expression(`({
foo: 16,
...(await {bar: 32}),
})`));
expect(evaluated.async)
.to.equal(true);
expect(await evaluated.value)
.to.deep.equal({
foo: 16,
bar: 32,
});
});