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