From 5cd898534358638d5316ab53a553f1c799599d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1n=20D=C3=A9nes?= Date: Sun, 16 May 2021 21:48:10 +0200 Subject: [PATCH] Add unit test for operation parsing --- test/unit/operation.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/unit/operation.js diff --git a/test/unit/operation.js b/test/unit/operation.js new file mode 100644 index 0000000..de2a12e --- /dev/null +++ b/test/unit/operation.js @@ -0,0 +1,22 @@ +const o = require('../../src/operation') + +describe('Operation', function() { + + it('op_prefix', function() { + o.op_prefix('arst').should.deep.equal({name: 'arst', operation: 'add'}) + o.op_prefix('+arst').should.deep.equal({name: 'arst', operation: 'add'}) + o.op_prefix('-arst').should.deep.equal({name: 'arst', operation: 'subtract'}) + o.op_prefix('~arst').should.deep.equal({name: 'arst', operation: 'intersect'}) + o.op_prefix('^arst').should.deep.equal({name: 'arst', operation: 'stack'}) + }) + + it('operation', function() { + // without choices, it's the same as op_prefix + o.operation('arst').should.deep.equal({name: 'arst', operation: 'add'}) + // with choices, it propagates type where it found the name + o.operation('arst', {bad: [], good: ['arst']}).should.deep.equal({name: 'arst', operation: 'add', type: 'good'}) + // it also respects order when overridden + o.operation('arst', {first: ['arst'], second: ['arst']}, ['second', 'first']).should.deep.equal({name: 'arst', operation: 'add', type: 'second'}) + }) + +}) \ No newline at end of file