Skip to content

Commit

Permalink
Add a test for #2270
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed May 5, 2023
1 parent af63d9e commit 5d38df1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 14 deletions.
9 changes: 1 addition & 8 deletions src/test/behavior.c2.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { deepStrictEqual as equal, ok } from "assert";
import {
DeclarationReflection,
LiteralType,
ProjectReflection,
ReflectionKind,
Comment,
CommentTag,
Expand All @@ -21,12 +19,7 @@ import {
import { join } from "path";
import { existsSync } from "fs";
import { clearCommentCache } from "../lib/converter/comments";

function query(project: ProjectReflection, name: string) {
const reflection = project.getChildByName(name);
ok(reflection instanceof DeclarationReflection, `Failed to find ${name}`);
return reflection;
}
import { query } from "./utils";

type NameTree = { [name: string]: NameTree };

Expand Down
8 changes: 8 additions & 0 deletions src/test/converter2/issues/gh2270.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Flagging all state references as {@link Immutable} guides IDEs to treat these
* as {@link https://en.wikipedia.org/wiki/Immutable_object | Immutable Objects}
* to avoid programming errors.
*/
export const A = 123;

export type Immutable = readonly [];
22 changes: 16 additions & 6 deletions src/test/issues.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { TestLogger } from "./TestLogger";
import { clearCommentCache } from "../lib/converter/comments";
import { join } from "path";
import { existsSync } from "fs";
import { getLinks, query } from "./utils";

const base = getConverter2Base();
const app = getConverter2App();
Expand Down Expand Up @@ -57,12 +58,6 @@ function doConvert(entry: string) {
]);
}

function query(project: ProjectReflection, name: string) {
const reflection = project.getChildByName(name);
ok(reflection instanceof DeclarationReflection, `Failed to find ${name}`);
return reflection;
}

describe("Issue Tests", () => {
let logger: TestLogger;
let convert: (name?: string) => ProjectReflection;
Expand Down Expand Up @@ -1101,4 +1096,19 @@ describe("Issue Tests", () => {
"ReadonlyCharMap.[iterator]"
);
});

it("Handles http links with TS link resolution #2270", () => {
const project = convert();
const links = getLinks(query(project, "A"));
equal(links, [
{
display: "Immutable",
target: [ReflectionKind.TypeAlias, "Immutable"],
},
{
display: "Immutable Objects",
target: "https://en.wikipedia.org/wiki/Immutable_object",
},
]);
});
});
38 changes: 38 additions & 0 deletions src/test/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ok } from "assert";
import {
DeclarationReflection,
ProjectReflection,
Reflection,
ReflectionKind,
} from "..";
import { filterMap } from "../lib/utils";

export function query(project: ProjectReflection, name: string) {
const reflection = project.getChildByName(name);
ok(reflection instanceof DeclarationReflection, `Failed to find ${name}`);
return reflection;
}

export function getLinks(refl: Reflection): Array<{
display: string;
target: undefined | string | [ReflectionKind, string];
}> {
ok(refl.comment);
return filterMap(refl.comment.summary, (p) => {
if (p.kind === "inline-tag" && p.tag === "@link") {
if (typeof p.target === "string") {
return { display: p.tsLinkText || p.text, target: p.target };
}
if (p.target instanceof Reflection) {
return {
display: p.tsLinkText || p.target.name,
target: [p.target.kind, p.target.getFullName()],
};
}
return {
display: p.tsLinkText || p.text,
target: p.target?.getStableKey(),
};
}
});
}

0 comments on commit 5d38df1

Please sign in to comment.