test: Check for undefined types, as a means to detect typos in type names #35
@ -16,7 +16,9 @@ export default class PocomathInstance {
|
||||
'install',
|
||||
'installType',
|
||||
'name',
|
||||
'Types'])
|
||||
'Types',
|
||||
'undefinedTypes'
|
||||
])
|
||||
|
||||
constructor(name) {
|
||||
this.name = name
|
||||
@ -25,6 +27,7 @@ export default class PocomathInstance {
|
||||
this._typed = typed.create()
|
||||
this._typed.clear()
|
||||
this.Types = {any: anySpec} // dummy entry to track the default 'any' type
|
||||
this._usedTypes = new Set() // all types that have occurred in a signature
|
||||
this._doomed = new Set() // for detecting circular reference
|
||||
this._config = {predictable: false}
|
||||
const self = this
|
||||
@ -226,6 +229,13 @@ export default class PocomathInstance {
|
||||
this._invalidateDependents(':' + type)
|
||||
}
|
||||
|
||||
/* Returns a list of all types that have been mentioned in the
|
||||
* signatures of operations, but which have not actually been installed:
|
||||
*/
|
||||
undefinedTypes() {
|
||||
return Array.from(this._usedTypes).filter(t => !(t in this.Types))
|
||||
}
|
||||
|
||||
/* Used internally by install, see the documentation there */
|
||||
_installFunctions(functions) {
|
||||
for (const [name, spec] of Object.entries(functions)) {
|
||||
@ -246,6 +256,7 @@ export default class PocomathInstance {
|
||||
this._addAffect(depname, name)
|
||||
}
|
||||
for (const type of typesOfSignature(signature)) {
|
||||
this._usedTypes.add(type)
|
||||
this._addAffect(':' + type, name)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,14 @@ import assert from 'assert'
|
||||
import math from '../src/pocomath.mjs'
|
||||
|
||||
describe('The default full pocomath instance "math"', () => {
|
||||
it('has no undefined types', () => {
|
||||
const undef = math.undefinedTypes()
|
||||
if (undef.length) {
|
||||
console.log('Probable typo: found undefined types', undef)
|
||||
}
|
||||
assert.strictEqual(undef.length, 0)
|
||||
})
|
||||
|
||||
it('can subtract numbers', () => {
|
||||
assert.strictEqual(math.subtract(12, 5), 7)
|
||||
})
|
||||
@ -35,6 +43,9 @@ describe('The default full pocomath instance "math"', () => {
|
||||
assert.deepStrictEqual(math.complex(2,3), norm13)
|
||||
assert.deepStrictEqual(math.complex(2), math.complex(2,0))
|
||||
assert.deepStrictEqual(math.add(2, math.complex(0,3)), norm13)
|
||||
assert.deepStrictEqual(
|
||||
math.subtract(math.complex(1,1), math.complex(2,-2)),
|
||||
math.complex(-1,3))
|
||||
assert.deepStrictEqual(
|
||||
math.subtract(16, math.add(3, math.complex(0,4), 2)),
|
||||
math.complex(11, -4))
|
||||
|
Loading…
Reference in New Issue
Block a user