-
Notifications
You must be signed in to change notification settings - Fork 46
/
FunctionType.spec.ts
38 lines (32 loc) · 1.31 KB
/
FunctionType.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { expect } from 'chai';
import { DynamicType } from './DynamicType';
import { FunctionType } from './FunctionType';
import { IntegerType } from './IntegerType';
import { StringType } from './StringType';
import { VoidType } from './VoidType';
describe('FunctionType', () => {
it('is equivalent to dynamic type', () => {
expect(new FunctionType(new VoidType()).isAssignableTo(new DynamicType())).to.be.true;
});
it('validates using param and return types', () => {
expect(new FunctionType(new VoidType()).isAssignableTo(new FunctionType(new VoidType()))).to.be.true;
//different parameter count
expect(
new FunctionType(new VoidType()).addParameter('a', new IntegerType(), false).isAssignableTo(
new FunctionType(new VoidType())
)
).to.be.false;
//different parameter types
expect(
new FunctionType(new VoidType()).addParameter('a', new IntegerType(), false).isAssignableTo(
new FunctionType(new VoidType()).addParameter('a', new StringType(), false)
)
).to.be.false;
//different return type
expect(
new FunctionType(new VoidType()).isAssignableTo(
new FunctionType(new IntegerType())
)
).to.be.false;
});
});