-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
function f() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
type Entity, | ||
DeclarationEntity, | ||
} from "@onlyoffice/library-declaration/next.ts" | ||
import { | ||
EntityToken, | ||
KeywordToken, | ||
type Signature, | ||
TextToken, | ||
type Token, | ||
TypeToken, | ||
} from "@onlyoffice/signature" | ||
|
||
export const name = "transforms an empty project" | ||
|
||
export const collection: Entity[] = [] | ||
|
||
let e0: Entity | ||
let s: Signature = [] | ||
let t: Token | ||
|
||
e0 = new DeclarationEntity() | ||
e0.id = 2 | ||
|
||
t = new KeywordToken() | ||
t.text = "function" | ||
s.push(t) | ||
|
||
t = new TextToken() | ||
t.text = " " | ||
s.push(t) | ||
|
||
t = new EntityToken() | ||
t.text = "f" | ||
s.push(t) | ||
|
||
t = new TextToken() | ||
t.text = "(" | ||
s.push(t) | ||
|
||
t = new TextToken() | ||
t.text = ")" | ||
s.push(t) | ||
|
||
t = new TextToken() | ||
t.text = ": " | ||
s.push(t) | ||
|
||
t = new TypeToken() | ||
t.text = "void" | ||
s.push(t) | ||
|
||
e0.declaration.signature.verbose = s | ||
|
||
collection.push(e0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"files": ["main.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import {readdir} from "node:fs/promises" | ||
import path from "node:path" | ||
import {pipeline} from "node:stream" | ||
import {promisify} from "node:util" | ||
import {type Entity, GroupEntity} from "@onlyoffice/library-declaration/next.ts" | ||
import {Transformer} from "@onlyoffice/typedoc-transformer" | ||
import {Transport} from "@onlyoffice/typedoc-transport" | ||
import {Application, type JSONOutput as J, type TypeDocOptions} from "typedoc" | ||
import {test} from "uvu" | ||
import {equal as eq} from "uvu/assert" | ||
import {Console} from "./console.ts" | ||
import {compute} from "./main.ts" | ||
|
||
const pipe = promisify(pipeline) | ||
|
||
test.before(() => { | ||
Console.shared.mute() | ||
}) | ||
|
||
test.after(() => { | ||
Console.shared.unmute() | ||
}) | ||
|
||
for (const f of await readdir("fixtures")) { | ||
const t = await setupTest(f) | ||
|
||
test(`${f}: ${t.name}`, async () => { | ||
const o = await setupReflection(f, t.options) | ||
|
||
const a = t.collection | ||
const e = await process(o) | ||
|
||
// TODO: handling cases where the equality test has not been met | ||
for (const x of a) { | ||
for (const y of e) { | ||
if (x instanceof GroupEntity || y instanceof GroupEntity) { | ||
continue // TODO | ||
} | ||
if (y.id === x.id) { | ||
eq(x.declaration.signature.verbose, y.declaration.signature.verbose) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
test.run() | ||
|
||
interface Test { | ||
name: string | ||
options: Partial<TypeDocOptions> | ||
collection: Entity[] | ||
} | ||
|
||
async function setupTest(n: string): Promise<Test> { | ||
const m = await import(`../fixtures/${n}/test.ts`) | ||
const t: Test = {name: m.name, options: {}, collection: m.collection} | ||
if (m.options) { | ||
t.options = m.options | ||
} | ||
return t | ||
} | ||
|
||
async function setupReflection(n: string, opts: Partial<TypeDocOptions>): Promise<J.ProjectReflection> { | ||
const d = path.join("fixtures", n) | ||
const e = path.join(d, "main.ts") | ||
const c = path.join(d, "tsconfig.json") | ||
|
||
const a = await Application.bootstrapWithPlugins({ | ||
entryPoints: [e], | ||
logLevel: "None", | ||
name: path.basename(d), | ||
tsconfig: c, | ||
...opts, | ||
}) | ||
|
||
const p = await a.convert() | ||
if (!p) { | ||
throw new Error("Project is missing") | ||
} | ||
|
||
return a.serializer.projectToObject(p, d) | ||
} | ||
|
||
export async function process(o: J.ProjectReflection): Promise<Entity[]> { | ||
const tp = new Transport(o) | ||
const tf = new Transformer(tp) | ||
|
||
await pipe(tp.toReadable(), tf, tp.toWritable()) | ||
|
||
compute(tp) | ||
return tp.entities | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters