/
reference.test.ts
76 lines (61 loc) · 2.94 KB
/
reference.test.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import type * as ts from "typescript";
import { deepStrictEqual as equal } from "assert";
import {
LiteralType,
ProjectReflection,
ReflectionKind,
} from "../../../lib/models";
import { DeclarationReflection } from "../../../lib/models/reflections/declaration";
import { ReferenceType } from "../../../lib/models/types/reference";
describe("Reference Type", () => {
describe("equals", () => {
const fakeSymbol1 = (Symbol() as any) as ts.Symbol;
const fakeSymbol2 = (Symbol() as any) as ts.Symbol;
const project = new ProjectReflection("");
const reflection = new DeclarationReflection(
"declaration",
ReflectionKind.Function
);
project.children ??= [];
project.children.push(reflection);
project.registerReflection(reflection, fakeSymbol1);
it("types with same target are equal", () => {
const type1 = new ReferenceType("Type", fakeSymbol1, project);
const type2 = new ReferenceType("Type", fakeSymbol1, project);
equal(type1.equals(type2), true);
});
it("unresolved types with same target are equal", () => {
const type1 = new ReferenceType("Type", fakeSymbol2, project);
const type2 = new ReferenceType("Type", fakeSymbol2, project);
equal(type1.equals(type2), true);
});
it("types with different targets are not equal", () => {
const type1 = new ReferenceType("Type1", fakeSymbol1, project);
const type2 = new ReferenceType("Type2", fakeSymbol2, project);
equal(type1.equals(type2), false);
});
it("types with same resolved target are equal", () => {
const type1 = new ReferenceType("Type1", reflection, project);
const type2 = new ReferenceType("Type2", fakeSymbol1, project);
equal(type1.equals(type2), true);
});
it("types with the same type parameters are equal", () => {
const type1 = new ReferenceType("Type1", reflection, project);
type1.typeArguments = [new LiteralType(null)];
const type2 = new ReferenceType("Type2", fakeSymbol1, project);
type2.typeArguments = [new LiteralType(null)];
equal(type1.equals(type2), true);
});
it("types with different type parameters are not equal", () => {
const type1 = new ReferenceType("Type1", reflection, project);
type1.typeArguments = [new LiteralType(null)];
const type2 = new ReferenceType("Type2", fakeSymbol1, project);
equal(type1.equals(type2), false);
});
it("intentionally broken reference types with different names are not equal", () => {
const type1 = ReferenceType.createBrokenReference("Type1", project);
const type2 = ReferenceType.createBrokenReference("Type2", project);
equal(type1.equals(type2), false);
});
});
});