import assert from 'assert' import poortf from '../poortf.js' describe('poortf', () => { const slate = poortf('slate') it('creates an empty tf', () => { assert.throws(() => slate('empty'), TypeError) assert.throws(() => slate('empty'), /slate.*empty/) }) const add = poortf('add', [ [args => Array.from(args).every(a => typeof a === 'number'), (a, b) => a+b], [args => Array.from(args).every(a => typeof a === 'boolean'), (p, q) => p || q] ]) it('creates a tf with initial behaviors', () => { assert.strictEqual(add(2,2), 4) assert.strictEqual(add(true, false), true) assert.throws(() => add('kilroy'), TypeError) }) it('extends an empty tf', () => { slate.addImps([ [args => typeof args[0] === 'string', s => s + ' wuz here'], [args => typeof args[0] === 'number', () => 'I am not a number'] ]) assert.strictEqual(slate('Kilroy', 'was here'), 'Kilroy wuz here') assert.strictEqual(slate(2, 'was here'), 'I am not a number') assert.throws(() => slate(['Ha!']), TypeError) }) it('extends a tf with other behaviors', () => { add.addImps([args => typeof args[0] === 'string', (s,x) => s + x]), assert.strictEqual(add('Kilroy', 23), 'Kilroy23') assert.throws(() => add(['Ha!'], 'gotcha'), TypeError) }) })