@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 51 lines 1.74 KB
Raw
1 import { assert } from "@effect/vitest"
2 import { applyTransform } from "jscodeshift/src/testUtils.js"
3 import { describe, it } from "vitest"
4 import transformer from "./jsdoc.ts"
5
6 const doc = "/** Repeats a value. */"
7
8 const transform = (source: string): string =>
9 applyTransform(transformer, {}, { path: "Module.ts", source }, { parser: "ts" })
10
11 const countDocs = (output: string): number => output.split("Repeats a value.").length - 1
12
13 describe("jsdoc codemod", () => {
14 it("leaves generic calls inside an annotated dual implementation unchanged", () => {
15 const output = transform(`${doc}
16 export const repeat: {
17 (n: number): <A>(self: A) => Array<A>
18 <A>(self: A, n: number): Array<A>
19 } = dual(2, <A>(self: A, n: number): Array<A> => make<A, number>(self, n))
20 `)
21 assert.include(output, "make<A, number>(self, n)")
22 assert.strictEqual(countDocs(output), 3)
23 })
24
25 it("leaves generic calls inside a dual implementation with type arguments unchanged", () => {
26 const output = transform(`${doc}
27 export const repeat = dual<
28 (n: number) => <A>(self: A) => Array<A>,
29 <A>(self: A, n: number) => Array<A>
30 >(2, <A>(self: A, n: number) => make<A, number>(self, n))
31 `)
32 assert.include(output, "make<A, number>(self, n)")
33 assert.strictEqual(countDocs(output), 3)
34 })
35
36 it.each(["dual", "Dual.dual"])(
37 "leaves initializer call signatures unchanged on an annotated %s export",
38 (callee) => {
39 const output = transform(`${doc}
40 export const repeat: {
41 (n: number): (self: string) => string
42 (self: string, n: number): string
43 } = ${callee}<
44 { (n: number): (self: string) => string },
45 { (self: string, n: number): string }
46 >(2, (self: string, n: number): string => self.repeat(n))
47 `)
48 assert.strictEqual(countDocs(output), 3)
49 }
50 )
51 })