Skip to content

Commit

Permalink
fix: Fix bug in ReferenceType equality check
Browse files Browse the repository at this point in the history
fixes #1383
  • Loading branch information
Soc Sieng authored and Gerrit0 committed Oct 28, 2020
1 parent fc4103f commit 3f63956
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/models/types/reference.ts
Expand Up @@ -92,7 +92,9 @@ export class ReferenceType extends Type {
return (
other instanceof ReferenceType &&
(other.symbolFullyQualifiedName === this.symbolFullyQualifiedName ||
other.reflection === this.reflection)
(other.reflection === this.reflection &&
other.reflection != null &&
this.reflection != null))
);
}

Expand Down
44 changes: 44 additions & 0 deletions src/test/models/types/reference.test.ts
@@ -0,0 +1,44 @@
import { deepStrictEqual as equal } from "assert";
import { ReflectionKind } from "../../../lib/models";
import { DeclarationReflection } from "../../../lib/models/reflections/declaration";
import { ReferenceType } from "../../../lib/models/types/reference";

describe("Reference Type", () => {
describe("equals", () => {
it("types with same symbolFullyQualifiedName are equal", () => {
const type1 = new ReferenceType("Type", "Type");
const type2 = new ReferenceType("Type", "Type");

equal(type1.equals(type2), true);
});

it("types with different symbolFullyQualifiedName are not equal", () => {
const type1 = new ReferenceType("Type1", "Type1");
const type2 = new ReferenceType("Type2", "Type2");

equal(type1.equals(type2), false);
});

it("types with different symbolFullyQualifiedName but same reflection are equal", () => {
const reflection = new DeclarationReflection(
"declaration",
ReflectionKind.Function
);
const type1 = new ReferenceType("Type1", "Type1", reflection);
const type2 = new ReferenceType("Type2", "Type2", reflection);

equal(type1.equals(type2), true);
});

it("types with different symbolFullyQualifiedName but different reflection (one is undefined) are equal", () => {
const reflection = new DeclarationReflection(
"declaration",
ReflectionKind.Function
);
const type1 = new ReferenceType("Type1", "Type1", reflection);
const type2 = new ReferenceType("Type2", "Type2", undefined);

equal(type1.equals(type2), false);
});
});
});

0 comments on commit 3f63956

Please sign in to comment.