@alloy-js/csharp 0.18.0-dev.9 → 0.19.0-dev.0

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 (113) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/src/components/ClassDeclaration.d.ts +39 -2
  3. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  4. package/dist/src/components/ClassDeclaration.js +35 -34
  5. package/dist/src/components/ClassMethod.d.ts +33 -1
  6. package/dist/src/components/ClassMethod.d.ts.map +1 -1
  7. package/dist/src/components/ClassMethod.js +22 -7
  8. package/dist/src/components/SourceFile.d.ts.map +1 -1
  9. package/dist/src/components/SourceFile.js +1 -0
  10. package/dist/src/components/attributes/attributes.d.ts +39 -0
  11. package/dist/src/components/attributes/attributes.d.ts.map +1 -0
  12. package/dist/src/components/attributes/attributes.js +62 -0
  13. package/dist/src/components/attributes/attributes.test.d.ts +2 -0
  14. package/dist/src/components/attributes/attributes.test.d.ts.map +1 -0
  15. package/dist/src/components/attributes/attributes.test.js +75 -0
  16. package/dist/src/components/index.d.ts +7 -1
  17. package/dist/src/components/index.d.ts.map +1 -1
  18. package/dist/src/components/index.js +8 -2
  19. package/dist/src/components/interface/declaration.d.ts +32 -1
  20. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  21. package/dist/src/components/interface/declaration.js +18 -25
  22. package/dist/src/components/interface/declaration.test.js +102 -0
  23. package/dist/src/components/interface/method.d.ts +33 -1
  24. package/dist/src/components/interface/method.d.ts.map +1 -1
  25. package/dist/src/components/interface/method.js +22 -7
  26. package/dist/src/components/interface/method.test.js +169 -0
  27. package/dist/src/components/interface/property.d.ts +36 -1
  28. package/dist/src/components/interface/property.d.ts.map +1 -1
  29. package/dist/src/components/interface/property.js +18 -4
  30. package/dist/src/components/interface/property.test.js +24 -0
  31. package/dist/src/components/parameters/parameters.d.ts +19 -0
  32. package/dist/src/components/parameters/parameters.d.ts.map +1 -0
  33. package/dist/src/components/parameters/parameters.js +43 -0
  34. package/dist/src/components/property/property.d.ts +80 -0
  35. package/dist/src/components/property/property.d.ts.map +1 -0
  36. package/dist/src/components/property/property.js +76 -0
  37. package/dist/src/components/property/property.test.d.ts +2 -0
  38. package/dist/src/components/property/property.test.d.ts.map +1 -0
  39. package/dist/src/components/property/property.test.js +242 -0
  40. package/dist/src/components/record/declaration.d.ts +35 -0
  41. package/dist/src/components/record/declaration.d.ts.map +1 -0
  42. package/dist/src/components/record/declaration.js +90 -0
  43. package/dist/src/components/record/declaration.test.d.ts +2 -0
  44. package/dist/src/components/record/declaration.test.d.ts.map +1 -0
  45. package/dist/src/components/record/declaration.test.js +94 -0
  46. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts +8 -0
  47. package/dist/src/components/type-parameters/type-parameter-constraints.d.ts.map +1 -0
  48. package/dist/src/components/type-parameters/type-parameter-constraints.js +44 -0
  49. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts +2 -0
  50. package/dist/src/components/type-parameters/type-parameter-constraints.test.d.ts.map +1 -0
  51. package/dist/src/components/type-parameters/type-parameter-constraints.test.js +67 -0
  52. package/dist/src/components/type-parameters/type-parameter.d.ts +20 -0
  53. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -0
  54. package/dist/src/components/type-parameters/type-parameter.js +22 -0
  55. package/dist/src/components/type-parameters/type-parameters.d.ts +17 -0
  56. package/dist/src/components/type-parameters/type-parameters.d.ts.map +1 -0
  57. package/dist/src/components/type-parameters/type-parameters.js +54 -0
  58. package/dist/src/components/type-parameters/type-parameters.test.d.ts +2 -0
  59. package/dist/src/components/type-parameters/type-parameters.test.d.ts.map +1 -0
  60. package/dist/src/components/type-parameters/type-parameters.test.js +48 -0
  61. package/dist/src/components/var/declaration.d.ts +35 -0
  62. package/dist/src/components/var/declaration.d.ts.map +1 -0
  63. package/dist/src/components/var/declaration.js +40 -0
  64. package/dist/src/components/var/declaration.test.d.ts +2 -0
  65. package/dist/src/components/var/declaration.test.d.ts.map +1 -0
  66. package/dist/src/components/var/declaration.test.js +73 -0
  67. package/dist/src/name-policy.d.ts +1 -1
  68. package/dist/src/name-policy.d.ts.map +1 -1
  69. package/dist/src/name-policy.js +1 -0
  70. package/dist/test/class-declaration.test.d.ts +2 -0
  71. package/dist/test/class-declaration.test.d.ts.map +1 -0
  72. package/dist/test/{class.test.js → class-declaration.test.js} +161 -33
  73. package/dist/test/project-directory.test.d.ts +2 -0
  74. package/dist/test/project-directory.test.d.ts.map +1 -0
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +3 -3
  77. package/src/components/ClassDeclaration.tsx +65 -33
  78. package/src/components/ClassMethod.tsx +46 -4
  79. package/src/components/SourceFile.tsx +1 -0
  80. package/src/components/attributes/attributes.test.tsx +61 -0
  81. package/src/components/attributes/attributes.tsx +100 -0
  82. package/src/components/index.ts +7 -1
  83. package/src/components/interface/declaration.test.tsx +102 -0
  84. package/src/components/interface/declaration.tsx +43 -27
  85. package/src/components/interface/method.test.tsx +173 -0
  86. package/src/components/interface/method.tsx +45 -5
  87. package/src/components/interface/property.test.tsx +21 -0
  88. package/src/components/interface/property.tsx +43 -6
  89. package/src/components/parameters/parameters.tsx +74 -0
  90. package/src/components/property/property.test.tsx +209 -0
  91. package/src/components/property/property.tsx +172 -0
  92. package/src/components/record/declaration.test.tsx +73 -0
  93. package/src/components/record/declaration.tsx +109 -0
  94. package/src/components/type-parameters/type-parameter-constraints.test.tsx +93 -0
  95. package/src/components/type-parameters/type-parameter-constraints.tsx +46 -0
  96. package/src/components/type-parameters/type-parameter.tsx +35 -0
  97. package/src/components/type-parameters/type-parameters.test.tsx +46 -0
  98. package/src/components/type-parameters/type-parameters.tsx +63 -0
  99. package/src/components/var/declaration.test.tsx +59 -0
  100. package/src/components/var/declaration.tsx +47 -0
  101. package/src/name-policy.ts +3 -0
  102. package/temp/api.json +4722 -2384
  103. package/test/{class.test.tsx → class-declaration.test.tsx} +144 -26
  104. package/dist/src/components/Parameters.d.ts +0 -13
  105. package/dist/src/components/Parameters.d.ts.map +0 -1
  106. package/dist/src/components/Parameters.js +0 -34
  107. package/dist/test/class.test.d.ts +0 -2
  108. package/dist/test/class.test.d.ts.map +0 -1
  109. package/dist/test/projectdirectory.test.d.ts +0 -2
  110. package/dist/test/projectdirectory.test.d.ts.map +0 -1
  111. package/src/components/Parameters.tsx +0 -51
  112. /package/dist/test/{projectdirectory.test.js → project-directory.test.js} +0 -0
  113. /package/test/{projectdirectory.test.tsx → project-directory.test.tsx} +0 -0
@@ -1,9 +1,11 @@
1
1
  import { createComponent as _$createComponent, mergeProps as _$mergeProps, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
2
  import * as core from "@alloy-js/core";
3
+ import { List, refkey } from "@alloy-js/core";
3
4
  import * as coretest from "@alloy-js/core/testing";
4
5
  import { describe, expect, it } from "vitest";
6
+ import { Attribute } from "../src/components/attributes/attributes.js";
5
7
  import * as csharp from "../src/index.js";
6
- import { ClassDeclaration } from "../src/index.js";
8
+ import { ClassDeclaration, ClassMember, Property, SourceFile } from "../src/index.js";
7
9
  import * as utils from "./utils.js";
8
10
  it("declares class with no members", () => {
9
11
  expect(_$createComponent(utils.TestNamespace, {
@@ -58,6 +60,45 @@ describe("modifiers", () => {
58
60
  `);
59
61
  });
60
62
  });
63
+ describe("base", () => {
64
+ it("define base class", () => {
65
+ expect(_$createComponent(utils.TestNamespace, {
66
+ get children() {
67
+ return _$createComponent(csharp.ClassDeclaration, {
68
+ name: "TestClass",
69
+ baseType: "Foo"
70
+ });
71
+ }
72
+ })).toRenderTo(`
73
+ class TestClass : Foo;
74
+ `);
75
+ });
76
+ it("define multiple interface types", () => {
77
+ expect(_$createComponent(utils.TestNamespace, {
78
+ get children() {
79
+ return _$createComponent(csharp.ClassDeclaration, {
80
+ name: "TestClass",
81
+ interfaceTypes: ["Foo", "Bar"]
82
+ });
83
+ }
84
+ })).toRenderTo(`
85
+ class TestClass : Foo, Bar;
86
+ `);
87
+ });
88
+ it("define base class and multiple interface types", () => {
89
+ expect(_$createComponent(utils.TestNamespace, {
90
+ get children() {
91
+ return _$createComponent(csharp.ClassDeclaration, {
92
+ name: "TestClass",
93
+ baseType: "BaseClass",
94
+ interfaceTypes: ["Foo", "Bar"]
95
+ });
96
+ }
97
+ })).toRenderTo(`
98
+ class TestClass : BaseClass, Foo, Bar;
99
+ `);
100
+ });
101
+ });
61
102
  it("declares class with some members", () => {
62
103
  const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
63
104
  "public": true,
@@ -212,41 +253,86 @@ it("uses refkeys for members, params, and return type", () => {
212
253
  }
213
254
  `);
214
255
  });
215
- it("declares class with generic parameters", () => {
216
- const typeParameters = {
217
- T: core.refkey(),
218
- U: core.refkey()
219
- };
220
- const res = utils.toSourceText(_$createComponent(csharp.ClassDeclaration, {
221
- "public": true,
222
- name: "TestClass",
223
- typeParameters: typeParameters,
224
- get children() {
225
- return [_$createComponent(csharp.ClassMember, {
226
- "public": true,
227
- name: "memberOne",
228
- get type() {
229
- return typeParameters.T;
230
- }
231
- }), ";", _$createIntrinsic("hbr", {}), _$createComponent(csharp.ClassMember, {
232
- "private": true,
233
- name: "memberTwo",
234
- get type() {
235
- return typeParameters.U;
236
- }
237
- }), ";"];
238
- }
239
- }));
240
- expect(res).toBe(coretest.d`
241
- namespace TestCode
242
- {
256
+ describe("with type parameters", () => {
257
+ it("reference parameters", () => {
258
+ const typeParameters = [{
259
+ name: "T",
260
+ refkey: refkey()
261
+ }, {
262
+ name: "U",
263
+ refkey: refkey()
264
+ }];
265
+ expect(_$createComponent(utils.TestNamespace, {
266
+ get children() {
267
+ return _$createComponent(SourceFile, {
268
+ path: "Test.cs",
269
+ get children() {
270
+ return _$createComponent(ClassDeclaration, {
271
+ "public": true,
272
+ name: "TestClass",
273
+ typeParameters: typeParameters,
274
+ get children() {
275
+ return _$createComponent(List, {
276
+ get children() {
277
+ return [_$createComponent(Property, {
278
+ name: "PropA",
279
+ get type() {
280
+ return typeParameters[0].refkey;
281
+ },
282
+ get: true,
283
+ set: true
284
+ }), _$createComponent(Property, {
285
+ name: "PropB",
286
+ get type() {
287
+ return typeParameters[1].refkey;
288
+ },
289
+ get: true,
290
+ set: true
291
+ })];
292
+ }
293
+ });
294
+ }
295
+ });
296
+ }
297
+ });
298
+ }
299
+ })).toRenderTo(`
300
+ namespace TestCode
301
+ {
243
302
  public class TestClass<T, U>
244
303
  {
245
- public T MemberOne;
246
- private U memberTwo;
304
+ T PropA { get; set; }
305
+ U PropB { get; set; }
247
306
  }
248
- }
249
- `);
307
+ }
308
+ `);
309
+ });
310
+ it("defines with constraints", () => {
311
+ const typeParameters = [{
312
+ name: "T",
313
+ constraints: "IFoo"
314
+ }, {
315
+ name: "U",
316
+ constraints: "IBar"
317
+ }];
318
+ expect(_$createComponent(utils.TestNamespace, {
319
+ get children() {
320
+ return _$createComponent(ClassDeclaration, {
321
+ "public": true,
322
+ name: "TestClass",
323
+ typeParameters: typeParameters,
324
+ children: "// Body"
325
+ });
326
+ }
327
+ })).toRenderTo(`
328
+ public class TestClass<T, U>
329
+ where T : IFoo
330
+ where U : IBar
331
+ {
332
+ // Body
333
+ }
334
+ `);
335
+ });
250
336
  });
251
337
  it("declares class with invalid members", () => {
252
338
  const decl = _$createComponent(csharp.ClassDeclaration, {
@@ -350,4 +436,46 @@ it("specify doc comment", () => {
350
436
  /// This is a test
351
437
  class Test;
352
438
  `);
439
+ });
440
+ it("supports class member doc comments", () => {
441
+ expect(_$createComponent(utils.TestNamespace, {
442
+ get children() {
443
+ return _$createComponent(ClassDeclaration, {
444
+ name: "Test",
445
+ doc: "This is a test",
446
+ get children() {
447
+ return _$createComponent(ClassMember, {
448
+ name: "Member",
449
+ "public": true,
450
+ type: "int",
451
+ doc: "This is a member"
452
+ });
453
+ }
454
+ });
455
+ }
456
+ })).toRenderTo(`
457
+ /// This is a test
458
+ class Test
459
+ {
460
+ /// This is a member
461
+ public int Member
462
+ }
463
+ `);
464
+ });
465
+ it("specify attributes", () => {
466
+ expect(_$createComponent(utils.TestNamespace, {
467
+ get children() {
468
+ return _$createComponent(ClassDeclaration, {
469
+ name: "Test",
470
+ get attributes() {
471
+ return [_$createComponent(Attribute, {
472
+ name: "Test"
473
+ })];
474
+ }
475
+ });
476
+ }
477
+ })).toRenderTo(`
478
+ [Test]
479
+ class Test;
480
+ `);
353
481
  });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=project-directory.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-directory.test.d.ts","sourceRoot":"","sources":["../../test/project-directory.test.tsx"],"names":[],"mappings":""}