@typespec/emitter-framework 0.11.0-dev.7 → 0.11.0-dev.9
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/core/components/index.js +2 -1
- package/dist/src/core/components/index.js.map +1 -0
- package/dist/src/core/components/output.js +2 -1
- package/dist/src/core/components/output.js.map +1 -0
- package/dist/src/core/components/overrides/component-overrides.js +2 -1
- package/dist/src/core/components/overrides/component-overrides.js.map +1 -0
- package/dist/src/core/components/overrides/config.js +2 -1
- package/dist/src/core/components/overrides/config.js.map +1 -0
- package/dist/src/core/components/overrides/context.js +2 -1
- package/dist/src/core/components/overrides/context.js.map +1 -0
- package/dist/src/core/context/index.js +2 -1
- package/dist/src/core/context/index.js.map +1 -0
- package/dist/src/core/context/name-policy-context.js +2 -1
- package/dist/src/core/context/name-policy-context.js.map +1 -0
- package/dist/src/core/context/tsp-context.js +2 -1
- package/dist/src/core/context/tsp-context.js.map +1 -0
- package/dist/src/core/index.js +2 -1
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/transport-name-policy.js +2 -1
- package/dist/src/core/transport-name-policy.js.map +1 -0
- package/dist/src/core/write-output.js +2 -1
- package/dist/src/core/write-output.js.map +1 -0
- package/dist/src/csharp/components/class/declaration.js +3 -2
- package/dist/src/csharp/components/class/declaration.js.map +1 -0
- package/dist/src/csharp/components/class/declaration.test.js +65 -105
- package/dist/src/csharp/components/class/declaration.test.js.map +1 -0
- package/dist/src/csharp/components/enum/declaration.js +2 -1
- package/dist/src/csharp/components/enum/declaration.js.map +1 -0
- package/dist/src/csharp/components/enum/declaration.test.js +52 -88
- package/dist/src/csharp/components/enum/declaration.test.js.map +1 -0
- package/dist/src/csharp/components/index.js +2 -1
- package/dist/src/csharp/components/index.js.map +1 -0
- package/dist/src/csharp/components/property/property.js +2 -1
- package/dist/src/csharp/components/property/property.js.map +1 -0
- package/dist/src/csharp/components/property/property.test.js +48 -73
- package/dist/src/csharp/components/property/property.test.js.map +1 -0
- package/dist/src/csharp/components/type-expression.js +2 -1
- package/dist/src/csharp/components/type-expression.js.map +1 -0
- package/dist/src/csharp/components/type-expression.test.js +46 -74
- package/dist/src/csharp/components/type-expression.test.js.map +1 -0
- package/dist/src/csharp/components/utils/doc-comments.js +2 -1
- package/dist/src/csharp/components/utils/doc-comments.js.map +1 -0
- package/dist/src/csharp/components/utils/nullable-util.js +2 -1
- package/dist/src/csharp/components/utils/nullable-util.js.map +1 -0
- package/dist/src/csharp/components/utils/refkey.js +2 -1
- package/dist/src/csharp/components/utils/refkey.js.map +1 -0
- package/dist/src/csharp/index.js +2 -1
- package/dist/src/csharp/index.js.map +1 -0
- package/dist/src/lib.js +2 -1
- package/dist/src/lib.js.map +1 -0
- package/dist/src/testing/index.js +2 -1
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.js +2 -1
- package/dist/src/testing/scenario-test/code-block-expectation.js.map +1 -0
- package/dist/src/testing/scenario-test/code-block-expectation.test.js +2 -1
- package/dist/src/testing/scenario-test/code-block-expectation.test.js.map +1 -0
- package/dist/src/testing/scenario-test/harness.js +2 -1
- package/dist/src/testing/scenario-test/harness.js.map +1 -0
- package/dist/src/testing/scenario-test/index.js +2 -1
- package/dist/src/testing/scenario-test/index.js.map +1 -0
- package/dist/src/testing/scenario-test/snippet-extractor.js +2 -1
- package/dist/src/testing/scenario-test/snippet-extractor.js.map +1 -0
- package/dist/src/typescript/components/array-expression.js +2 -1
- package/dist/src/typescript/components/array-expression.js.map +1 -0
- package/dist/src/typescript/components/arrow-function.js +2 -1
- package/dist/src/typescript/components/arrow-function.js.map +1 -0
- package/dist/src/typescript/components/class-method.js +2 -1
- package/dist/src/typescript/components/class-method.js.map +1 -0
- package/dist/src/typescript/components/enum-declaration.js +2 -1
- package/dist/src/typescript/components/enum-declaration.js.map +1 -0
- package/dist/src/typescript/components/function-declaration.js +2 -1
- package/dist/src/typescript/components/function-declaration.js.map +1 -0
- package/dist/src/typescript/components/function-expression.js +2 -1
- package/dist/src/typescript/components/function-expression.js.map +1 -0
- package/dist/src/typescript/components/function-type.js +2 -1
- package/dist/src/typescript/components/function-type.js.map +1 -0
- package/dist/src/typescript/components/index.js +2 -1
- package/dist/src/typescript/components/index.js.map +1 -0
- package/dist/src/typescript/components/interface-declaration.js +2 -1
- package/dist/src/typescript/components/interface-declaration.js.map +1 -0
- package/dist/src/typescript/components/interface-member.js +2 -1
- package/dist/src/typescript/components/interface-member.js.map +1 -0
- package/dist/src/typescript/components/interface-method.js +2 -1
- package/dist/src/typescript/components/interface-method.js.map +1 -0
- package/dist/src/typescript/components/record-expression.js +2 -1
- package/dist/src/typescript/components/record-expression.js.map +1 -0
- package/dist/src/typescript/components/static-serializers.js +2 -1
- package/dist/src/typescript/components/static-serializers.js.map +1 -0
- package/dist/src/typescript/components/type-alias-declaration.js +2 -1
- package/dist/src/typescript/components/type-alias-declaration.js.map +1 -0
- package/dist/src/typescript/components/type-declaration.js +2 -1
- package/dist/src/typescript/components/type-declaration.js.map +1 -0
- package/dist/src/typescript/components/type-expression.js +2 -1
- package/dist/src/typescript/components/type-expression.js.map +1 -0
- package/dist/src/typescript/components/type-transform.js +2 -1
- package/dist/src/typescript/components/type-transform.js.map +1 -0
- package/dist/src/typescript/components/union/declaration.js +2 -1
- package/dist/src/typescript/components/union/declaration.js.map +1 -0
- package/dist/src/typescript/components/union/declaration.test.js +2 -1
- package/dist/src/typescript/components/union/declaration.test.js.map +1 -0
- package/dist/src/typescript/components/union/expression.js +2 -1
- package/dist/src/typescript/components/union/expression.js.map +1 -0
- package/dist/src/typescript/components/union/expression.test.js +2 -1
- package/dist/src/typescript/components/union/expression.test.js.map +1 -0
- package/dist/src/typescript/components/value-expression.js +2 -1
- package/dist/src/typescript/components/value-expression.js.map +1 -0
- package/dist/src/typescript/index.js +2 -1
- package/dist/src/typescript/index.js.map +1 -0
- package/dist/src/typescript/lib.js +2 -1
- package/dist/src/typescript/lib.js.map +1 -0
- package/dist/src/typescript/utils/index.js +2 -1
- package/dist/src/typescript/utils/index.js.map +1 -0
- package/dist/src/typescript/utils/operation.js +2 -1
- package/dist/src/typescript/utils/operation.js.map +1 -0
- package/dist/src/typescript/utils/refkey.js +2 -1
- package/dist/src/typescript/utils/refkey.js.map +1 -0
- package/dist/test/test-host.js +2 -1
- package/dist/test/test-host.js.map +1 -0
- package/dist/test/testing/snippet-extractor-csharp.test.js +2 -1
- package/dist/test/testing/snippet-extractor-csharp.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-java.test.js +2 -1
- package/dist/test/testing/snippet-extractor-java.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-python.test.js +2 -1
- package/dist/test/testing/snippet-extractor-python.test.js.map +1 -0
- package/dist/test/testing/snippet-extractor-typescript.test.js +2 -1
- package/dist/test/testing/snippet-extractor-typescript.test.js.map +1 -0
- package/dist/test/typescript/components/arrow-function.test.js +9 -14
- package/dist/test/typescript/components/arrow-function.test.js.map +1 -0
- package/dist/test/typescript/components/component-override.test.js +2 -1
- package/dist/test/typescript/components/component-override.test.js.map +1 -0
- package/dist/test/typescript/components/enum-declaration.test.js +2 -1
- package/dist/test/typescript/components/enum-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/function-declaration.test.js +2 -1
- package/dist/test/typescript/components/function-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/function-expression.test.js +9 -14
- package/dist/test/typescript/components/function-expression.test.js.map +1 -0
- package/dist/test/typescript/components/function-type.test.js +9 -14
- package/dist/test/typescript/components/function-type.test.js.map +1 -0
- package/dist/test/typescript/components/interface-declaration.test.js +2 -1
- package/dist/test/typescript/components/interface-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/interface-method.test.js +19 -29
- package/dist/test/typescript/components/interface-method.test.js.map +1 -0
- package/dist/test/typescript/components/member-expression.test.js +2 -1
- package/dist/test/typescript/components/member-expression.test.js.map +1 -0
- package/dist/test/typescript/components/type-alias-declaration.test.js +2 -1
- package/dist/test/typescript/components/type-alias-declaration.test.js.map +1 -0
- package/dist/test/typescript/components/type-transform.test.js +2 -1
- package/dist/test/typescript/components/type-transform.test.js.map +1 -0
- package/dist/test/typescript/components/value-expression.test.js +2 -1
- package/dist/test/typescript/components/value-expression.test.js.map +1 -0
- package/dist/test/typescript/test-host.js +2 -1
- package/dist/test/typescript/test-host.js.map +1 -0
- package/dist/test/typescript/utils.js +2 -1
- package/dist/test/typescript/utils.js.map +1 -0
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +5 -2
- package/dist/test/utils.js.map +1 -0
- package/dist/test/vitest.setup.js +2 -1
- package/dist/test/vitest.setup.js.map +1 -0
- package/package.json +7 -7
- package/src/csharp/components/class/declaration.test.tsx +64 -102
- package/src/csharp/components/class/declaration.tsx +1 -1
- package/src/csharp/components/enum/declaration.test.tsx +47 -78
- package/src/csharp/components/property/property.test.tsx +44 -67
- package/src/csharp/components/type-expression.test.tsx +44 -93
- package/test/typescript/components/arrow-function.test.tsx +10 -28
- package/test/typescript/components/function-expression.test.tsx +10 -28
- package/test/typescript/components/function-type.test.tsx +10 -28
- package/test/typescript/components/interface-method.test.tsx +25 -68
- package/test/utils.ts +3 -1
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import { Tester } from "#test/test-host.js";
|
|
6
6
|
import { List, type Children } from "@alloy-js/core";
|
|
7
7
|
import { d } from "@alloy-js/core/testing";
|
|
8
|
-
import { createCSharpNamePolicy,
|
|
8
|
+
import { createCSharpNamePolicy, SourceFile } from "@alloy-js/csharp";
|
|
9
9
|
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
10
10
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
11
11
|
import { Output } from "../../../core/index.js";
|
|
@@ -21,9 +21,7 @@ function Wrapper(props: { children: Children }) {
|
|
|
21
21
|
const policy = createCSharpNamePolicy();
|
|
22
22
|
return (
|
|
23
23
|
<Output program={runner.program} namePolicy={policy}>
|
|
24
|
-
<
|
|
25
|
-
<SourceFile path="test.cs">{props.children}</SourceFile>
|
|
26
|
-
</Namespace>
|
|
24
|
+
<SourceFile path="test.cs">{props.children}</SourceFile>
|
|
27
25
|
</Output>
|
|
28
26
|
);
|
|
29
27
|
}
|
|
@@ -38,12 +36,9 @@ it("renders an empty class declaration", async () => {
|
|
|
38
36
|
<ClassDeclaration type={TestModel} />
|
|
39
37
|
</Wrapper>,
|
|
40
38
|
).toRenderTo(`
|
|
41
|
-
|
|
39
|
+
class TestModel
|
|
42
40
|
{
|
|
43
|
-
class TestModel
|
|
44
|
-
{
|
|
45
41
|
|
|
46
|
-
}
|
|
47
42
|
}
|
|
48
43
|
`);
|
|
49
44
|
});
|
|
@@ -61,13 +56,11 @@ it("renders a class declaration with properties", async () => {
|
|
|
61
56
|
<ClassDeclaration type={TestModel} />
|
|
62
57
|
</Wrapper>,
|
|
63
58
|
).toRenderTo(`
|
|
64
|
-
|
|
59
|
+
class TestModel
|
|
65
60
|
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
public required int Prop2 { get; set; }
|
|
70
|
-
}
|
|
61
|
+
public required string Prop1 { get; set; }
|
|
62
|
+
|
|
63
|
+
public required int Prop2 { get; set; }
|
|
71
64
|
}
|
|
72
65
|
`);
|
|
73
66
|
});
|
|
@@ -94,22 +87,21 @@ it("renders a class declaration with properties using component override", async
|
|
|
94
87
|
</TestClientOverrides>
|
|
95
88
|
</Wrapper>,
|
|
96
89
|
).toRenderTo(d`
|
|
97
|
-
|
|
90
|
+
class Foo
|
|
91
|
+
{
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
class Bar
|
|
98
95
|
{
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{
|
|
109
|
-
public required string Prop1 { get; set; }
|
|
110
|
-
public required int Prop2 { get; set; }
|
|
111
|
-
public Bar? Prop3 { get; set; }
|
|
112
|
-
}
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
class TestModel
|
|
99
|
+
{
|
|
100
|
+
public required string Prop1 { get; set; }
|
|
101
|
+
|
|
102
|
+
public required int Prop2 { get; set; }
|
|
103
|
+
|
|
104
|
+
public Bar? Prop3 { get; set; }
|
|
113
105
|
}
|
|
114
106
|
`);
|
|
115
107
|
});
|
|
@@ -141,12 +133,9 @@ it("can override class name", async () => {
|
|
|
141
133
|
<ClassDeclaration type={TestModel} name="CustomClassName" />
|
|
142
134
|
</Wrapper>,
|
|
143
135
|
).toRenderTo(`
|
|
144
|
-
|
|
136
|
+
class CustomClassName
|
|
145
137
|
{
|
|
146
|
-
class CustomClassName
|
|
147
|
-
{
|
|
148
138
|
|
|
149
|
-
}
|
|
150
139
|
}
|
|
151
140
|
`);
|
|
152
141
|
});
|
|
@@ -162,12 +151,9 @@ it("renders a class with access modifiers", async () => {
|
|
|
162
151
|
<ClassDeclaration type={TestModel} protected />
|
|
163
152
|
</Wrapper>,
|
|
164
153
|
).toRenderTo(`
|
|
165
|
-
|
|
154
|
+
protected class TestModel
|
|
166
155
|
{
|
|
167
|
-
protected class TestModel
|
|
168
|
-
{
|
|
169
156
|
|
|
170
|
-
}
|
|
171
157
|
}
|
|
172
158
|
`);
|
|
173
159
|
});
|
|
@@ -184,12 +170,9 @@ describe("from an interface", () => {
|
|
|
184
170
|
<ClassDeclaration type={TestInterface} />
|
|
185
171
|
</Wrapper>,
|
|
186
172
|
).toRenderTo(`
|
|
187
|
-
|
|
173
|
+
class TestInterface
|
|
188
174
|
{
|
|
189
|
-
class TestInterface
|
|
190
|
-
{
|
|
191
175
|
|
|
192
|
-
}
|
|
193
176
|
}
|
|
194
177
|
`);
|
|
195
178
|
});
|
|
@@ -206,12 +189,9 @@ describe("from an interface", () => {
|
|
|
206
189
|
<ClassDeclaration type={TestInterface} />
|
|
207
190
|
</Wrapper>,
|
|
208
191
|
).toRenderTo(`
|
|
209
|
-
|
|
192
|
+
class TestInterface
|
|
210
193
|
{
|
|
211
|
-
|
|
212
|
-
{
|
|
213
|
-
public abstract string GetName(string id);
|
|
214
|
-
}
|
|
194
|
+
public abstract string GetName(string id);
|
|
215
195
|
}
|
|
216
196
|
`);
|
|
217
197
|
});
|
|
@@ -232,16 +212,13 @@ it("renders a class with model members", async () => {
|
|
|
232
212
|
<ClassDeclaration type={TestModel} />
|
|
233
213
|
</Wrapper>,
|
|
234
214
|
).toRenderTo(`
|
|
235
|
-
|
|
215
|
+
class TestReference
|
|
216
|
+
{
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
class TestModel
|
|
236
220
|
{
|
|
237
|
-
|
|
238
|
-
{
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
class TestModel
|
|
242
|
-
{
|
|
243
|
-
public required TestReference Prop1 { get; set; }
|
|
244
|
-
}
|
|
221
|
+
public required TestReference Prop1 { get; set; }
|
|
245
222
|
}
|
|
246
223
|
`);
|
|
247
224
|
});
|
|
@@ -264,17 +241,14 @@ it("renders a class with enum members", async () => {
|
|
|
264
241
|
<ClassDeclaration type={TestModel} />
|
|
265
242
|
</Wrapper>,
|
|
266
243
|
).toRenderTo(`
|
|
267
|
-
|
|
244
|
+
enum TestEnum
|
|
268
245
|
{
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
{
|
|
276
|
-
public required TestEnum Prop1 { get; set; }
|
|
277
|
-
}
|
|
246
|
+
Value1,
|
|
247
|
+
Value2
|
|
248
|
+
}
|
|
249
|
+
class TestModel
|
|
250
|
+
{
|
|
251
|
+
public required TestEnum Prop1 { get; set; }
|
|
278
252
|
}
|
|
279
253
|
`);
|
|
280
254
|
});
|
|
@@ -291,12 +265,9 @@ it("maps prop: string | null to nullable property", async () => {
|
|
|
291
265
|
<ClassDeclaration type={TestModel} />
|
|
292
266
|
</Wrapper>,
|
|
293
267
|
).toRenderTo(`
|
|
294
|
-
|
|
268
|
+
class TestModel
|
|
295
269
|
{
|
|
296
|
-
|
|
297
|
-
{
|
|
298
|
-
public required string? Prop1 { get; set; }
|
|
299
|
-
}
|
|
270
|
+
public required string? Prop1 { get; set; }
|
|
300
271
|
}
|
|
301
272
|
`);
|
|
302
273
|
});
|
|
@@ -319,17 +290,14 @@ it("renders a class with string enums", async () => {
|
|
|
319
290
|
<ClassDeclaration type={TestModel} />
|
|
320
291
|
</Wrapper>,
|
|
321
292
|
).toRenderTo(`
|
|
322
|
-
|
|
293
|
+
enum TestEnum
|
|
294
|
+
{
|
|
295
|
+
Value1,
|
|
296
|
+
Value2
|
|
297
|
+
}
|
|
298
|
+
class TestModel
|
|
323
299
|
{
|
|
324
|
-
|
|
325
|
-
{
|
|
326
|
-
Value1,
|
|
327
|
-
Value2
|
|
328
|
-
}
|
|
329
|
-
class TestModel
|
|
330
|
-
{
|
|
331
|
-
public required TestEnum Prop1 { get; set; }
|
|
332
|
-
}
|
|
300
|
+
public required TestEnum Prop1 { get; set; }
|
|
333
301
|
}
|
|
334
302
|
`);
|
|
335
303
|
});
|
|
@@ -350,18 +318,15 @@ describe("with doc comments", () => {
|
|
|
350
318
|
<ClassDeclaration type={TestModel} />
|
|
351
319
|
</Wrapper>,
|
|
352
320
|
).toRenderTo(`
|
|
353
|
-
|
|
321
|
+
/// <summary>
|
|
322
|
+
/// This is a test model
|
|
323
|
+
/// </summary>
|
|
324
|
+
class TestModel
|
|
354
325
|
{
|
|
355
326
|
/// <summary>
|
|
356
|
-
/// This is a test
|
|
327
|
+
/// This is a test property
|
|
357
328
|
/// </summary>
|
|
358
|
-
|
|
359
|
-
{
|
|
360
|
-
/// <summary>
|
|
361
|
-
/// This is a test property
|
|
362
|
-
/// </summary>
|
|
363
|
-
public required string Prop1 { get; set; }
|
|
364
|
-
}
|
|
329
|
+
public required string Prop1 { get; set; }
|
|
365
330
|
}
|
|
366
331
|
`);
|
|
367
332
|
});
|
|
@@ -381,22 +346,19 @@ describe("with doc comments", () => {
|
|
|
381
346
|
<ClassDeclaration type={TestInterface} />
|
|
382
347
|
</Wrapper>,
|
|
383
348
|
).toRenderTo(`
|
|
384
|
-
|
|
349
|
+
/// <summary>
|
|
350
|
+
/// This is a test interface
|
|
351
|
+
/// </summary>
|
|
352
|
+
class TestInterface
|
|
385
353
|
{
|
|
386
354
|
/// <summary>
|
|
387
|
-
/// This is a test
|
|
355
|
+
/// This is a test operation
|
|
388
356
|
/// </summary>
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
///
|
|
395
|
-
/// <returns>
|
|
396
|
-
/// The name of the item
|
|
397
|
-
/// </returns>
|
|
398
|
-
public abstract string GetName(string id);
|
|
399
|
-
}
|
|
357
|
+
///
|
|
358
|
+
/// <returns>
|
|
359
|
+
/// The name of the item
|
|
360
|
+
/// </returns>
|
|
361
|
+
public abstract string GetName(string id);
|
|
400
362
|
}
|
|
401
363
|
`);
|
|
402
364
|
});
|
|
@@ -64,7 +64,7 @@ function ClassProperties(props: ClassPropertiesProps): Children {
|
|
|
64
64
|
([_, p]) => !isVoidType(p.type),
|
|
65
65
|
);
|
|
66
66
|
return (
|
|
67
|
-
<For each={properties}
|
|
67
|
+
<For each={properties} doubleHardline>
|
|
68
68
|
{([name, property]) => <Property type={property} jsonAttributes={props.jsonAttributes} />}
|
|
69
69
|
</For>
|
|
70
70
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Tester } from "#test/test-host.js";
|
|
2
2
|
import { type Children } from "@alloy-js/core";
|
|
3
|
-
import { createCSharpNamePolicy,
|
|
3
|
+
import { createCSharpNamePolicy, SourceFile } from "@alloy-js/csharp";
|
|
4
4
|
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
5
5
|
import { beforeEach, expect, it } from "vitest";
|
|
6
6
|
import { Output } from "../../../core/index.js";
|
|
@@ -16,9 +16,7 @@ function Wrapper(props: { children: Children }) {
|
|
|
16
16
|
const policy = createCSharpNamePolicy();
|
|
17
17
|
return (
|
|
18
18
|
<Output program={runner.program} namePolicy={policy}>
|
|
19
|
-
<
|
|
20
|
-
<SourceFile path="test.cs">{props.children}</SourceFile>
|
|
21
|
-
</Namespace>
|
|
19
|
+
<SourceFile path="test.cs">{props.children}</SourceFile>
|
|
22
20
|
</Output>
|
|
23
21
|
);
|
|
24
22
|
}
|
|
@@ -37,14 +35,11 @@ it("renders a basic enum declaration", async () => {
|
|
|
37
35
|
<EnumDeclaration type={TestEnum} />
|
|
38
36
|
</Wrapper>,
|
|
39
37
|
).toRenderTo(`
|
|
40
|
-
|
|
38
|
+
enum TestEnum
|
|
41
39
|
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Value2,
|
|
46
|
-
Value3
|
|
47
|
-
}
|
|
40
|
+
Value1,
|
|
41
|
+
Value2,
|
|
42
|
+
Value3
|
|
48
43
|
}
|
|
49
44
|
`);
|
|
50
45
|
});
|
|
@@ -59,12 +54,9 @@ it("renders an empty enum declaration", async () => {
|
|
|
59
54
|
<EnumDeclaration type={TestEnum} />
|
|
60
55
|
</Wrapper>,
|
|
61
56
|
).toRenderTo(`
|
|
62
|
-
|
|
57
|
+
enum TestEnum
|
|
63
58
|
{
|
|
64
|
-
enum TestEnum
|
|
65
|
-
{
|
|
66
59
|
|
|
67
|
-
}
|
|
68
60
|
}
|
|
69
61
|
`);
|
|
70
62
|
});
|
|
@@ -82,13 +74,10 @@ it("can override enum name", async () => {
|
|
|
82
74
|
<EnumDeclaration type={TestEnum} name="CustomEnumName" />
|
|
83
75
|
</Wrapper>,
|
|
84
76
|
).toRenderTo(`
|
|
85
|
-
|
|
77
|
+
enum CustomEnumName
|
|
86
78
|
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Value1,
|
|
90
|
-
Value2
|
|
91
|
-
}
|
|
79
|
+
Value1,
|
|
80
|
+
Value2
|
|
92
81
|
}
|
|
93
82
|
`);
|
|
94
83
|
});
|
|
@@ -106,13 +95,10 @@ it("renders an enum with access modifiers", async () => {
|
|
|
106
95
|
<EnumDeclaration type={TestEnum} internal />
|
|
107
96
|
</Wrapper>,
|
|
108
97
|
).toRenderTo(`
|
|
109
|
-
|
|
98
|
+
internal enum TestEnum
|
|
110
99
|
{
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Value1,
|
|
114
|
-
Value2
|
|
115
|
-
}
|
|
100
|
+
Value1,
|
|
101
|
+
Value2
|
|
116
102
|
}
|
|
117
103
|
`);
|
|
118
104
|
});
|
|
@@ -128,21 +114,16 @@ it("renders enum with C# naming conventions", async () => {
|
|
|
128
114
|
|
|
129
115
|
expect(
|
|
130
116
|
<Output program={runner.program} namePolicy={createCSharpNamePolicy()}>
|
|
131
|
-
<
|
|
132
|
-
<
|
|
133
|
-
|
|
134
|
-
</SourceFile>
|
|
135
|
-
</Namespace>
|
|
117
|
+
<SourceFile path="test.cs">
|
|
118
|
+
<EnumDeclaration type={TestEnum} />
|
|
119
|
+
</SourceFile>
|
|
136
120
|
</Output>,
|
|
137
121
|
).toRenderTo(`
|
|
138
|
-
|
|
122
|
+
enum TestEnum
|
|
139
123
|
{
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
ValueTwo,
|
|
144
|
-
ValueThree
|
|
145
|
-
}
|
|
124
|
+
ValueOne,
|
|
125
|
+
ValueTwo,
|
|
126
|
+
ValueThree
|
|
146
127
|
}
|
|
147
128
|
`);
|
|
148
129
|
});
|
|
@@ -159,13 +140,10 @@ it("renders enum with single value", async () => {
|
|
|
159
140
|
<EnumDeclaration type={TestEnum} />
|
|
160
141
|
</Wrapper>,
|
|
161
142
|
).toRenderTo(`
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
OnlyValue
|
|
167
|
-
}
|
|
168
|
-
}
|
|
143
|
+
enum TestEnum
|
|
144
|
+
{
|
|
145
|
+
OnlyValue
|
|
146
|
+
}
|
|
169
147
|
`);
|
|
170
148
|
});
|
|
171
149
|
|
|
@@ -184,15 +162,12 @@ it("renders enum with numeric-like member names", async () => {
|
|
|
184
162
|
<EnumDeclaration type={TestEnum} />
|
|
185
163
|
</Wrapper>,
|
|
186
164
|
).toRenderTo(`
|
|
187
|
-
|
|
165
|
+
enum TestEnum
|
|
188
166
|
{
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
Value10,
|
|
194
|
-
Value100
|
|
195
|
-
}
|
|
167
|
+
Value0,
|
|
168
|
+
Value1,
|
|
169
|
+
Value10,
|
|
170
|
+
Value100
|
|
196
171
|
}
|
|
197
172
|
`);
|
|
198
173
|
});
|
|
@@ -217,19 +192,16 @@ it("renders multiple enums in the same namespace", async () => {
|
|
|
217
192
|
<EnumDeclaration type={TestEnum2} />
|
|
218
193
|
</Wrapper>,
|
|
219
194
|
).toRenderTo(`
|
|
220
|
-
|
|
195
|
+
enum TestEnum1
|
|
196
|
+
{
|
|
197
|
+
Value1,
|
|
198
|
+
Value2
|
|
199
|
+
}
|
|
200
|
+
enum TestEnum2
|
|
221
201
|
{
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
Value2
|
|
226
|
-
}
|
|
227
|
-
enum TestEnum2
|
|
228
|
-
{
|
|
229
|
-
OptionA,
|
|
230
|
-
OptionB,
|
|
231
|
-
OptionC
|
|
232
|
-
}
|
|
202
|
+
OptionA,
|
|
203
|
+
OptionB,
|
|
204
|
+
OptionC
|
|
233
205
|
}
|
|
234
206
|
`);
|
|
235
207
|
});
|
|
@@ -249,19 +221,16 @@ it("renders an enum with doc comments", async () => {
|
|
|
249
221
|
<EnumDeclaration type={TestEnum} />
|
|
250
222
|
</Wrapper>,
|
|
251
223
|
).toRenderTo(`
|
|
252
|
-
|
|
224
|
+
enum TestEnum
|
|
253
225
|
{
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
/// </summary>
|
|
263
|
-
Value2
|
|
264
|
-
}
|
|
226
|
+
/// <summary>
|
|
227
|
+
/// This is value one
|
|
228
|
+
/// </summary>
|
|
229
|
+
Value1,
|
|
230
|
+
/// <summary>
|
|
231
|
+
/// This is value two
|
|
232
|
+
/// </summary>
|
|
233
|
+
Value2
|
|
265
234
|
}
|
|
266
235
|
`);
|
|
267
236
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Tester } from "#test/test-host.js";
|
|
2
2
|
import { List, type Children } from "@alloy-js/core";
|
|
3
|
-
import { ClassDeclaration, createCSharpNamePolicy,
|
|
3
|
+
import { ClassDeclaration, createCSharpNamePolicy, SourceFile } from "@alloy-js/csharp";
|
|
4
4
|
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
5
5
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
6
6
|
import { Output } from "../../../core/components/output.jsx";
|
|
@@ -16,11 +16,9 @@ function Wrapper(props: { children: Children }) {
|
|
|
16
16
|
const policy = createCSharpNamePolicy();
|
|
17
17
|
return (
|
|
18
18
|
<Output program={tester.program} namePolicy={policy}>
|
|
19
|
-
<
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
</SourceFile>
|
|
23
|
-
</Namespace>
|
|
19
|
+
<SourceFile path="test.cs">
|
|
20
|
+
<ClassDeclaration name="Test">{props.children}</ClassDeclaration>
|
|
21
|
+
</SourceFile>
|
|
24
22
|
</Output>
|
|
25
23
|
);
|
|
26
24
|
}
|
|
@@ -37,12 +35,9 @@ it("maps prop: string | null to nullable property", async () => {
|
|
|
37
35
|
<Property type={prop1} />
|
|
38
36
|
</Wrapper>,
|
|
39
37
|
).toRenderTo(`
|
|
40
|
-
|
|
38
|
+
class Test
|
|
41
39
|
{
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
public required string? Prop1 { get; set; }
|
|
45
|
-
}
|
|
40
|
+
public required string? Prop1 { get; set; }
|
|
46
41
|
}
|
|
47
42
|
`);
|
|
48
43
|
});
|
|
@@ -59,12 +54,9 @@ it("maps optional properties to nullable properties", async () => {
|
|
|
59
54
|
<Property type={prop1} />
|
|
60
55
|
</Wrapper>,
|
|
61
56
|
).toRenderTo(`
|
|
62
|
-
|
|
57
|
+
class Test
|
|
63
58
|
{
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
public string? Prop1 { get; set; }
|
|
67
|
-
}
|
|
59
|
+
public string? Prop1 { get; set; }
|
|
68
60
|
}
|
|
69
61
|
`);
|
|
70
62
|
});
|
|
@@ -81,12 +73,9 @@ it("maps optional and nullable properties to nullable properties", async () => {
|
|
|
81
73
|
<Property type={prop1} />
|
|
82
74
|
</Wrapper>,
|
|
83
75
|
).toRenderTo(`
|
|
84
|
-
|
|
76
|
+
class Test
|
|
85
77
|
{
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
public string? Prop1 { get; set; }
|
|
89
|
-
}
|
|
78
|
+
public string? Prop1 { get; set; }
|
|
90
79
|
}
|
|
91
80
|
`);
|
|
92
81
|
});
|
|
@@ -104,13 +93,10 @@ describe("jsonAttributes", () => {
|
|
|
104
93
|
<Property type={prop1} jsonAttributes />
|
|
105
94
|
</Wrapper>,
|
|
106
95
|
).toRenderTo(`
|
|
107
|
-
|
|
96
|
+
class Test
|
|
108
97
|
{
|
|
109
|
-
|
|
110
|
-
{
|
|
111
|
-
[System.Text.Json.JsonPropertyName("prop1")]
|
|
112
|
-
public required string Prop1 { get; set; }
|
|
113
|
-
}
|
|
98
|
+
[System.Text.Json.JsonPropertyName("prop1")]
|
|
99
|
+
public required string Prop1 { get; set; }
|
|
114
100
|
}
|
|
115
101
|
`);
|
|
116
102
|
});
|
|
@@ -128,28 +114,25 @@ describe("jsonAttributes", () => {
|
|
|
128
114
|
<Property type={prop1} jsonAttributes />
|
|
129
115
|
</Wrapper>,
|
|
130
116
|
).toRenderTo(`
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
public required string Prop1 { get; set; }
|
|
137
|
-
}
|
|
138
|
-
}
|
|
117
|
+
class Test
|
|
118
|
+
{
|
|
119
|
+
[System.Text.Json.JsonPropertyName("prop_1")]
|
|
120
|
+
public required string Prop1 { get; set; }
|
|
121
|
+
}
|
|
139
122
|
`);
|
|
140
123
|
});
|
|
141
124
|
|
|
142
125
|
it("inherit prop: override, new", async () => {
|
|
143
126
|
const r = await tester.compile(t.code`
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
127
|
+
model TestModel extends BaseModel {
|
|
128
|
+
${t.modelProperty("prop1")}: string;
|
|
129
|
+
${t.modelProperty("prop2")}: string | null;
|
|
130
|
+
}
|
|
131
|
+
model BaseModel {
|
|
132
|
+
prop1: string | null;
|
|
133
|
+
prop2: string | null;
|
|
134
|
+
}
|
|
135
|
+
`);
|
|
153
136
|
|
|
154
137
|
expect(
|
|
155
138
|
<Wrapper>
|
|
@@ -159,28 +142,25 @@ describe("jsonAttributes", () => {
|
|
|
159
142
|
</List>
|
|
160
143
|
</Wrapper>,
|
|
161
144
|
).toRenderTo(`
|
|
162
|
-
|
|
145
|
+
class Test
|
|
163
146
|
{
|
|
164
|
-
|
|
165
|
-
{
|
|
166
|
-
public new required string Prop1 { get; set; }
|
|
167
|
-
public override required string? Prop2 { get; set; }
|
|
168
|
-
}
|
|
147
|
+
public new required string Prop1 { get; set; }
|
|
148
|
+
public override required string? Prop2 { get; set; }
|
|
169
149
|
}
|
|
170
|
-
|
|
150
|
+
`);
|
|
171
151
|
});
|
|
172
152
|
|
|
173
153
|
it("inherit prop: virtual", async () => {
|
|
174
154
|
const r = await tester.compile(t.code`
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
155
|
+
model TestModel extends BaseModel {
|
|
156
|
+
prop1: string;
|
|
157
|
+
prop2: string | null;
|
|
158
|
+
}
|
|
159
|
+
model BaseModel {
|
|
160
|
+
${t.modelProperty("prop1")}: string | null;
|
|
161
|
+
${t.modelProperty("prop2")}: string | null;
|
|
162
|
+
}
|
|
163
|
+
`);
|
|
184
164
|
|
|
185
165
|
expect(
|
|
186
166
|
<Wrapper>
|
|
@@ -190,14 +170,11 @@ describe("jsonAttributes", () => {
|
|
|
190
170
|
</List>
|
|
191
171
|
</Wrapper>,
|
|
192
172
|
).toRenderTo(`
|
|
193
|
-
|
|
173
|
+
class Test
|
|
194
174
|
{
|
|
195
|
-
|
|
196
|
-
{
|
|
197
|
-
public required string? Prop1 { get; set; }
|
|
198
|
-
public virtual required string? Prop2 { get; set; }
|
|
199
|
-
}
|
|
175
|
+
public required string? Prop1 { get; set; }
|
|
176
|
+
public virtual required string? Prop2 { get; set; }
|
|
200
177
|
}
|
|
201
|
-
|
|
178
|
+
`);
|
|
202
179
|
});
|
|
203
180
|
});
|