Skip to content

Commit

Permalink
test: use snapshots everywhere
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

<!-- ps-id: 4bf9a40d-293a-483c-bf6b-24bd494e9c03 -->
  • Loading branch information
rgrinberg committed Jun 14, 2024
1 parent d95d947 commit a5f6ba7
Show file tree
Hide file tree
Showing 14 changed files with 1,063 additions and 676 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ clean: ## Clean build artifacts and other generated files
.PHONY: fmt
fmt: ## Format the codebase with ocamlformat
dune build @fmt --auto-promote
cd $(TEST_E2E_DIR) && yarn fmt
cd $(TEST_E2E_DIR)

.PHONY: watch
watch: ## Watch for the filesystem and rebuild on every change
Expand All @@ -97,7 +97,7 @@ nix-tests:
nix-fmt:
$(MAKE) yarn-install
dune build @fmt --auto-promote
cd $(TEST_E2E_DIR) && yarn fmt
cd $(TEST_E2E_DIR)

.PHONY: coverage-deps
coverage-deps:
Expand Down
186 changes: 120 additions & 66 deletions ocaml-lsp-server/test/e2e/__tests__/ocamllsp-hoverExtended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@ describe("ocamllsp/hoverExtended", () => {
verbosity: 0,
});

expect(result).toMatchObject({
contents: { kind: "plaintext", value: "int" },
range: {
end: { character: 5, line: 0 },
start: { character: 4, line: 0 },
},
});
expect(result).toMatchInlineSnapshot(`
Object {
"contents": Object {
"kind": "plaintext",
"value": "int",
},
"range": Object {
"end": Object {
"character": 5,
"line": 0,
},
"start": Object {
"character": 4,
"line": 0,
},
},
}
`);
});

it("returns type inferred under cursor (markdown formatting)", async () => {
Expand Down Expand Up @@ -63,13 +74,26 @@ describe("ocamllsp/hoverExtended", () => {
verbosity: 0,
});

expect(result).toMatchObject({
contents: { kind: "markdown", value: "```ocaml\nint\n```" },
range: {
end: { character: 5, line: 0 },
start: { character: 4, line: 0 },
},
});
expect(result).toMatchInlineSnapshot(`
Object {
"contents": Object {
"kind": "markdown",
"value": "\`\`\`ocaml
int
\`\`\`",
},
"range": Object {
"end": Object {
"character": 5,
"line": 0,
},
"start": Object {
"character": 4,
"line": 0,
},
},
}
`);
});

it("returns type inferred under cursor with documentation", async () => {
Expand Down Expand Up @@ -104,18 +128,28 @@ describe("ocamllsp/hoverExtended", () => {
verbosity: 0,
});

expect(result).toMatchObject({
contents: {
kind: "markdown",
value: outdent`
\`\`\`ocaml
'a -> 'a
\`\`\`
---
This function has a nice documentation
`,
},
});
expect(result).toMatchInlineSnapshot(`
Object {
"contents": Object {
"kind": "markdown",
"value": "\`\`\`ocaml
'a -> 'a
\`\`\`
---
This function has a nice documentation",
},
"range": Object {
"end": Object {
"character": 11,
"line": 3,
},
"start": Object {
"character": 9,
"line": 3,
},
},
}
`);
});

it("returns type inferred under cursor with documentation with tags (markdown formatting)", async () => {
Expand Down Expand Up @@ -170,48 +204,58 @@ describe("ocamllsp/hoverExtended", () => {
verbosity: 0,
});

expect(result).toMatchObject({
contents: {
kind: "markdown",
value: outdent`
\`\`\`ocaml
int -> int -> int
\`\`\`
---
This function has a nice documentation.
expect(result).toMatchInlineSnapshot(`
Object {
"contents": Object {
"kind": "markdown",
"value": "\`\`\`ocaml
int -> int -> int
\`\`\`
---
This function has a nice documentation.
It performs division of two integer numbers.
It performs division of two integer numbers.
***@param*** \`x\`
dividend
***@param*** \`x\`
dividend
***@param*** divisor
***@param*** divisor
***@return***
*quotient*, i.e. result of division
***@return***
*quotient*, i.e. result of division
***@raise*** \`Division_by_zero\`
raised when divided by zero
***@raise*** \`Division_by_zero\`
raised when divided by zero
***@see*** [link](https://en.wikipedia.org/wiki/Arithmetic#Division_\\(%C3%B7,_or_/\\))
article
***@see*** [link](https://en.wikipedia.org/wiki/Arithmetic#Division_\\\\(%C3%B7,_or_/\\\\))
article
***@see*** \`arithmetic.ml\`
for more context
***@see*** \`arithmetic.ml\`
for more context
***@since*** \`4.0.0\`
***@since*** \`4.0.0\`
***@before*** \`4.4.0\`
***@before*** \`4.4.0\`
***@deprecated***
use \`(/)\`
***@deprecated***
use \`(/)\`
***@version*** \`1.0.0\`
***@version*** \`1.0.0\`
***@author*** John Doe
`,
},
});
***@author*** John Doe",
},
"range": Object {
"end": Object {
"character": 11,
"line": 23,
},
"start": Object {
"character": 8,
"line": 23,
},
},
}
`);
});

it("returns good type when cursor is between values", async () => {
Expand Down Expand Up @@ -246,16 +290,26 @@ describe("ocamllsp/hoverExtended", () => {
verbosity: 0,
});

expect(result).toMatchObject({
contents: {
kind: "markdown",
value: "```ocaml\nint\n```",
},
range: {
start: { character: 12, line: 3 },
end: { character: 13, line: 3 },
},
});
expect(result).toMatchInlineSnapshot(`
Object {
"contents": Object {
"kind": "markdown",
"value": "\`\`\`ocaml
int
\`\`\`",
},
"range": Object {
"end": Object {
"character": 13,
"line": 3,
},
"start": Object {
"character": 12,
"line": 3,
},
},
}
`);
});

it("regression test for #343", async () => {
Expand Down
69 changes: 49 additions & 20 deletions ocaml-lsp-server/test/e2e/__tests__/textDocument-codeLens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,57 @@ describe("textDocument/references", () => {

let result = await query();

expect(result).toMatchObject([
{
command: { command: "", title: "int -> int -> int" },
range: {
end: { character: 19, line: 4 },
start: { character: 2, line: 4 },
},
expect(result).toMatchInlineSnapshot(`
Array [
Object {
"command": Object {
"command": "",
"title": "int -> int -> int",
},
"range": Object {
"end": Object {
"character": 19,
"line": 4,
},
{
command: { command: "", title: "string" },
range: {
end: { character: 20, line: 1 },
start: { character: 0, line: 1 },
},
"start": Object {
"character": 2,
"line": 4,
},
{
command: { command: "", title: "int" },
range: {
end: { character: 12, line: 0 },
start: { character: 0, line: 0 },
},
},
},
Object {
"command": Object {
"command": "",
"title": "string",
},
"range": Object {
"end": Object {
"character": 20,
"line": 1,
},
"start": Object {
"character": 0,
"line": 1,
},
},
},
Object {
"command": Object {
"command": "",
"title": "int",
},
"range": Object {
"end": Object {
"character": 12,
"line": 0,
},
"start": Object {
"character": 0,
"line": 0,
},
]);
},
},
]
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ describe("textDocument/declaration", () => {
);

expect(result.length).toBe(1);
expect(result[0].range).toMatchObject({
end: { character: 0, line: 0 },
start: { character: 0, line: 0 },
});
expect(result[0].range).toMatchInlineSnapshot(`
Object {
"end": Object {
"character": 0,
"line": 0,
},
"start": Object {
"character": 0,
"line": 0,
},
}
`);
expect(result[0].uri).toEqualUri(testUri(createPathForFile("lib.mli")));
});
});

0 comments on commit a5f6ba7

Please sign in to comment.