feat(returnTypeOf): Support template and upper bound types

Also changed the notation for an upper bound template to the more
  readable 'T:number' (instead of 'T (= number', which was supposed to
  look like the non-strict subset relation).
This commit is contained in:
Glen Whitney 2022-08-24 13:37:32 -04:00
parent f7bb3697ed
commit 775bb9ddb7
12 changed files with 170 additions and 53 deletions

View file

@ -23,6 +23,17 @@ describe('The default full pocomath instance "math"', () => {
it('can determine the return types of operations', () => {
assert.strictEqual(math.returnTypeOf('negate', 'number'), 'number')
assert.strictEqual(math.returnTypeOf('negate', 'NumInt'), 'NumInt')
math.negate(math.complex(1.2, 2.8)) // TODO: make this call unnecessary
assert.strictEqual(
math.returnTypeOf('negate', 'Complex<number>'), 'Complex<number>')
assert.strictEqual(math.returnTypeOf('add', 'number,number'), 'number')
assert.strictEqual(math.returnTypeOf('add', 'NumInt,NumInt'), 'NumInt')
assert.strictEqual(math.returnTypeOf('add', 'NumInt,number'), 'number')
assert.strictEqual(math.returnTypeOf('add', 'number,NumInt'), 'number')
assert.deepStrictEqual( // TODO: ditto
math.add(3, math.complex(2.5, 1)), math.complex(5.5, 1))
assert.strictEqual(
math.returnTypeOf('add', 'Complex<number>,NumInt'), 'Complex<number>')
})
it('can subtract numbers', () => {

8
test/core/_utils.mjs Normal file
View file

@ -0,0 +1,8 @@
import assert from 'assert'
import * as utils from '../../src/core/utils.mjs'
describe('typeListOfSignature', () => {
it('returns an empty list for the empty signature', () => {
assert.deepStrictEqual(utils.typeListOfSignature(''), [])
})
})