2022-07-19 19:37:52 +00:00
|
|
|
import assert from 'assert'
|
2022-07-22 20:49:14 +00:00
|
|
|
import PocomathInstance from '../../src/core/PocomathInstance.mjs'
|
2022-07-19 19:37:52 +00:00
|
|
|
|
2022-07-22 21:25:26 +00:00
|
|
|
const pi = new PocomathInstance('dummy')
|
2022-07-19 19:37:52 +00:00
|
|
|
describe('PocomathInstance', () => {
|
|
|
|
it('creates an instance that can define typed-functions', () => {
|
2022-07-23 16:55:02 +00:00
|
|
|
pi.install({add: {'any,any': () => (a,b) => a+b}})
|
2022-07-19 19:37:52 +00:00
|
|
|
assert.strictEqual(pi.add(2,2), 4)
|
|
|
|
assert.strictEqual(pi.add('Kilroy', 17), 'Kilroy17')
|
|
|
|
assert.strictEqual(pi.add(1, undefined), NaN)
|
|
|
|
assert.throws(() => pi.add(1), TypeError)
|
|
|
|
})
|
2022-07-22 21:25:26 +00:00
|
|
|
|
|
|
|
it('reserves certain function names', () => {
|
|
|
|
assert.throws(
|
|
|
|
() => pi.install({install: {any: [[], x => x]}}), SyntaxError)
|
|
|
|
assert.throws(
|
|
|
|
() => pi.install({_foo: {any: [[], x => x]}}), SyntaxError)
|
|
|
|
})
|
|
|
|
|
2022-07-19 19:37:52 +00:00
|
|
|
})
|