silphius/app/swcx/evaluators/unary.test.js
2024-06-17 05:20:01 -05:00

43 lines
1.0 KiB
JavaScript

import {expect, test} from 'vitest';
import {first} from '@/swcx/builders.js';
import evaluate from '@/swcx/evaluate.js';
test('evaluates +', async () => {
expect(evaluate(await first('+1')))
.to.deep.include({value: 1});
});
test('evaluates -', async () => {
expect(evaluate(await first('-1')))
.to.deep.include({value: -1});
});
test('evaluates !', async () => {
expect(evaluate(await first('!true')))
.to.deep.include({value: false});
});
test('evaluates ~', async () => {
expect(evaluate(await first('~1')))
.to.deep.include({value: -2});
});
test('evaluates typeof', async () => {
expect(evaluate(await first('typeof "a"')))
.to.deep.include({value: 'string'});
});
test('evaluates void', async () => {
expect(evaluate(await first('void 0')))
.to.deep.include({value: undefined});
});
test('evaluates promised unary expression', async () => {
const evaluated = evaluate(await first('-(await 4)'));
expect(evaluated.async)
.to.equal(true);
expect(await evaluated.value)
.to.equal(-4);
});