@typespec/emitter-framework 0.9.0-dev.7 → 0.9.0-dev.8
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/csharp/components/class/declaration.test.js +100 -115
- package/dist/src/csharp/components/{enum-declaration.d.ts → enum/declaration.d.ts} +1 -1
- package/dist/src/csharp/components/enum/declaration.d.ts.map +1 -0
- package/dist/src/csharp/components/{enum-declaration.js → enum/declaration.js} +4 -4
- package/dist/src/csharp/components/enum/declaration.test.d.ts +2 -0
- package/dist/src/csharp/components/enum/declaration.test.d.ts.map +1 -0
- package/dist/src/csharp/components/enum/declaration.test.js +309 -0
- package/dist/src/csharp/components/index.d.ts +1 -1
- package/dist/src/csharp/components/index.js +1 -1
- package/dist/src/csharp/components/property/property.test.js +14 -14
- package/package.json +7 -4
- package/src/csharp/components/class/declaration.test.tsx +106 -168
- package/src/csharp/components/enum/declaration.test.tsx +267 -0
- package/src/csharp/components/{enum-declaration.tsx → enum/declaration.tsx} +4 -4
- package/src/csharp/components/index.ts +1 -1
- package/src/csharp/components/property/property.test.tsx +14 -14
- package/dist/src/csharp/components/enum-declaration.d.ts.map +0 -1
- package/dist/test/csharp/components/enum-declaration.test.d.ts +0 -2
- package/dist/test/csharp/components/enum-declaration.test.d.ts.map +0 -1
- package/dist/test/csharp/components/enum-declaration.test.js +0 -403
- package/dist/test/csharp/test-host.d.ts +0 -11
- package/dist/test/csharp/test-host.d.ts.map +0 -1
- package/dist/test/csharp/test-host.js +0 -32
- package/dist/test/csharp/utils.d.ts +0 -3
- package/dist/test/csharp/utils.d.ts.map +0 -1
- package/dist/test/csharp/utils.js +0 -6
- package/test/csharp/components/enum-declaration.test.tsx +0 -337
- package/test/csharp/test-host.ts +0 -42
- package/test/csharp/utils.ts +0 -8
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Tester } from "#test/test-host.js";
|
|
2
|
-
import { type Children
|
|
3
|
-
import { d } from "@alloy-js/core/testing";
|
|
2
|
+
import { type Children } from "@alloy-js/core";
|
|
4
3
|
import { createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
|
|
5
4
|
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
6
|
-
import { beforeEach, describe, it } from "vitest";
|
|
7
|
-
import { assertFileContents } from "../../../../test/csharp/utils.js";
|
|
5
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
8
6
|
import { Output } from "../../../core/index.js";
|
|
9
7
|
import { ClassDeclaration, EnumDeclaration } from "../../index.js";
|
|
10
8
|
|
|
@@ -30,24 +28,19 @@ it("renders an empty class declaration", async () => {
|
|
|
30
28
|
model ${t.model("TestModel")} {}
|
|
31
29
|
`);
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
expect(
|
|
34
32
|
<Wrapper>
|
|
35
33
|
<ClassDeclaration type={TestModel} />
|
|
36
34
|
</Wrapper>,
|
|
37
|
-
)
|
|
35
|
+
).toRenderTo(`
|
|
36
|
+
namespace TestNamespace
|
|
37
|
+
{
|
|
38
|
+
class TestModel
|
|
39
|
+
{
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
namespace TestNamespace
|
|
43
|
-
{
|
|
44
|
-
class TestModel
|
|
45
|
-
{
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
`,
|
|
50
|
-
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`);
|
|
51
44
|
});
|
|
52
45
|
|
|
53
46
|
it("renders a class declaration with properties", async () => {
|
|
@@ -58,25 +51,20 @@ it("renders a class declaration with properties", async () => {
|
|
|
58
51
|
}
|
|
59
52
|
`);
|
|
60
53
|
|
|
61
|
-
|
|
54
|
+
expect(
|
|
62
55
|
<Wrapper>
|
|
63
56
|
<ClassDeclaration type={TestModel} />
|
|
64
57
|
</Wrapper>,
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
public required int Prop2 { get; set; }
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
`,
|
|
79
|
-
);
|
|
58
|
+
).toRenderTo(`
|
|
59
|
+
namespace TestNamespace
|
|
60
|
+
{
|
|
61
|
+
class TestModel
|
|
62
|
+
{
|
|
63
|
+
public required string Prop1 { get; set; }
|
|
64
|
+
public required int Prop2 { get; set; }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
`);
|
|
80
68
|
});
|
|
81
69
|
|
|
82
70
|
it("can override class name", async () => {
|
|
@@ -84,24 +72,19 @@ it("can override class name", async () => {
|
|
|
84
72
|
model ${t.model("TestModel")} {}
|
|
85
73
|
`);
|
|
86
74
|
|
|
87
|
-
|
|
75
|
+
expect(
|
|
88
76
|
<Wrapper>
|
|
89
77
|
<ClassDeclaration type={TestModel} name="CustomClassName" />
|
|
90
78
|
</Wrapper>,
|
|
91
|
-
)
|
|
79
|
+
).toRenderTo(`
|
|
80
|
+
namespace TestNamespace
|
|
81
|
+
{
|
|
82
|
+
class CustomClassName
|
|
83
|
+
{
|
|
92
84
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
namespace TestNamespace
|
|
97
|
-
{
|
|
98
|
-
class CustomClassName
|
|
99
|
-
{
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
`,
|
|
104
|
-
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`);
|
|
105
88
|
});
|
|
106
89
|
|
|
107
90
|
it("renders a class with access modifiers", async () => {
|
|
@@ -110,24 +93,19 @@ it("renders a class with access modifiers", async () => {
|
|
|
110
93
|
}
|
|
111
94
|
`);
|
|
112
95
|
|
|
113
|
-
|
|
96
|
+
expect(
|
|
114
97
|
<Wrapper>
|
|
115
98
|
<ClassDeclaration type={TestModel} protected />
|
|
116
99
|
</Wrapper>,
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
namespace TestNamespace
|
|
123
|
-
{
|
|
124
|
-
protected class TestModel
|
|
125
|
-
{
|
|
100
|
+
).toRenderTo(`
|
|
101
|
+
namespace TestNamespace
|
|
102
|
+
{
|
|
103
|
+
protected class TestModel
|
|
104
|
+
{
|
|
126
105
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
`);
|
|
131
109
|
});
|
|
132
110
|
|
|
133
111
|
describe("from an interface", () => {
|
|
@@ -137,15 +115,11 @@ describe("from an interface", () => {
|
|
|
137
115
|
}
|
|
138
116
|
`);
|
|
139
117
|
|
|
140
|
-
|
|
118
|
+
expect(
|
|
141
119
|
<Wrapper>
|
|
142
120
|
<ClassDeclaration type={TestInterface} />
|
|
143
121
|
</Wrapper>,
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
assertFileContents(
|
|
147
|
-
res,
|
|
148
|
-
d`
|
|
122
|
+
).toRenderTo(`
|
|
149
123
|
namespace TestNamespace
|
|
150
124
|
{
|
|
151
125
|
class TestInterface
|
|
@@ -153,8 +127,7 @@ describe("from an interface", () => {
|
|
|
153
127
|
|
|
154
128
|
}
|
|
155
129
|
}
|
|
156
|
-
|
|
157
|
-
);
|
|
130
|
+
`);
|
|
158
131
|
});
|
|
159
132
|
|
|
160
133
|
it("renders a class with operations", async () => {
|
|
@@ -164,15 +137,11 @@ describe("from an interface", () => {
|
|
|
164
137
|
}
|
|
165
138
|
`);
|
|
166
139
|
|
|
167
|
-
|
|
140
|
+
expect(
|
|
168
141
|
<Wrapper>
|
|
169
142
|
<ClassDeclaration type={TestInterface} />
|
|
170
143
|
</Wrapper>,
|
|
171
|
-
)
|
|
172
|
-
|
|
173
|
-
assertFileContents(
|
|
174
|
-
res,
|
|
175
|
-
d`
|
|
144
|
+
).toRenderTo(`
|
|
176
145
|
namespace TestNamespace
|
|
177
146
|
{
|
|
178
147
|
class TestInterface
|
|
@@ -180,8 +149,7 @@ describe("from an interface", () => {
|
|
|
180
149
|
public abstract string GetName(string id);
|
|
181
150
|
}
|
|
182
151
|
}
|
|
183
|
-
|
|
184
|
-
);
|
|
152
|
+
`);
|
|
185
153
|
});
|
|
186
154
|
});
|
|
187
155
|
|
|
@@ -193,30 +161,25 @@ it("renders a class with model members", async () => {
|
|
|
193
161
|
}
|
|
194
162
|
`);
|
|
195
163
|
|
|
196
|
-
|
|
164
|
+
expect(
|
|
197
165
|
<Wrapper>
|
|
198
166
|
<ClassDeclaration type={TestReference} />
|
|
199
167
|
<hbr />
|
|
200
168
|
<ClassDeclaration type={TestModel} />
|
|
201
169
|
</Wrapper>,
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
public required TestReference Prop1 { get; set; }
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
`,
|
|
219
|
-
);
|
|
170
|
+
).toRenderTo(`
|
|
171
|
+
namespace TestNamespace
|
|
172
|
+
{
|
|
173
|
+
class TestReference
|
|
174
|
+
{
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
class TestModel
|
|
178
|
+
{
|
|
179
|
+
public required TestReference Prop1 { get; set; }
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
`);
|
|
220
183
|
});
|
|
221
184
|
|
|
222
185
|
it("renders a class with enum members", async () => {
|
|
@@ -230,31 +193,26 @@ it("renders a class with enum members", async () => {
|
|
|
230
193
|
}
|
|
231
194
|
`);
|
|
232
195
|
|
|
233
|
-
|
|
196
|
+
expect(
|
|
234
197
|
<Wrapper>
|
|
235
198
|
<EnumDeclaration type={TestEnum} />
|
|
236
199
|
<hbr />
|
|
237
200
|
<ClassDeclaration type={TestModel} />
|
|
238
201
|
</Wrapper>,
|
|
239
|
-
)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
public required TestEnum Prop1 { get; set; }
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
`,
|
|
257
|
-
);
|
|
202
|
+
).toRenderTo(`
|
|
203
|
+
namespace TestNamespace
|
|
204
|
+
{
|
|
205
|
+
enum TestEnum
|
|
206
|
+
{
|
|
207
|
+
Value1,
|
|
208
|
+
Value2
|
|
209
|
+
}
|
|
210
|
+
class TestModel
|
|
211
|
+
{
|
|
212
|
+
public required TestEnum Prop1 { get; set; }
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
`);
|
|
258
216
|
});
|
|
259
217
|
|
|
260
218
|
it("maps prop: string | null to nullable property", async () => {
|
|
@@ -264,24 +222,19 @@ it("maps prop: string | null to nullable property", async () => {
|
|
|
264
222
|
}
|
|
265
223
|
`);
|
|
266
224
|
|
|
267
|
-
|
|
225
|
+
expect(
|
|
268
226
|
<Wrapper>
|
|
269
227
|
<ClassDeclaration type={TestModel} />
|
|
270
228
|
</Wrapper>,
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
public required string? Prop1 { get; set; }
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
`,
|
|
284
|
-
);
|
|
229
|
+
).toRenderTo(`
|
|
230
|
+
namespace TestNamespace
|
|
231
|
+
{
|
|
232
|
+
class TestModel
|
|
233
|
+
{
|
|
234
|
+
public required string? Prop1 { get; set; }
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
`);
|
|
285
238
|
});
|
|
286
239
|
|
|
287
240
|
it("renders a class with string enums", async () => {
|
|
@@ -295,31 +248,26 @@ it("renders a class with string enums", async () => {
|
|
|
295
248
|
}
|
|
296
249
|
`);
|
|
297
250
|
|
|
298
|
-
|
|
251
|
+
expect(
|
|
299
252
|
<Wrapper>
|
|
300
253
|
<EnumDeclaration type={TestEnum} />
|
|
301
254
|
<hbr />
|
|
302
255
|
<ClassDeclaration type={TestModel} />
|
|
303
256
|
</Wrapper>,
|
|
304
|
-
)
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
public required TestEnum Prop1 { get; set; }
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
`,
|
|
322
|
-
);
|
|
257
|
+
).toRenderTo(`
|
|
258
|
+
namespace TestNamespace
|
|
259
|
+
{
|
|
260
|
+
enum TestEnum
|
|
261
|
+
{
|
|
262
|
+
Value1,
|
|
263
|
+
Value2
|
|
264
|
+
}
|
|
265
|
+
class TestModel
|
|
266
|
+
{
|
|
267
|
+
public required TestEnum Prop1 { get; set; }
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
`);
|
|
323
271
|
});
|
|
324
272
|
|
|
325
273
|
describe("with doc comments", () => {
|
|
@@ -333,15 +281,11 @@ describe("with doc comments", () => {
|
|
|
333
281
|
|
|
334
282
|
`);
|
|
335
283
|
|
|
336
|
-
|
|
284
|
+
expect(
|
|
337
285
|
<Wrapper>
|
|
338
286
|
<ClassDeclaration type={TestModel} />
|
|
339
287
|
</Wrapper>,
|
|
340
|
-
)
|
|
341
|
-
|
|
342
|
-
assertFileContents(
|
|
343
|
-
res,
|
|
344
|
-
d`
|
|
288
|
+
).toRenderTo(`
|
|
345
289
|
namespace TestNamespace
|
|
346
290
|
{
|
|
347
291
|
/// <summary>
|
|
@@ -355,8 +299,7 @@ describe("with doc comments", () => {
|
|
|
355
299
|
public required string Prop1 { get; set; }
|
|
356
300
|
}
|
|
357
301
|
}
|
|
358
|
-
|
|
359
|
-
);
|
|
302
|
+
`);
|
|
360
303
|
});
|
|
361
304
|
|
|
362
305
|
it("renders an interface with docs", async () => {
|
|
@@ -369,15 +312,11 @@ describe("with doc comments", () => {
|
|
|
369
312
|
}
|
|
370
313
|
`);
|
|
371
314
|
|
|
372
|
-
|
|
315
|
+
expect(
|
|
373
316
|
<Wrapper>
|
|
374
317
|
<ClassDeclaration type={TestInterface} />
|
|
375
318
|
</Wrapper>,
|
|
376
|
-
)
|
|
377
|
-
|
|
378
|
-
assertFileContents(
|
|
379
|
-
res,
|
|
380
|
-
d`
|
|
319
|
+
).toRenderTo(`
|
|
381
320
|
namespace TestNamespace
|
|
382
321
|
{
|
|
383
322
|
/// <summary>
|
|
@@ -395,7 +334,6 @@ describe("with doc comments", () => {
|
|
|
395
334
|
public abstract string GetName(string id);
|
|
396
335
|
}
|
|
397
336
|
}
|
|
398
|
-
|
|
399
|
-
);
|
|
337
|
+
`);
|
|
400
338
|
});
|
|
401
339
|
});
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { Tester } from "#test/test-host.js";
|
|
2
|
+
import { type Children } from "@alloy-js/core";
|
|
3
|
+
import { createCSharpNamePolicy, Namespace, SourceFile } from "@alloy-js/csharp";
|
|
4
|
+
import { t, type TesterInstance } from "@typespec/compiler/testing";
|
|
5
|
+
import { beforeEach, expect, it } from "vitest";
|
|
6
|
+
import { Output } from "../../../core/index.js";
|
|
7
|
+
import { EnumDeclaration } from "../../index.js";
|
|
8
|
+
|
|
9
|
+
let runner: TesterInstance;
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
runner = await Tester.createInstance();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
function Wrapper(props: { children: Children }) {
|
|
16
|
+
const policy = createCSharpNamePolicy();
|
|
17
|
+
return (
|
|
18
|
+
<Output program={runner.program} namePolicy={policy}>
|
|
19
|
+
<Namespace name="TestNamespace">
|
|
20
|
+
<SourceFile path="test.cs">{props.children}</SourceFile>
|
|
21
|
+
</Namespace>
|
|
22
|
+
</Output>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
it("renders a basic enum declaration", async () => {
|
|
27
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
28
|
+
@test enum ${t.enum("TestEnum")} {
|
|
29
|
+
Value1;
|
|
30
|
+
Value2;
|
|
31
|
+
Value3;
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
34
|
+
|
|
35
|
+
expect(
|
|
36
|
+
<Wrapper>
|
|
37
|
+
<EnumDeclaration type={TestEnum} />
|
|
38
|
+
</Wrapper>,
|
|
39
|
+
).toRenderTo(`
|
|
40
|
+
namespace TestNamespace
|
|
41
|
+
{
|
|
42
|
+
enum TestEnum
|
|
43
|
+
{
|
|
44
|
+
Value1,
|
|
45
|
+
Value2,
|
|
46
|
+
Value3
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
`);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("renders an empty enum declaration", async () => {
|
|
53
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
54
|
+
@test enum ${t.enum("TestEnum")} {}
|
|
55
|
+
`);
|
|
56
|
+
|
|
57
|
+
expect(
|
|
58
|
+
<Wrapper>
|
|
59
|
+
<EnumDeclaration type={TestEnum} />
|
|
60
|
+
</Wrapper>,
|
|
61
|
+
).toRenderTo(`
|
|
62
|
+
namespace TestNamespace
|
|
63
|
+
{
|
|
64
|
+
enum TestEnum
|
|
65
|
+
{
|
|
66
|
+
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("can override enum name", async () => {
|
|
73
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
74
|
+
@test enum ${t.enum("TestEnum")} {
|
|
75
|
+
Value1;
|
|
76
|
+
Value2;
|
|
77
|
+
}
|
|
78
|
+
`);
|
|
79
|
+
|
|
80
|
+
expect(
|
|
81
|
+
<Wrapper>
|
|
82
|
+
<EnumDeclaration type={TestEnum} name="CustomEnumName" />
|
|
83
|
+
</Wrapper>,
|
|
84
|
+
).toRenderTo(`
|
|
85
|
+
namespace TestNamespace
|
|
86
|
+
{
|
|
87
|
+
enum CustomEnumName
|
|
88
|
+
{
|
|
89
|
+
Value1,
|
|
90
|
+
Value2
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
`);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("renders an enum with access modifiers", async () => {
|
|
97
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
98
|
+
@test enum ${t.enum("TestEnum")} {
|
|
99
|
+
Value1;
|
|
100
|
+
Value2;
|
|
101
|
+
}
|
|
102
|
+
`);
|
|
103
|
+
|
|
104
|
+
expect(
|
|
105
|
+
<Wrapper>
|
|
106
|
+
<EnumDeclaration type={TestEnum} internal />
|
|
107
|
+
</Wrapper>,
|
|
108
|
+
).toRenderTo(`
|
|
109
|
+
namespace TestNamespace
|
|
110
|
+
{
|
|
111
|
+
internal enum TestEnum
|
|
112
|
+
{
|
|
113
|
+
Value1,
|
|
114
|
+
Value2
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("renders enum with C# naming conventions", async () => {
|
|
121
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
122
|
+
@test enum ${t.enum("TestEnum")} {
|
|
123
|
+
value_one;
|
|
124
|
+
value_two;
|
|
125
|
+
value_three;
|
|
126
|
+
}
|
|
127
|
+
`);
|
|
128
|
+
|
|
129
|
+
expect(
|
|
130
|
+
<Output program={runner.program} namePolicy={createCSharpNamePolicy()}>
|
|
131
|
+
<Namespace name="TestNamespace">
|
|
132
|
+
<SourceFile path="test.cs">
|
|
133
|
+
<EnumDeclaration type={TestEnum} />
|
|
134
|
+
</SourceFile>
|
|
135
|
+
</Namespace>
|
|
136
|
+
</Output>,
|
|
137
|
+
).toRenderTo(`
|
|
138
|
+
namespace TestNamespace
|
|
139
|
+
{
|
|
140
|
+
enum TestEnum
|
|
141
|
+
{
|
|
142
|
+
ValueOne,
|
|
143
|
+
ValueTwo,
|
|
144
|
+
ValueThree
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
`);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("renders enum with single value", async () => {
|
|
151
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
152
|
+
@test enum ${t.enum("TestEnum")} {
|
|
153
|
+
OnlyValue;
|
|
154
|
+
}
|
|
155
|
+
`);
|
|
156
|
+
|
|
157
|
+
expect(
|
|
158
|
+
<Wrapper>
|
|
159
|
+
<EnumDeclaration type={TestEnum} />
|
|
160
|
+
</Wrapper>,
|
|
161
|
+
).toRenderTo(`
|
|
162
|
+
namespace TestNamespace
|
|
163
|
+
{
|
|
164
|
+
enum TestEnum
|
|
165
|
+
{
|
|
166
|
+
OnlyValue
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
`);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("renders enum with numeric-like member names", async () => {
|
|
173
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
174
|
+
@test enum ${t.enum("TestEnum")} {
|
|
175
|
+
Value0;
|
|
176
|
+
Value1;
|
|
177
|
+
Value10;
|
|
178
|
+
Value100;
|
|
179
|
+
}
|
|
180
|
+
`);
|
|
181
|
+
|
|
182
|
+
expect(
|
|
183
|
+
<Wrapper>
|
|
184
|
+
<EnumDeclaration type={TestEnum} />
|
|
185
|
+
</Wrapper>,
|
|
186
|
+
).toRenderTo(`
|
|
187
|
+
namespace TestNamespace
|
|
188
|
+
{
|
|
189
|
+
enum TestEnum
|
|
190
|
+
{
|
|
191
|
+
Value0,
|
|
192
|
+
Value1,
|
|
193
|
+
Value10,
|
|
194
|
+
Value100
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
`);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("renders multiple enums in the same namespace", async () => {
|
|
201
|
+
const { TestEnum1, TestEnum2 } = await runner.compile(t.code`
|
|
202
|
+
@test enum ${t.enum("TestEnum1")} {
|
|
203
|
+
Value1;
|
|
204
|
+
Value2;
|
|
205
|
+
}
|
|
206
|
+
@test enum ${t.enum("TestEnum2")} {
|
|
207
|
+
OptionA;
|
|
208
|
+
OptionB;
|
|
209
|
+
OptionC;
|
|
210
|
+
}
|
|
211
|
+
`);
|
|
212
|
+
|
|
213
|
+
expect(
|
|
214
|
+
<Wrapper>
|
|
215
|
+
<EnumDeclaration type={TestEnum1} />
|
|
216
|
+
<hbr />
|
|
217
|
+
<EnumDeclaration type={TestEnum2} />
|
|
218
|
+
</Wrapper>,
|
|
219
|
+
).toRenderTo(`
|
|
220
|
+
namespace TestNamespace
|
|
221
|
+
{
|
|
222
|
+
enum TestEnum1
|
|
223
|
+
{
|
|
224
|
+
Value1,
|
|
225
|
+
Value2
|
|
226
|
+
}
|
|
227
|
+
enum TestEnum2
|
|
228
|
+
{
|
|
229
|
+
OptionA,
|
|
230
|
+
OptionB,
|
|
231
|
+
OptionC
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
`);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("renders an enum with doc comments", async () => {
|
|
238
|
+
const { TestEnum } = await runner.compile(t.code`
|
|
239
|
+
@test enum ${t.enum("TestEnum")} {
|
|
240
|
+
@doc("This is value one")
|
|
241
|
+
Value1;
|
|
242
|
+
/** This is value two */
|
|
243
|
+
Value2;
|
|
244
|
+
}
|
|
245
|
+
`);
|
|
246
|
+
|
|
247
|
+
expect(
|
|
248
|
+
<Wrapper>
|
|
249
|
+
<EnumDeclaration type={TestEnum} />
|
|
250
|
+
</Wrapper>,
|
|
251
|
+
).toRenderTo(`
|
|
252
|
+
namespace TestNamespace
|
|
253
|
+
{
|
|
254
|
+
enum TestEnum
|
|
255
|
+
{
|
|
256
|
+
/// <summary>
|
|
257
|
+
/// This is value one
|
|
258
|
+
/// </summary>
|
|
259
|
+
Value1,
|
|
260
|
+
/// <summary>
|
|
261
|
+
/// This is value two
|
|
262
|
+
/// </summary>
|
|
263
|
+
Value2
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
`);
|
|
267
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { useTsp } from "#core/context/tsp-context.js";
|
|
1
2
|
import { type Children, For } from "@alloy-js/core";
|
|
2
3
|
import * as cs from "@alloy-js/csharp";
|
|
3
4
|
import type { Enum, Union } from "@typespec/compiler";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { declarationRefkeys, efRefkey } from "./utils/refkey.js";
|
|
5
|
+
import { reportDiagnostic } from "../../../lib.js";
|
|
6
|
+
import { getDocComments } from "../utils/doc-comments.jsx";
|
|
7
|
+
import { declarationRefkeys, efRefkey } from "../utils/refkey.js";
|
|
8
8
|
|
|
9
9
|
export interface EnumDeclarationProps extends Omit<cs.EnumDeclarationProps, "name"> {
|
|
10
10
|
name?: string;
|