@alloy-js/csharp 0.18.0-dev.18 → 0.18.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/Class.d.ts +26 -0
- package/dist/src/components/Class.d.ts.map +1 -0
- package/dist/src/components/{ClassDeclaration.js → Class.js} +32 -59
- package/dist/src/components/ClassMethod.d.ts +4 -25
- package/dist/src/components/ClassMethod.d.ts.map +1 -1
- package/dist/src/components/ClassMethod.js +3 -22
- package/dist/src/components/Enum.d.ts +15 -0
- package/dist/src/components/Enum.d.ts.map +1 -0
- package/dist/src/components/{EnumDeclaration.js → Enum.js} +5 -25
- package/dist/src/components/Parameters.d.ts +1 -6
- package/dist/src/components/Parameters.d.ts.map +1 -1
- package/dist/src/components/Parameters.js +2 -3
- package/dist/src/components/index.d.ts +3 -12
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +4 -13
- package/dist/src/components/stc/index.d.ts +2 -2
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +2 -2
- package/dist/src/modifiers.d.ts +4 -10
- package/dist/src/modifiers.d.ts.map +1 -1
- package/dist/src/modifiers.js +32 -9
- package/dist/src/name-policy.d.ts +1 -1
- package/dist/src/name-policy.d.ts.map +1 -1
- package/dist/src/name-policy.js +0 -2
- package/dist/test/class-method.test.js +14 -37
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/class.test.js +298 -0
- package/dist/test/enum.test.js +12 -12
- package/dist/test/namespace.test.js +8 -8
- package/dist/test/projectdirectory.test.d.ts +2 -0
- package/dist/test/projectdirectory.test.d.ts.map +1 -0
- package/dist/test/{project-directory.test.js → projectdirectory.test.js} +8 -8
- package/dist/test/sourcefile.test.js +4 -4
- package/dist/test/using.test.js +9 -9
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -21
- package/src/components/{ClassDeclaration.tsx → Class.tsx} +43 -108
- package/src/components/ClassMethod.tsx +12 -53
- package/src/components/{EnumDeclaration.tsx → Enum.tsx} +6 -30
- package/src/components/Parameters.tsx +3 -10
- package/src/components/index.ts +3 -12
- package/src/components/stc/index.ts +2 -2
- package/src/modifiers.ts +42 -25
- package/src/name-policy.ts +0 -5
- package/temp/api.json +714 -5256
- package/test/class-method.test.tsx +14 -24
- package/test/class.test.tsx +292 -0
- package/test/enum.test.tsx +11 -11
- package/test/namespace.test.tsx +4 -4
- package/test/{project-directory.test.tsx → projectdirectory.test.tsx} +4 -4
- package/test/sourcefile.test.tsx +2 -2
- package/test/using.test.tsx +9 -9
- package/vitest.config.ts +0 -3
- package/LICENSE +0 -7
- package/dist/src/components/ClassDeclaration.d.ts +0 -74
- package/dist/src/components/ClassDeclaration.d.ts.map +0 -1
- package/dist/src/components/EnumDeclaration.d.ts +0 -34
- package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
- package/dist/src/components/doc/comment.d.ts +0 -70
- package/dist/src/components/doc/comment.d.ts.map +0 -1
- package/dist/src/components/doc/comment.js +0 -88
- package/dist/src/components/doc/comment.test.d.ts +0 -2
- package/dist/src/components/doc/comment.test.d.ts.map +0 -1
- package/dist/src/components/doc/comment.test.js +0 -348
- package/dist/src/components/doc/from-markdown.d.ts +0 -6
- package/dist/src/components/doc/from-markdown.d.ts.map +0 -1
- package/dist/src/components/doc/from-markdown.js +0 -58
- package/dist/src/components/doc/from-markdown.test.d.ts +0 -2
- package/dist/src/components/doc/from-markdown.test.d.ts.map +0 -1
- package/dist/src/components/doc/from-markdown.test.js +0 -83
- package/dist/src/components/interface/declaration.d.ts +0 -47
- package/dist/src/components/interface/declaration.d.ts.map +0 -1
- package/dist/src/components/interface/declaration.js +0 -77
- package/dist/src/components/interface/declaration.test.d.ts +0 -2
- package/dist/src/components/interface/declaration.test.d.ts.map +0 -1
- package/dist/src/components/interface/declaration.test.js +0 -153
- package/dist/src/components/interface/method.d.ts +0 -32
- package/dist/src/components/interface/method.d.ts.map +0 -1
- package/dist/src/components/interface/method.js +0 -69
- package/dist/src/components/interface/method.test.d.ts +0 -2
- package/dist/src/components/interface/method.test.d.ts.map +0 -1
- package/dist/src/components/interface/method.test.js +0 -254
- package/dist/src/components/interface/property.d.ts +0 -38
- package/dist/src/components/interface/property.d.ts.map +0 -1
- package/dist/src/components/interface/property.js +0 -67
- package/dist/src/components/interface/property.test.d.ts +0 -2
- package/dist/src/components/interface/property.test.d.ts.map +0 -1
- package/dist/src/components/interface/property.test.js +0 -165
- package/dist/src/components/property/property.d.ts +0 -57
- package/dist/src/components/property/property.d.ts.map +0 -1
- package/dist/src/components/property/property.js +0 -70
- package/dist/src/components/property/property.test.d.ts +0 -2
- package/dist/src/components/property/property.test.d.ts.map +0 -1
- package/dist/src/components/property/property.test.js +0 -218
- package/dist/src/components/record/declaration.d.ts +0 -35
- package/dist/src/components/record/declaration.d.ts.map +0 -1
- package/dist/src/components/record/declaration.js +0 -90
- package/dist/src/components/record/declaration.test.d.ts +0 -2
- package/dist/src/components/record/declaration.test.d.ts.map +0 -1
- package/dist/src/components/record/declaration.test.js +0 -94
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +0 -8
- package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter-constraints.js +0 -44
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +0 -2
- package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter-constraints.test.js +0 -67
- package/dist/src/components/type-parameters/type-parameter.d.ts +0 -20
- package/dist/src/components/type-parameters/type-parameter.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameter.js +0 -22
- package/dist/src/components/type-parameters/type-parameters.d.ts +0 -17
- package/dist/src/components/type-parameters/type-parameters.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameters.js +0 -65
- package/dist/src/components/type-parameters/type-parameters.test.d.ts +0 -2
- package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +0 -1
- package/dist/src/components/type-parameters/type-parameters.test.js +0 -26
- package/dist/src/components/var/declaration.d.ts +0 -35
- package/dist/src/components/var/declaration.d.ts.map +0 -1
- package/dist/src/components/var/declaration.js +0 -40
- package/dist/src/components/var/declaration.test.d.ts +0 -2
- package/dist/src/components/var/declaration.test.d.ts.map +0 -1
- package/dist/src/components/var/declaration.test.js +0 -73
- package/dist/test/class-declaration.test.d.ts +0 -2
- package/dist/test/class-declaration.test.d.ts.map +0 -1
- package/dist/test/class-declaration.test.js +0 -463
- package/dist/test/project-directory.test.d.ts +0 -2
- package/dist/test/project-directory.test.d.ts.map +0 -1
- package/dist/test/vitest.setup.d.ts +0 -2
- package/dist/test/vitest.setup.d.ts.map +0 -1
- package/dist/test/vitest.setup.js +0 -1
- package/src/components/doc/comment.test.tsx +0 -337
- package/src/components/doc/comment.tsx +0 -152
- package/src/components/doc/from-markdown.test.tsx +0 -103
- package/src/components/doc/from-markdown.tsx +0 -58
- package/src/components/interface/declaration.test.tsx +0 -143
- package/src/components/interface/declaration.tsx +0 -105
- package/src/components/interface/method.test.tsx +0 -250
- package/src/components/interface/method.tsx +0 -105
- package/src/components/interface/property.test.tsx +0 -144
- package/src/components/interface/property.tsx +0 -107
- package/src/components/property/property.test.tsx +0 -187
- package/src/components/property/property.tsx +0 -146
- package/src/components/record/declaration.test.tsx +0 -73
- package/src/components/record/declaration.tsx +0 -109
- package/src/components/type-parameters/type-parameter-constraints.test.tsx +0 -93
- package/src/components/type-parameters/type-parameter-constraints.tsx +0 -46
- package/src/components/type-parameters/type-parameter.tsx +0 -35
- package/src/components/type-parameters/type-parameters.test.tsx +0 -19
- package/src/components/type-parameters/type-parameters.tsx +0 -72
- package/src/components/var/declaration.test.tsx +0 -59
- package/src/components/var/declaration.tsx +0 -47
- package/test/class-declaration.test.tsx +0 -418
- package/test/vitest.setup.ts +0 -1
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
import { createComponent as _$createComponent, mergeProps as _$mergeProps, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import * as core from "@alloy-js/core";
|
|
3
|
-
import { List, refkey } from "@alloy-js/core";
|
|
4
|
-
import * as coretest from "@alloy-js/core/testing";
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
import * as csharp from "../src/index.js";
|
|
7
|
-
import { ClassDeclaration, ClassMember, Property, SourceFile } from "../src/index.js";
|
|
8
|
-
import * as utils from "./utils.js";
|
|
9
|
-
it("declares class with no members", () => {
|
|
10
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
11
|
-
get children() {
|
|
12
|
-
return _$createComponent(ClassDeclaration, {
|
|
13
|
-
name: "TestClass"
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
})).toRenderTo(`
|
|
17
|
-
class TestClass;
|
|
18
|
-
`);
|
|
19
|
-
});
|
|
20
|
-
describe("modifiers", () => {
|
|
21
|
-
it.each(["public", "private"])("%s", mod => {
|
|
22
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
23
|
-
get children() {
|
|
24
|
-
return _$createComponent(ClassDeclaration, _$mergeProps({
|
|
25
|
-
[mod]: true
|
|
26
|
-
}, {
|
|
27
|
-
name: "TestClass"
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
})).toRenderTo(`
|
|
31
|
-
${mod} class TestClass;
|
|
32
|
-
`);
|
|
33
|
-
});
|
|
34
|
-
it.each(["partial", "abstract", "static", "sealed"])("%s", mod => {
|
|
35
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
36
|
-
get children() {
|
|
37
|
-
return _$createComponent(ClassDeclaration, _$mergeProps({
|
|
38
|
-
[mod]: true
|
|
39
|
-
}, {
|
|
40
|
-
name: "TestClass"
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
})).toRenderTo(`
|
|
44
|
-
${mod} class TestClass;
|
|
45
|
-
`);
|
|
46
|
-
});
|
|
47
|
-
it("combines modifiers", () => {
|
|
48
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
49
|
-
get children() {
|
|
50
|
-
return _$createComponent(ClassDeclaration, {
|
|
51
|
-
"public": true,
|
|
52
|
-
abstract: true,
|
|
53
|
-
partial: true,
|
|
54
|
-
name: "TestClass"
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
})).toRenderTo(`
|
|
58
|
-
public abstract partial class TestClass;
|
|
59
|
-
`);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
describe("base", () => {
|
|
63
|
-
it("define base class", () => {
|
|
64
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
65
|
-
get children() {
|
|
66
|
-
return _$createComponent(csharp.ClassDeclaration, {
|
|
67
|
-
name: "TestClass",
|
|
68
|
-
baseType: "Foo"
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
})).toRenderTo(`
|
|
72
|
-
class TestClass : Foo;
|
|
73
|
-
`);
|
|
74
|
-
});
|
|
75
|
-
it("define multiple interface types", () => {
|
|
76
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
77
|
-
get children() {
|
|
78
|
-
return _$createComponent(csharp.ClassDeclaration, {
|
|
79
|
-
name: "TestClass",
|
|
80
|
-
interfaceTypes: ["Foo", "Bar"]
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
})).toRenderTo(`
|
|
84
|
-
class TestClass : Foo, Bar;
|
|
85
|
-
`);
|
|
86
|
-
});
|
|
87
|
-
it("define base class and multiple interface types", () => {
|
|
88
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
89
|
-
get children() {
|
|
90
|
-
return _$createComponent(csharp.ClassDeclaration, {
|
|
91
|
-
name: "TestClass",
|
|
92
|
-
baseType: "BaseClass",
|
|
93
|
-
interfaceTypes: ["Foo", "Bar"]
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
})).toRenderTo(`
|
|
97
|
-
class TestClass : BaseClass, Foo, Bar;
|
|
98
|
-
`);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
it("declares class with some members", () => {
|
|
102
|
-
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
103
|
-
"public": true,
|
|
104
|
-
name: "TestClass",
|
|
105
|
-
get children() {
|
|
106
|
-
return _$createComponent(core.StatementList, {
|
|
107
|
-
get children() {
|
|
108
|
-
return [_$createComponent(csharp.ClassMember, {
|
|
109
|
-
"public": true,
|
|
110
|
-
name: "MemberOne",
|
|
111
|
-
type: "string"
|
|
112
|
-
}), _$createComponent(csharp.ClassMember, {
|
|
113
|
-
"private": true,
|
|
114
|
-
name: "MemberTwo",
|
|
115
|
-
type: "int"
|
|
116
|
-
})];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}));
|
|
121
|
-
expect(res).toBe(coretest.d`
|
|
122
|
-
namespace TestCode
|
|
123
|
-
{
|
|
124
|
-
public class TestClass
|
|
125
|
-
{
|
|
126
|
-
public string MemberOne;
|
|
127
|
-
private int memberTwo;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
`);
|
|
131
|
-
});
|
|
132
|
-
it("declares class with some methods", () => {
|
|
133
|
-
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
134
|
-
"public": true,
|
|
135
|
-
name: "TestClass",
|
|
136
|
-
get children() {
|
|
137
|
-
return _$createComponent(core.List, {
|
|
138
|
-
get children() {
|
|
139
|
-
return [_$createComponent(csharp.ClassMethod, {
|
|
140
|
-
"public": true,
|
|
141
|
-
name: "MethodOne"
|
|
142
|
-
}), _$createComponent(csharp.ClassMethod, {
|
|
143
|
-
"private": true,
|
|
144
|
-
virtual: true,
|
|
145
|
-
name: "MethodTwo"
|
|
146
|
-
})];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}));
|
|
151
|
-
expect(res).toBe(coretest.d`
|
|
152
|
-
namespace TestCode
|
|
153
|
-
{
|
|
154
|
-
public class TestClass
|
|
155
|
-
{
|
|
156
|
-
public void MethodOne() {}
|
|
157
|
-
private virtual void MethodTwo() {}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
`);
|
|
161
|
-
});
|
|
162
|
-
it("uses refkeys for members, params, and return type", () => {
|
|
163
|
-
const inputTypeRefkey = core.refkey();
|
|
164
|
-
const testResultTypeRefkey = core.refkey();
|
|
165
|
-
const enumTypeRefkey = core.refkey();
|
|
166
|
-
const params = [{
|
|
167
|
-
name: "IntParam",
|
|
168
|
-
type: "int"
|
|
169
|
-
}, {
|
|
170
|
-
name: "BodyParam",
|
|
171
|
-
type: inputTypeRefkey
|
|
172
|
-
}];
|
|
173
|
-
const res = core.render(_$createComponent(core.Output, {
|
|
174
|
-
get namePolicy() {
|
|
175
|
-
return csharp.createCSharpNamePolicy();
|
|
176
|
-
},
|
|
177
|
-
get children() {
|
|
178
|
-
return _$createComponent(csharp.Namespace, {
|
|
179
|
-
name: "TestCode",
|
|
180
|
-
get children() {
|
|
181
|
-
return _$createComponent(csharp.SourceFile, {
|
|
182
|
-
path: "Test.cs",
|
|
183
|
-
get children() {
|
|
184
|
-
return [_$createComponent(csharp.EnumDeclaration, {
|
|
185
|
-
"public": true,
|
|
186
|
-
name: "TestEnum",
|
|
187
|
-
refkey: enumTypeRefkey,
|
|
188
|
-
get children() {
|
|
189
|
-
return _$createComponent(core.List, {
|
|
190
|
-
comma: true,
|
|
191
|
-
hardline: true,
|
|
192
|
-
get children() {
|
|
193
|
-
return [_$createComponent(csharp.EnumMember, {
|
|
194
|
-
name: "One"
|
|
195
|
-
}), _$createComponent(csharp.EnumMember, {
|
|
196
|
-
name: "Two"
|
|
197
|
-
})];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
|
|
202
|
-
"public": true,
|
|
203
|
-
name: "TestInput",
|
|
204
|
-
refkey: inputTypeRefkey
|
|
205
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
|
|
206
|
-
"public": true,
|
|
207
|
-
name: "TestResult",
|
|
208
|
-
refkey: testResultTypeRefkey
|
|
209
|
-
}), _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassDeclaration, {
|
|
210
|
-
"public": true,
|
|
211
|
-
name: "TestClass",
|
|
212
|
-
get children() {
|
|
213
|
-
return [_$createComponent(csharp.ClassMember, {
|
|
214
|
-
"private": true,
|
|
215
|
-
name: "MemberOne",
|
|
216
|
-
type: enumTypeRefkey
|
|
217
|
-
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMethod, {
|
|
218
|
-
"public": true,
|
|
219
|
-
name: "MethodOne",
|
|
220
|
-
parameters: params,
|
|
221
|
-
returns: testResultTypeRefkey,
|
|
222
|
-
get children() {
|
|
223
|
-
return ["return new ", testResultTypeRefkey, "();"];
|
|
224
|
-
}
|
|
225
|
-
})];
|
|
226
|
-
}
|
|
227
|
-
})];
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
}));
|
|
234
|
-
expect(res.contents[0].contents).toBe(coretest.d`
|
|
235
|
-
namespace TestCode
|
|
236
|
-
{
|
|
237
|
-
public enum TestEnum
|
|
238
|
-
{
|
|
239
|
-
One,
|
|
240
|
-
Two
|
|
241
|
-
}
|
|
242
|
-
public class TestInput;
|
|
243
|
-
public class TestResult;
|
|
244
|
-
public class TestClass
|
|
245
|
-
{
|
|
246
|
-
private TestEnum memberOne;
|
|
247
|
-
public TestResult MethodOne(int intParam, TestInput bodyParam)
|
|
248
|
-
{
|
|
249
|
-
return new TestResult();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
`);
|
|
254
|
-
});
|
|
255
|
-
describe("with type parameters", () => {
|
|
256
|
-
it("reference parameters", () => {
|
|
257
|
-
const typeParameters = [{
|
|
258
|
-
name: "T",
|
|
259
|
-
refkey: refkey()
|
|
260
|
-
}, {
|
|
261
|
-
name: "U",
|
|
262
|
-
refkey: refkey()
|
|
263
|
-
}];
|
|
264
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
265
|
-
get children() {
|
|
266
|
-
return _$createComponent(SourceFile, {
|
|
267
|
-
path: "Test.cs",
|
|
268
|
-
get children() {
|
|
269
|
-
return _$createComponent(ClassDeclaration, {
|
|
270
|
-
"public": true,
|
|
271
|
-
name: "TestClass",
|
|
272
|
-
typeParameters: typeParameters,
|
|
273
|
-
get children() {
|
|
274
|
-
return _$createComponent(List, {
|
|
275
|
-
get children() {
|
|
276
|
-
return [_$createComponent(Property, {
|
|
277
|
-
name: "PropA",
|
|
278
|
-
get type() {
|
|
279
|
-
return typeParameters[0].refkey;
|
|
280
|
-
},
|
|
281
|
-
get: true,
|
|
282
|
-
set: true
|
|
283
|
-
}), _$createComponent(Property, {
|
|
284
|
-
name: "PropB",
|
|
285
|
-
get type() {
|
|
286
|
-
return typeParameters[1].refkey;
|
|
287
|
-
},
|
|
288
|
-
get: true,
|
|
289
|
-
set: true
|
|
290
|
-
})];
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
})).toRenderTo(`
|
|
299
|
-
namespace TestCode
|
|
300
|
-
{
|
|
301
|
-
public class TestClass<T, U>
|
|
302
|
-
{
|
|
303
|
-
T PropA { get; set; }
|
|
304
|
-
U PropB { get; set; }
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
`);
|
|
308
|
-
});
|
|
309
|
-
it("defines with constraints", () => {
|
|
310
|
-
const typeParameters = [{
|
|
311
|
-
name: "T",
|
|
312
|
-
constraints: "IFoo"
|
|
313
|
-
}, {
|
|
314
|
-
name: "U",
|
|
315
|
-
constraints: "IBar"
|
|
316
|
-
}];
|
|
317
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
318
|
-
get children() {
|
|
319
|
-
return _$createComponent(ClassDeclaration, {
|
|
320
|
-
"public": true,
|
|
321
|
-
name: "TestClass",
|
|
322
|
-
typeParameters: typeParameters,
|
|
323
|
-
children: "// Body"
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
})).toRenderTo(`
|
|
327
|
-
public class TestClass<T, U>
|
|
328
|
-
where T : IFoo
|
|
329
|
-
where U : IBar
|
|
330
|
-
{
|
|
331
|
-
// Body
|
|
332
|
-
}
|
|
333
|
-
`);
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
it("declares class with invalid members", () => {
|
|
337
|
-
const decl = _$createComponent(csharp.ClassDeclaration, {
|
|
338
|
-
"public": true,
|
|
339
|
-
name: "TestClass",
|
|
340
|
-
get children() {
|
|
341
|
-
return [_$createComponent(csharp.EnumMember, {
|
|
342
|
-
name: "One"
|
|
343
|
-
}), ",", _$createIntrinsic("hbr", {}), _$createComponent(csharp.EnumMember, {
|
|
344
|
-
name: "Two"
|
|
345
|
-
})];
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
expect(() => utils.toSourceText(decl)).toThrow("can't define an enum member outside of an enum-decl scope");
|
|
349
|
-
});
|
|
350
|
-
it("declares class with constructor", () => {
|
|
351
|
-
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
352
|
-
"public": true,
|
|
353
|
-
name: "TestClass",
|
|
354
|
-
get children() {
|
|
355
|
-
return _$createComponent(csharp.ClassConstructor, {
|
|
356
|
-
"public": true
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
}));
|
|
360
|
-
expect(res).toBe(coretest.d`
|
|
361
|
-
namespace TestCode
|
|
362
|
-
{
|
|
363
|
-
public class TestClass
|
|
364
|
-
{
|
|
365
|
-
public TestClass() {}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
`);
|
|
369
|
-
});
|
|
370
|
-
it("declares class with constructor params and assigns values to fields", () => {
|
|
371
|
-
const thisNameRefkey = core.refkey();
|
|
372
|
-
const thisSizeRefkey = core.refkey();
|
|
373
|
-
const paramNameRefkey = core.refkey();
|
|
374
|
-
const paramSizeRefkey = core.refkey();
|
|
375
|
-
const ctorParams = [{
|
|
376
|
-
name: "name",
|
|
377
|
-
type: "string",
|
|
378
|
-
refkey: paramNameRefkey
|
|
379
|
-
}, {
|
|
380
|
-
name: "size",
|
|
381
|
-
type: "int",
|
|
382
|
-
refkey: paramSizeRefkey
|
|
383
|
-
}];
|
|
384
|
-
const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
|
|
385
|
-
"public": true,
|
|
386
|
-
name: "TestClass",
|
|
387
|
-
get children() {
|
|
388
|
-
return [_$createComponent(csharp.ClassMember, {
|
|
389
|
-
"private": true,
|
|
390
|
-
name: "name",
|
|
391
|
-
type: "string",
|
|
392
|
-
refkey: thisNameRefkey
|
|
393
|
-
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMember, {
|
|
394
|
-
"private": true,
|
|
395
|
-
name: "size",
|
|
396
|
-
type: "int",
|
|
397
|
-
refkey: thisSizeRefkey
|
|
398
|
-
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassConstructor, {
|
|
399
|
-
"public": true,
|
|
400
|
-
parameters: ctorParams,
|
|
401
|
-
get children() {
|
|
402
|
-
return [thisNameRefkey, " = ", paramNameRefkey, ";", _$createIntrinsic("hbr", {}), thisSizeRefkey, " = ", paramSizeRefkey, ";"];
|
|
403
|
-
}
|
|
404
|
-
})];
|
|
405
|
-
}
|
|
406
|
-
}));
|
|
407
|
-
|
|
408
|
-
// TODO: assignments to members should have this. prefix
|
|
409
|
-
// e.g. this.name = name;
|
|
410
|
-
expect(res).toBe(coretest.d`
|
|
411
|
-
namespace TestCode
|
|
412
|
-
{
|
|
413
|
-
public class TestClass
|
|
414
|
-
{
|
|
415
|
-
private string name;
|
|
416
|
-
private int size;
|
|
417
|
-
public TestClass(string name, int size)
|
|
418
|
-
{
|
|
419
|
-
name = name;
|
|
420
|
-
size = size;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
`);
|
|
425
|
-
});
|
|
426
|
-
it("specify doc comment", () => {
|
|
427
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
428
|
-
get children() {
|
|
429
|
-
return _$createComponent(ClassDeclaration, {
|
|
430
|
-
name: "Test",
|
|
431
|
-
doc: "This is a test"
|
|
432
|
-
});
|
|
433
|
-
}
|
|
434
|
-
})).toRenderTo(`
|
|
435
|
-
/// This is a test
|
|
436
|
-
class Test;
|
|
437
|
-
`);
|
|
438
|
-
});
|
|
439
|
-
it("supports class member doc comments", () => {
|
|
440
|
-
expect(_$createComponent(utils.TestNamespace, {
|
|
441
|
-
get children() {
|
|
442
|
-
return _$createComponent(ClassDeclaration, {
|
|
443
|
-
name: "Test",
|
|
444
|
-
doc: "This is a test",
|
|
445
|
-
get children() {
|
|
446
|
-
return _$createComponent(ClassMember, {
|
|
447
|
-
name: "Member",
|
|
448
|
-
"public": true,
|
|
449
|
-
type: "int",
|
|
450
|
-
doc: "This is a member"
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
})).toRenderTo(`
|
|
456
|
-
/// This is a test
|
|
457
|
-
class Test
|
|
458
|
-
{
|
|
459
|
-
/// This is a member
|
|
460
|
-
public int Member
|
|
461
|
-
}
|
|
462
|
-
`);
|
|
463
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"project-directory.test.d.ts","sourceRoot":"","sources":["../../test/project-directory.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.setup.d.ts","sourceRoot":"","sources":["../../test/vitest.setup.ts"],"names":[],"mappings":"AAAA,OAAO,wBAAwB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "@alloy-js/core/testing";
|