mirror of
https://github.com/c-cube/linol.git
synced 2025-12-11 05:28:35 -05:00
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
import outdent from "outdent";
|
|
import * as Protocol from "vscode-languageserver-protocol";
|
|
import * as Types from "vscode-languageserver-types";
|
|
import * as LanguageServer from "../src/LanguageServer";
|
|
|
|
describe("ocamllsp/inferIntf", () => {
|
|
let languageServer: LanguageServer.LanguageServer;
|
|
|
|
function openDocument(source: string, name: string) {
|
|
languageServer.sendNotification(
|
|
Protocol.DidOpenTextDocumentNotification.type,
|
|
{
|
|
textDocument: Types.TextDocumentItem.create(
|
|
LanguageServer.toURI(name),
|
|
"ocaml",
|
|
0,
|
|
source,
|
|
),
|
|
},
|
|
);
|
|
}
|
|
|
|
beforeEach(async () => {
|
|
languageServer = await LanguageServer.startAndInitialize();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await LanguageServer.exit(languageServer);
|
|
});
|
|
|
|
async function inferIntf(name: string) {
|
|
return await languageServer.sendRequest(
|
|
"ocamllsp/inferIntf",
|
|
`file:///${name}`,
|
|
);
|
|
}
|
|
|
|
it("can infer module interfaces", async () => {
|
|
openDocument(
|
|
outdent`
|
|
type t = Foo of int | Bar of bool
|
|
|
|
let f (x : t) = x
|
|
`,
|
|
"test.ml",
|
|
);
|
|
const actions = await inferIntf("test.ml");
|
|
expect(actions).toEqual(
|
|
"type t = Foo of int | Bar of bool\nval f : t -> t\n",
|
|
);
|
|
});
|
|
});
|