-
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathcomments.spec.ts
More file actions
115 lines (102 loc) · 3.56 KB
/
comments.spec.ts
File metadata and controls
115 lines (102 loc) · 3.56 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import * as util from "../util";
test("Single-line JSDoc is copied on a function", () => {
const builder = util.testModule`
/** This is a function comment. */
function foo() {}
`
.expectToHaveNoDiagnostics()
.expectDiagnosticsToMatchSnapshot();
const transpiledFile = builder.getLuaResult().transpiledFiles[0];
expect(transpiledFile).toBeDefined();
const { lua } = transpiledFile;
expect(lua).toBeDefined();
expect(lua).toContain("This is a function comment.");
});
test("Multi-line JSDoc with one block is copied on a function", () => {
const builder = util.testModule`
/**
* This is a function comment.
* It has more than one line.
*/
function foo() {}
`
.expectToHaveNoDiagnostics()
.expectDiagnosticsToMatchSnapshot();
const transpiledFile = builder.getLuaResult().transpiledFiles[0];
expect(transpiledFile).toBeDefined();
const { lua } = transpiledFile;
expect(lua).toBeDefined();
expect(lua).toContain("It has more than one line.");
});
test("Multi-line JSDoc with two blocks is copied on a function", () => {
const builder = util.testModule`
/**
* This is a function comment.
* It has more than one line.
*
* It also has more than one block.
*/
function foo() {}
`
.expectToHaveNoDiagnostics()
.expectDiagnosticsToMatchSnapshot();
const transpiledFile = builder.getLuaResult().transpiledFiles[0];
expect(transpiledFile).toBeDefined();
const { lua } = transpiledFile;
expect(lua).toBeDefined();
expect(lua).toContain("It also has more than one block.");
});
test("JSDoc is copied on a function with tags", () => {
const builder = util.testModule`
/**
* This is a function comment.
* It has multiple lines.
*
* @param arg1 This is the first argument.
* @param arg2 This is the second argument.
* @returns A very powerful string.
*/
function foo(arg1: boolean, arg2: number): string {
return "bar";
}
`
.expectToHaveNoDiagnostics()
.expectDiagnosticsToMatchSnapshot();
const transpiledFile = builder.getLuaResult().transpiledFiles[0];
expect(transpiledFile).toBeDefined();
const { lua } = transpiledFile;
expect(lua).toBeDefined();
expect(lua).toContain("This is the first argument.");
expect(lua).toContain("This is the second argument.");
expect(lua).toContain("A very powerful string.");
});
test("JSDoc is copied on a variable", () => {
const builder = util.testModule`
/** This is a variable comment. */
const foo = 123;
`
.expectToHaveNoDiagnostics()
.expectDiagnosticsToMatchSnapshot();
const transpiledFile = builder.getLuaResult().transpiledFiles[0];
expect(transpiledFile).toBeDefined();
const { lua } = transpiledFile;
expect(lua).toBeDefined();
expect(lua).toContain("This is a variable comment.");
});
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1299
test("tsdoc comment does not cause a diagnostic (#1299)", () => {
util.testModule`
interface LuaBootstrap {
/**
* @remarks
*
* Links can point to a URL: {@link https://github.com/microsoft/tsdoc}
*/
on_init(f: (() => void) ): void
}
const script : LuaBootstrap = {
on_init: (x) => x()
}
script.on_init(() => {})
`.expectToHaveNoDiagnostics();
});