open-epsilon
Version:
empty-epsilon / open-sound-control bidirectional proxy
117 lines • 4.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const translate_1 = require("../src/translate");
const process_schema_1 = require("../src/process-schema");
const apiModel = process_schema_1.processApiSchema({
"global": {
"getPlayerShip": {
"arguments": ["integer"],
"type": ["PlayerSpaceship"]
}
},
"PlayerSpaceship": {
"$inherits": "SpaceShip"
},
"SpaceShip": {
"$inherits": "ShipTemplateBasedObject",
"getSystemHealth": {
"arguments": ["ESystem"],
"type": ["float"]
},
"setSystemHealth": {
"arguments": ["ESystem", "float"],
"type": []
},
},
"ShipTemplateBasedObject": {
"getHull": {
"arguments": [],
"type": ["float"]
},
"setHull": {
"arguments": ["float"],
"type": []
},
"getPosition": {
"arguments": [],
"type": ["float", "float"]
},
"setPosition": {
"arguments": ["float", "float"],
"type": []
},
}
});
describe('MessageTranslator', () => {
const namespace = 'zagzag';
let translator;
beforeEach(() => {
translator = new translate_1.MessageTranslator(apiModel, namespace);
});
describe('translateAddressToGameQuery', () => {
it('meaningless address throws', () => {
chai_1.expect(() => translator.translateAddressToGameQuery(`/${'foo' + namespace}/player-ship/-1`)).to.throw(Error);
});
it('incomplete expression throws', () => {
chai_1.expect(() => translator.translateAddressToGameQuery(`/${namespace}/player-ship`)).to.throw(Error);
});
it('expression that does not resolve to primitive throws', () => {
chai_1.expect(() => translator.translateAddressToGameQuery(`/${namespace}/player-ship/-1`)).to.throw(Error);
});
it('basic : ee/playership/-1/hull', () => {
const q = translator.translateAddressToGameQuery(`/${namespace}/player-ship/-1/hull`);
chai_1.expect(q).to.eql({
"address": `/${namespace}/player-ship/-1/hull`,
"expr": "getPlayerShip(-1):getHull()",
"type": "f"
});
});
it('multiple returns : ee/playership/-1/position', () => {
const q = translator.translateAddressToGameQuery(`/${namespace}/player-ship/-1/position`);
chai_1.expect(q).to.eql({
"address": `/${namespace}/player-ship/-1/position`,
"expr": "getPlayerShip(-1):getPosition()",
"type": "ff"
});
});
});
describe('translateOscMessageToGameCommand', () => {
it('meaningless address throws', () => {
chai_1.expect(() => translator.translateOscMessageToGameCommand({ address: '/foo/bar', args: [] })).to.throw(Error);
});
it(`incomplete expression throws`, () => {
chai_1.expect(() => translator.translateOscMessageToGameCommand({
address: `/${namespace}/player-ship`,
args: []
})).to.throw(Error);
});
it(`expression that does not resolve to primitive throws`, () => {
chai_1.expect(() => translator.translateOscMessageToGameCommand({
address: `/${namespace}/player-ship/-1`,
args: []
})).to.throw(Error);
});
it('basic : ee/playership/-1/hull', () => {
const q = translator.translateOscMessageToGameCommand({
address: `/${namespace}/player-ship/-1/hull`,
args: [0.5]
});
chai_1.expect(q).to.eql({
"template": "getPlayerShip(-1):setHull({0})",
"values": ["0.50"]
});
});
it('with a method argument in the address (set it as part of the template, not a variable)', () => {
const q = translator.translateOscMessageToGameCommand({
address: `/${namespace}/player-ship/-1/system-health/reactor`,
args: [0.5]
});
chai_1.expect(q).to.eql({
"template": 'getPlayerShip(-1):setSystemHealth("Reactor", {0})',
"values": ["0.50"]
});
});
});
});
//# sourceMappingURL=translate.spec.js.map