chore: test scopes

This commit is contained in:
cha0s 2024-06-22 04:05:18 -05:00
parent c7cb1b6876
commit 1a908bc0af

View File

@ -32,6 +32,30 @@ test('declares variables', async () => {
});
});
test('scopes variables', async () => {
const sandbox = new Sandbox(
await parse(`
const result = [];
const scalar = 1;
result.push(scalar);
{
const scalar = 2;
result.push(scalar);
}
result.push(scalar);
`),
);
let result;
do {
result = sandbox.step();
if (result.value?.async) {
await result.value.async;
}
} while (!result.done);
expect(sandbox.context.result)
.to.deep.equal([1, 2, 1]);
});
test('destructures variables', async () => {
const sandbox = new Sandbox(
await parse(`