@typespec/emitter-framework 0.9.0-dev.1 → 0.9.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.
Files changed (41) hide show
  1. package/dist/src/csharp/components/class-declaration.d.ts +9 -0
  2. package/dist/src/csharp/components/class-declaration.d.ts.map +1 -0
  3. package/dist/src/csharp/components/class-declaration.js +97 -0
  4. package/dist/src/csharp/components/enum-declaration.d.ts +9 -0
  5. package/dist/src/csharp/components/enum-declaration.d.ts.map +1 -0
  6. package/dist/src/csharp/components/enum-declaration.js +52 -0
  7. package/dist/src/csharp/components/index.d.ts +3 -0
  8. package/dist/src/csharp/components/index.d.ts.map +1 -0
  9. package/dist/src/csharp/components/index.js +2 -0
  10. package/dist/src/csharp/components/type-expression.d.ts +11 -0
  11. package/dist/src/csharp/components/type-expression.d.ts.map +1 -0
  12. package/dist/src/csharp/components/type-expression.js +129 -0
  13. package/dist/src/csharp/components/utils/refkey.d.ts +23 -0
  14. package/dist/src/csharp/components/utils/refkey.d.ts.map +1 -0
  15. package/dist/src/csharp/components/utils/refkey.js +35 -0
  16. package/dist/src/csharp/index.d.ts +2 -0
  17. package/dist/src/csharp/index.d.ts.map +1 -0
  18. package/dist/src/csharp/index.js +1 -0
  19. package/dist/test/csharp/components/class-declaration.test.d.ts +2 -0
  20. package/dist/test/csharp/components/class-declaration.test.d.ts.map +1 -0
  21. package/dist/test/csharp/components/class-declaration.test.js +421 -0
  22. package/dist/test/csharp/components/enum-declaration.test.d.ts +2 -0
  23. package/dist/test/csharp/components/enum-declaration.test.d.ts.map +1 -0
  24. package/dist/test/csharp/components/enum-declaration.test.js +355 -0
  25. package/dist/test/csharp/test-host.d.ts +11 -0
  26. package/dist/test/csharp/test-host.d.ts.map +1 -0
  27. package/dist/test/csharp/test-host.js +32 -0
  28. package/dist/test/csharp/utils.d.ts +3 -0
  29. package/dist/test/csharp/utils.d.ts.map +1 -0
  30. package/dist/test/csharp/utils.js +6 -0
  31. package/package.json +2 -1
  32. package/src/csharp/components/class-declaration.tsx +87 -0
  33. package/src/csharp/components/enum-declaration.tsx +48 -0
  34. package/src/csharp/components/index.ts +2 -0
  35. package/src/csharp/components/type-expression.tsx +112 -0
  36. package/src/csharp/components/utils/refkey.ts +36 -0
  37. package/src/csharp/index.ts +1 -0
  38. package/test/csharp/components/class-declaration.test.tsx +344 -0
  39. package/test/csharp/components/enum-declaration.test.tsx +296 -0
  40. package/test/csharp/test-host.ts +42 -0
  41. package/test/csharp/utils.ts +8 -0
@@ -0,0 +1,421 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { render } from "@alloy-js/core";
3
+ import { d } from "@alloy-js/core/testing";
4
+ import * as cs from "@alloy-js/csharp";
5
+ import { Namespace, SourceFile } from "@alloy-js/csharp";
6
+ import { beforeEach, describe, it } from "vitest";
7
+ import { Output } from "../../../src/core/index.js";
8
+ import { ClassDeclaration, EnumDeclaration } from "../../../src/csharp/index.js";
9
+ import { createEmitterFrameworkTestRunner } from "../test-host.js";
10
+ import { assertFileContents } from "../utils.js";
11
+ let runner;
12
+ beforeEach(async () => {
13
+ runner = await createEmitterFrameworkTestRunner();
14
+ });
15
+ it("renders an empty class declaration", async () => {
16
+ const {
17
+ TestModel
18
+ } = await runner.compile(`
19
+ @test model TestModel {}
20
+ `);
21
+ const res = render(_$createComponent(Output, {
22
+ get program() {
23
+ return runner.program;
24
+ },
25
+ get children() {
26
+ return _$createComponent(Namespace, {
27
+ name: "TestNamespace",
28
+ get children() {
29
+ return _$createComponent(SourceFile, {
30
+ path: "test.cs",
31
+ get children() {
32
+ return _$createComponent(ClassDeclaration, {
33
+ type: TestModel
34
+ });
35
+ }
36
+ });
37
+ }
38
+ });
39
+ }
40
+ }));
41
+ assertFileContents(res, d`
42
+ namespace TestNamespace
43
+ {
44
+ class TestModel
45
+ {
46
+
47
+ }
48
+ }
49
+ `);
50
+ });
51
+ it("renders a class declaration with properties", async () => {
52
+ const {
53
+ TestModel
54
+ } = await runner.compile(`
55
+ @test model TestModel {
56
+ @test Prop1: string;
57
+ @test Prop2: int32;
58
+ }
59
+ `);
60
+ const res = render(_$createComponent(Output, {
61
+ get program() {
62
+ return runner.program;
63
+ },
64
+ get children() {
65
+ return _$createComponent(Namespace, {
66
+ name: "TestNamespace",
67
+ get children() {
68
+ return _$createComponent(SourceFile, {
69
+ path: "test.cs",
70
+ get children() {
71
+ return _$createComponent(ClassDeclaration, {
72
+ type: TestModel
73
+ });
74
+ }
75
+ });
76
+ }
77
+ });
78
+ }
79
+ }));
80
+ assertFileContents(res, d`
81
+ namespace TestNamespace
82
+ {
83
+ class TestModel
84
+ {
85
+ public string Prop1
86
+ {
87
+ get;
88
+ set;
89
+ }
90
+ public int Prop2
91
+ {
92
+ get;
93
+ set;
94
+ }
95
+ }
96
+ }
97
+ `);
98
+ });
99
+ it("can override class name", async () => {
100
+ const {
101
+ TestModel
102
+ } = await runner.compile(`
103
+ @test model TestModel {}
104
+ `);
105
+ const res = render(_$createComponent(Output, {
106
+ get program() {
107
+ return runner.program;
108
+ },
109
+ get children() {
110
+ return _$createComponent(Namespace, {
111
+ name: "TestNamespace",
112
+ get children() {
113
+ return _$createComponent(SourceFile, {
114
+ path: "test.cs",
115
+ get children() {
116
+ return _$createComponent(ClassDeclaration, {
117
+ type: TestModel,
118
+ name: "CustomClassName"
119
+ });
120
+ }
121
+ });
122
+ }
123
+ });
124
+ }
125
+ }));
126
+ assertFileContents(res, d`
127
+ namespace TestNamespace
128
+ {
129
+ class CustomClassName
130
+ {
131
+
132
+ }
133
+ }
134
+ `);
135
+ });
136
+ it("renders a class with access modifiers", async () => {
137
+ const {
138
+ TestModel
139
+ } = await runner.compile(`
140
+ @test model TestModel {
141
+ }
142
+ `);
143
+ const res = render(_$createComponent(Output, {
144
+ get program() {
145
+ return runner.program;
146
+ },
147
+ get children() {
148
+ return _$createComponent(Namespace, {
149
+ name: "TestNamespace",
150
+ get children() {
151
+ return _$createComponent(SourceFile, {
152
+ path: "test.cs",
153
+ get children() {
154
+ return _$createComponent(ClassDeclaration, {
155
+ type: TestModel,
156
+ accessModifier: "protected"
157
+ });
158
+ }
159
+ });
160
+ }
161
+ });
162
+ }
163
+ }));
164
+ assertFileContents(res, d`
165
+ namespace TestNamespace
166
+ {
167
+ protected class TestModel
168
+ {
169
+
170
+ }
171
+ }
172
+ `);
173
+ });
174
+ describe("from an interface", () => {
175
+ it("renders an empty class", async () => {
176
+ const {
177
+ TestInterface
178
+ } = await runner.compile(`
179
+ @test interface TestInterface {
180
+ }
181
+ `);
182
+ const res = render(_$createComponent(Output, {
183
+ get program() {
184
+ return runner.program;
185
+ },
186
+ get children() {
187
+ return _$createComponent(Namespace, {
188
+ name: "TestNamespace",
189
+ get children() {
190
+ return _$createComponent(SourceFile, {
191
+ path: "test.cs",
192
+ get children() {
193
+ return _$createComponent(ClassDeclaration, {
194
+ type: TestInterface
195
+ });
196
+ }
197
+ });
198
+ }
199
+ });
200
+ }
201
+ }));
202
+ assertFileContents(res, d`
203
+ namespace TestNamespace
204
+ {
205
+ class TestInterface
206
+ {
207
+
208
+ }
209
+ }
210
+ `);
211
+ });
212
+ it("renders a class with operations", async () => {
213
+ const {
214
+ TestInterface
215
+ } = await runner.compile(`
216
+ @test interface TestInterface {
217
+ op getName(id: string): string;
218
+ }
219
+ `);
220
+ const res = render(_$createComponent(Output, {
221
+ get program() {
222
+ return runner.program;
223
+ },
224
+ get namePolicy() {
225
+ return cs.createCSharpNamePolicy();
226
+ },
227
+ get children() {
228
+ return _$createComponent(Namespace, {
229
+ name: "TestNamespace",
230
+ get children() {
231
+ return _$createComponent(SourceFile, {
232
+ path: "test.cs",
233
+ get children() {
234
+ return _$createComponent(ClassDeclaration, {
235
+ type: TestInterface
236
+ });
237
+ }
238
+ });
239
+ }
240
+ });
241
+ }
242
+ }));
243
+ assertFileContents(res, d`
244
+ namespace TestNamespace
245
+ {
246
+ class TestInterface
247
+ {
248
+ public abstract string GetName(string id) {}
249
+ }
250
+ }
251
+ `);
252
+ });
253
+ });
254
+ it("renders a class with model members", async () => {
255
+ const {
256
+ TestModel,
257
+ TestReference
258
+ } = await runner.compile(`
259
+ @test model TestReference {
260
+ }
261
+ @test model TestModel {
262
+ @test prop1: TestReference;
263
+ }
264
+ `);
265
+ const res = render(_$createComponent(Output, {
266
+ get program() {
267
+ return runner.program;
268
+ },
269
+ get namePolicy() {
270
+ return cs.createCSharpNamePolicy();
271
+ },
272
+ get children() {
273
+ return _$createComponent(Namespace, {
274
+ name: "TestNamespace",
275
+ get children() {
276
+ return _$createComponent(SourceFile, {
277
+ path: "test.cs",
278
+ get children() {
279
+ return [_$createComponent(ClassDeclaration, {
280
+ type: TestReference
281
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
282
+ type: TestModel
283
+ })];
284
+ }
285
+ });
286
+ }
287
+ });
288
+ }
289
+ }));
290
+ assertFileContents(res, d`
291
+ namespace TestNamespace
292
+ {
293
+ class TestReference
294
+ {
295
+
296
+ }
297
+ class TestModel
298
+ {
299
+ public TestReference Prop1
300
+ {
301
+ get;
302
+ set;
303
+ }
304
+ }
305
+ }
306
+ `);
307
+ });
308
+ it("renders a class with enum members", async () => {
309
+ const {
310
+ TestModel,
311
+ TestEnum
312
+ } = await runner.compile(`
313
+ @test enum TestEnum {
314
+ Value1;
315
+ Value2;
316
+ }
317
+ @test model TestModel {
318
+ @test prop1: TestEnum;
319
+ }
320
+ `);
321
+ const res = render(_$createComponent(Output, {
322
+ get program() {
323
+ return runner.program;
324
+ },
325
+ get namePolicy() {
326
+ return cs.createCSharpNamePolicy();
327
+ },
328
+ get children() {
329
+ return _$createComponent(Namespace, {
330
+ name: "TestNamespace",
331
+ get children() {
332
+ return _$createComponent(SourceFile, {
333
+ path: "test.cs",
334
+ get children() {
335
+ return [_$createComponent(EnumDeclaration, {
336
+ type: TestEnum
337
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
338
+ type: TestModel
339
+ })];
340
+ }
341
+ });
342
+ }
343
+ });
344
+ }
345
+ }));
346
+ assertFileContents(res, d`
347
+ namespace TestNamespace
348
+ {
349
+ public enum TestEnum
350
+ {
351
+ Value1,
352
+ Value2
353
+ }
354
+ class TestModel
355
+ {
356
+ public TestEnum Prop1
357
+ {
358
+ get;
359
+ set;
360
+ }
361
+ }
362
+ }
363
+ `);
364
+ });
365
+ it("renders a class with string enums", async () => {
366
+ const {
367
+ TestModel,
368
+ TestEnum
369
+ } = await runner.compile(`
370
+ @test enum TestEnum {
371
+ Value1;
372
+ Value2;
373
+ }
374
+ @test model TestModel {
375
+ @test prop1: TestEnum;
376
+ }
377
+ `);
378
+ const res = render(_$createComponent(Output, {
379
+ get program() {
380
+ return runner.program;
381
+ },
382
+ get namePolicy() {
383
+ return cs.createCSharpNamePolicy();
384
+ },
385
+ get children() {
386
+ return _$createComponent(Namespace, {
387
+ name: "TestNamespace",
388
+ get children() {
389
+ return _$createComponent(SourceFile, {
390
+ path: "test.cs",
391
+ get children() {
392
+ return [_$createComponent(EnumDeclaration, {
393
+ type: TestEnum
394
+ }), _$createIntrinsic("hbr", {}), _$createComponent(ClassDeclaration, {
395
+ type: TestModel
396
+ })];
397
+ }
398
+ });
399
+ }
400
+ });
401
+ }
402
+ }));
403
+ assertFileContents(res, d`
404
+ namespace TestNamespace
405
+ {
406
+ public enum TestEnum
407
+ {
408
+ Value1,
409
+ Value2
410
+ }
411
+ class TestModel
412
+ {
413
+ public TestEnum Prop1
414
+ {
415
+ get;
416
+ set;
417
+ }
418
+ }
419
+ }
420
+ `);
421
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=enum-declaration.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-declaration.test.d.ts","sourceRoot":"","sources":["../../../../test/csharp/components/enum-declaration.test.tsx"],"names":[],"mappings":""}