-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractComments.test.ts
More file actions
70 lines (60 loc) · 2.21 KB
/
Copy pathextractComments.test.ts
File metadata and controls
70 lines (60 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {describe, it, expect} from "vitest";
import {extractComments} from "../src/lib/utils";
describe("extractComments", () => {
it("extracts Python # line comments above a test", () => {
const code = [
" # Calls:",
" # (415) POST:/v2/pet/{petId}/uploadImage",
" # Found 1 potential fault of type-code 101",
" @timeout_decorator.timeout(60)",
" def test_23_post_on_uploadImage_returnsMismatchResponseWithSchema(self):",
" pass",
].join("\n");
expect(extractComments(code)).toBe(
[
"Calls:",
"(415) POST:/v2/pet/{petId}/uploadImage",
"Found 1 potential fault of type-code 101",
].join("\n"),
);
});
it("extracts Java /** */ Javadoc blocks", () => {
const code = [
" /**",
" * Calls:",
" * (200) GET:/pets",
" */",
" @Test",
" public void test_1() { }",
].join("\n");
expect(extractComments(code)).toBe(["Calls:", "(200) GET:/pets"].join("\n"));
});
it("extracts // line comments", () => {
const code = [
" // Calls:",
" // (200) GET:/pets",
" public void test() { }",
].join("\n");
expect(extractComments(code)).toBe(["Calls:", "(200) GET:/pets"].join("\n"));
});
it("separates distinct comment blocks with a blank line", () => {
const code = [
"# first block",
"# more of first block",
"",
"code_line()",
"# second block",
].join("\n");
expect(extractComments(code)).toBe(
["first block\nmore of first block", "second block"].join("\n\n"),
);
});
it("returns empty string when there are no comments", () => {
const code = ["def test():", " pass"].join("\n");
expect(extractComments(code)).toBe("");
});
it("handles a single-line /* ... */ block", () => {
const code = ["/* hello world */", "def f(): pass"].join("\n");
expect(extractComments(code)).toBe("hello world");
});
});