feat: tests
This commit is contained in:
parent
f349915c65
commit
18272ceecf
|
@ -1,14 +1,61 @@
|
||||||
|
import {Latus} from '@latus/core';
|
||||||
import {expect} from 'chai';
|
import {expect} from 'chai';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
buildCondition,
|
buildCondition,
|
||||||
buildInvoke,
|
buildInvoke,
|
||||||
buildExpression,
|
buildExpression,
|
||||||
buildValue,
|
buildValue,
|
||||||
} from '../src/builders';
|
} from '../src/builders';
|
||||||
|
import Context from '../src/context';
|
||||||
|
import compile from '../src/compilers/compile';
|
||||||
|
|
||||||
describe('@avocado/behavior', () => {
|
const {name} = require('../package.json');
|
||||||
|
|
||||||
|
describe(name, () => {
|
||||||
|
let latus;
|
||||||
|
let context;
|
||||||
|
beforeEach(async () => {
|
||||||
|
latus = Latus.mock([
|
||||||
|
['@avocado/behavior', `${__dirname}/../src`],
|
||||||
|
]);
|
||||||
|
await Promise.all(latus.invokeFlat('@latus/core/starting'));
|
||||||
|
context = new Context({}, latus);
|
||||||
|
});
|
||||||
describe('builders', () => {
|
describe('builders', () => {
|
||||||
describe('.buildValue', () => {
|
it('can build conditions', async () => {
|
||||||
|
const condition = compile(buildCondition('is', [
|
||||||
|
buildValue(69),
|
||||||
|
buildValue(69),
|
||||||
|
]), latus);
|
||||||
|
expect(condition(context)).to.be.true;
|
||||||
|
});
|
||||||
|
it('can build expressions', async () => {
|
||||||
|
const test = {foo: 69};
|
||||||
|
context.add('test', test);
|
||||||
|
const expression = compile(buildExpression(['test', 'foo']), latus);
|
||||||
|
expect(expression(context)).to.equal(test.foo);
|
||||||
|
const expression2 = compile(buildExpression(['test', 'foo'], 420), latus);
|
||||||
|
expression2(context);
|
||||||
|
expect(test.foo).to.equal(420);
|
||||||
|
});
|
||||||
|
it('can build invocations', async () => {
|
||||||
|
const test = {foo: () => 69};
|
||||||
|
context.add('test', test);
|
||||||
|
const expression = compile(buildInvoke(['test', 'foo']), latus);
|
||||||
|
expect(expression(context)).to.equal(69);
|
||||||
|
});
|
||||||
|
it('can build values', async () => {
|
||||||
|
const passthroughs = [
|
||||||
|
buildCondition('is', []),
|
||||||
|
buildExpression([]),
|
||||||
|
buildValue(69),
|
||||||
|
];
|
||||||
|
for (let i = 0; i < passthroughs.length; i++) {
|
||||||
|
const passthrough = passthroughs[i];
|
||||||
|
expect(passthrough).to.equal(buildValue(passthrough));
|
||||||
|
}
|
||||||
|
expect(buildValue(420)).to.deep.equal({type: 'literal', value: 420});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user